Mi Scale using OpenMQTTGateway Bluetooth Low Energy (BLE)

I have my gateway interval set to 7 seconds which may result in multiple values registered from my scale to node red. Therefore I setup the flow below to only send the maximum value received by node red in 15 second intervals. Honestly, I've only tested this using a random number generator. However, I'll update this post if changes are required. Be sure to look at the comment nodes for addition information. The maximum weight is set to pounds in this example. You can move these nodes to the Kg output. Be sure to update the Optional lbs filter to fit your needs.

https://docs.openmqttgateway.com/

[{"id":"704a8dc7.f3b43c","type":"switch","z":"f1f85c58.fbb96","name":"BTtoMQTT","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"BTtoMQTT","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":3900,"wires":[["3985ac27.e2eb64","ff78a0b7.e71a5"]]},{"id":"3985ac27.e2eb64","type":"json","z":"f1f85c58.fbb96","name":"","property":"payload","action":"","pretty":false,"x":330,"y":3940,"wires":[["221fccfb.053d84"]]},{"id":"221fccfb.053d84","type":"switch","z":"f1f85c58.fbb96","name":"Mi Scale","property":"payload.name","propertyType":"msg","rules":[{"t":"cont","v":"SCALE2","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":3980,"wires":[["bbc712d3.79c7c8"]]},{"id":"6c16e6ac.fab128","type":"ui_text","z":"f1f85c58.fbb96","group":"42272b88.099334","order":3,"width":0,"height":0,"name":"","label":"Weight","format":"{{msg.payload}}","layout":"row-spread","x":1240,"y":4340,"wires":[]},{"id":"bbc712d3.79c7c8","type":"function","z":"f1f85c58.fbb96","name":"","func":"var msg1 = { payload:msg.payload.weight };\n//convert and round Kg to lbs\nvar msg2 = msg.payload.weight * 2.20462;\nmsg2 = { payload:Math.round(msg2 * 10) / 10 };\nreturn [ msg1, msg2 ];","outputs":2,"noerr":0,"x":330,"y":4080,"wires":[["952a6ff6.96829"],["a0e7f93.b5b6008","b0f06856.ff0c9"]]},{"id":"952a6ff6.96829","type":"debug","z":"f1f85c58.fbb96","name":"Kg","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":4060,"wires":[]},{"id":"f75088b7.62d498","type":"debug","z":"f1f85c58.fbb96","name":"final lbs","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1240,"y":4420,"wires":[]},{"id":"b7394c2c.d1158","type":"timeout","z":"f1f85c58.fbb96","name":"My Timeout","outtopic":"","outsafe":"Safe","outwarning":"Warning","outunsafe":"Unsafe","warning":"5","timer":"15","repeat":false,"again":false,"x":650,"y":4360,"wires":[["76951ffd.e1d64"]]},{"id":"27eb4a04.566a96","type":"switch","z":"f1f85c58.fbb96","name":"maxweight","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"maxweight","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":910,"y":4260,"wires":[["4915879d.f1162"]]},{"id":"a0e7f93.b5b6008","type":"switch","z":"f1f85c58.fbb96","name":">= 175","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"175","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":520,"y":4260,"wires":[["27eb4a04.566a96","b7394c2c.d1158"]]},{"id":"bcedee5.e35fe1","type":"change","z":"f1f85c58.fbb96","name":"maxweight to 0","rules":[{"t":"set","p":"maxweight","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":4620,"wires":[[]]},{"id":"76951ffd.e1d64","type":"switch","z":"f1f85c58.fbb96","name":"Unsafe","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Unsafe","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":640,"y":4420,"wires":[["4c09358.ddb274c","7ee6588c.b49b98"]]},{"id":"c9e53dee.bcf218","type":"inject","z":"f1f85c58.fbb96","name":"","topic":"0","payload":"","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":"1","x":550,"y":4620,"wires":[["bcedee5.e35fe1"]]},{"id":"7ee6588c.b49b98","type":"change","z":"f1f85c58.fbb96","name":"Send maxweight","rules":[{"t":"set","p":"payload","pt":"msg","to":"maxweight","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":4420,"wires":[["2ec7fad6.b54fc6"]]},{"id":"4c09358.ddb274c","type":"delay","z":"f1f85c58.fbb96","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":920,"y":4520,"wires":[["bcedee5.e35fe1"]]},{"id":"4915879d.f1162","type":"change","z":"f1f85c58.fbb96","name":"Set maxweight","rules":[{"t":"set","p":"maxweight","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":4300,"wires":[[]]},{"id":"47c8548b.cce244","type":"comment","z":"f1f85c58.fbb96","name":"Set flow.maxweight to 0","info":"","x":880,"y":4580,"wires":[]},{"id":"b8f75551.be20a8","type":"comment","z":"f1f85c58.fbb96","name":"Set flow.maxweight at Startup","info":"","x":480,"y":4580,"wires":[]},{"id":"533ec063.bcc598","type":"comment","z":"f1f85c58.fbb96","name":"Reset flow.maxweight","info":"","x":880,"y":4480,"wires":[]},{"id":"4b999ff1.7462","type":"comment","z":"f1f85c58.fbb96","name":"Send flow.maxweight","info":"","x":890,"y":4380,"wires":[]},{"id":"5ccb415a.5cb678","type":"comment","z":"f1f85c58.fbb96","name":"Send weight after 15s of no change","info":"","x":580,"y":4320,"wires":[]},{"id":"52a41c5.9bc5f64","type":"comment","z":"f1f85c58.fbb96","name":"Optional lbs filter for more than 1 person ","info":"","x":430,"y":4220,"wires":[]},{"id":"b7bd7f81.a94bb8","type":"comment","z":"f1f85c58.fbb96","name":"Get the highest value","info":"","x":890,"y":4220,"wires":[]},{"id":"b0f06856.ff0c9","type":"debug","z":"f1f85c58.fbb96","name":"lbs","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":4100,"wires":[]},{"id":"c09d6121.517718","type":"comment","z":"f1f85c58.fbb96","name":"Kg or calculate lbs","info":"","x":310,"y":4040,"wires":[]},{"id":"52c6f6b4.52ca78","type":"comment","z":"f1f85c58.fbb96","name":"***Notes on maxwieght inside this node***","info":"Maxweight is set to account for changing vaules when messages are sent from the scale to OpenMQTTGateway. You can move these nodes to the Kg output. Be sure to update the Optional lbs filter to fit your needs. ","x":700,"y":4160,"wires":[]},{"id":"4b7ef863.4831","type":"ui_chart","z":"f1f85c58.fbb96","name":"","group":"42272b88.099334","order":4,"width":0,"height":0,"label":"Weight","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"604800","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1240,"y":4380,"wires":[[]]},{"id":"ff78a0b7.e71a5","type":"debug","z":"f1f85c58.fbb96","name":"Raw","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":490,"y":3900,"wires":[]},{"id":"a070b6a3.92193","type":"comment","z":"f1f85c58.fbb96","name":"From MQTT Broker","info":"","x":170,"y":3820,"wires":[]},{"id":"2ec7fad6.b54fc6","type":"switch","z":"f1f85c58.fbb96","name":"> 0","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1050,"y":4420,"wires":[["f75088b7.62d498","6c16e6ac.fab128","4b7ef863.4831"]]},{"id":"42272b88.099334","type":"ui_group","z":"","name":"OpenMQTTGateway","tab":"582298b8.fd8a68","disp":true,"width":"6","collapse":false},{"id":"582298b8.fd8a68","type":"ui_tab","z":"","name":"Test","icon":"dashboard","disabled":false,"hidden":false}]

Flow Info

Created 2 years ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x3)
  • comment (x10)
  • debug (x4)
  • delay (x1)
  • function (x1)
  • inject (x1)
  • json (x1)
  • switch (x6)
Other
  • timeout (x1)
  • ui_chart (x1)
  • ui_group (x1)
  • ui_tab (x1)
  • ui_text (x1)

Tags

  • openmqttgateway
  • mqtt
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option