Xiaomi Miflora sensor integration

This is my take of integrating the Xiaomi Miflora to NodeRed. I am using a python script running as a cron job to read the sensor and pushing the data to MQTT. There is a more details writeup here, where you find the python script as well: https://community.openhab.org/t/xiaomi-miflora-sensor-integration/17453. Also you can watch my video on this topic here: https://youtu.be/8-wwijM4W88

Below is a simple script that reads the incoming sensor values from MQTT separates them and adds them to the dashboard text fields and graphs.

[{"id":"fa795f97.61e78","type":"tab","label":"MiFlora MQTT"},{"id":"8b334812.a19a98","type":"mqtt in","z":"fa795f97.61e78","name":"Miflora MQTT","topic":"/home/miflora","qos":"2","broker":"cea5258a.b34038","x":89,"y":35,"wires":[["f4621ab.43b90e8","cf640b9b.5379b8"]]},{"id":"cf640b9b.5379b8","type":"json","z":"fa795f97.61e78","name":"","x":102.5,"y":116,"wires":[["a8a5a60e.f0c048","8156421a.b4b4d","5f640125.9be3","d8427b8d.fdf018","3ab31027.1e746","893ca343.2b424"]]},{"id":"a8a5a60e.f0c048","type":"function","z":"fa795f97.61e78","name":"Temperature","func":"msg.payload = msg.payload.temperature;\nmsg.topic = \"Temperature\";\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":118,"wires":[["1f57b9c0.ddc766","8a0c2b0e.243478"]]},{"id":"1f57b9c0.ddc766","type":"ui_text","z":"fa795f97.61e78","group":"27c3d951.18a4e6","order":1,"width":"","height":"","name":"Temperature","label":"Temperature","format":"{{msg.payload}} °C","layout":"","x":516,"y":122,"wires":[]},{"id":"8156421a.b4b4d","type":"function","z":"fa795f97.61e78","name":"Sunlight","func":"msg.payload = msg.payload.sunlight;\nmsg.topic = \"Sunlight\";\nreturn msg;","outputs":1,"noerr":0,"x":284,"y":210,"wires":[["626d5b13.216094","3d661786.15f678"]]},{"id":"626d5b13.216094","type":"ui_text","z":"fa795f97.61e78","group":"27c3d951.18a4e6","order":5,"width":"","height":"","name":"Sunlight","label":"Sunlight","format":"{{msg.payload}} lux","layout":"","x":510,"y":214,"wires":[]},{"id":"5f640125.9be3","type":"function","z":"fa795f97.61e78","name":"Soil moisture","func":"msg.payload = msg.payload.moisture;\nreturn msg;","outputs":1,"noerr":0,"x":294,"y":300,"wires":[["2196fe5.045d702"]]},{"id":"2196fe5.045d702","type":"ui_text","z":"fa795f97.61e78","group":"27c3d951.18a4e6","order":7,"width":"","height":"","name":"Soil moisture","label":"Soil Moisture","format":"{{msg.payload}} %","layout":"","x":520,"y":304,"wires":[]},{"id":"d8427b8d.fdf018","type":"function","z":"fa795f97.61e78","name":"Soli fertility","func":"msg.payload = msg.payload.fertility;\nreturn msg;","outputs":1,"noerr":0,"x":288,"y":348,"wires":[["59cc2505.08ad5c"]]},{"id":"59cc2505.08ad5c","type":"ui_text","z":"fa795f97.61e78","group":"27c3d951.18a4e6","order":8,"width":"","height":"","name":"Soil fertility","label":"Soil fertility","format":"{{msg.payload}} µs/cm","layout":"","x":514,"y":352,"wires":[]},{"id":"3ab31027.1e746","type":"function","z":"fa795f97.61e78","name":"Battery","func":"msg.payload = msg.payload.battery;\nmsg.topic = \"Battery\";\nreturn msg;","outputs":1,"noerr":0,"x":278,"y":398,"wires":[["68d62e60.579c3","4ccca0c6.48c42"]]},{"id":"68d62e60.579c3","type":"ui_text","z":"fa795f97.61e78","group":"27c3d951.18a4e6","order":3,"width":"","height":"","name":"Battery level","label":"Battery level","format":"{{msg.payload}} %","layout":"","x":514,"y":402,"wires":[]},{"id":"893ca343.2b424","type":"function","z":"fa795f97.61e78","name":"Version","func":"msg.payload = msg.payload.version;\nreturn msg;","outputs":1,"noerr":0,"x":276,"y":486,"wires":[["af7eb105.4cc46"]]},{"id":"af7eb105.4cc46","type":"ui_text","z":"fa795f97.61e78","group":"27c3d951.18a4e6","order":9,"width":"","height":"","name":"Firmware version","label":"Firmware version","format":"{{msg.payload}}","layout":"","x":532,"y":490,"wires":[]},{"id":"f4621ab.43b90e8","type":"debug","z":"fa795f97.61e78","name":"","active":false,"console":"false","complete":"payload","x":556,"y":32,"wires":[]},{"id":"3d661786.15f678","type":"ui_chart","z":"fa795f97.61e78","name":"Sunlight","group":"27c3d951.18a4e6","order":6,"width":"","height":"","label":"","chartType":"line","xformat":"%H:%M:%S","interpolate":"linear","nodata":"No Data","ymin":"","ymax":"","removeOlder":"5","removeOlderUnit":"86400","x":512,"y":261,"wires":[[],[]]},{"id":"4ccca0c6.48c42","type":"ui_chart","z":"fa795f97.61e78","name":"Battery","group":"27c3d951.18a4e6","order":4,"width":"","height":"","label":"","chartType":"line","xformat":"%H:%M:%S","interpolate":"linear","nodata":"No Data","ymin":"","ymax":"","removeOlder":"20","removeOlderUnit":"86400","x":504,"y":445,"wires":[[],[]]},{"id":"8a0c2b0e.243478","type":"ui_chart","z":"fa795f97.61e78","name":"Temperature","group":"27c3d951.18a4e6","order":2,"width":"","height":"","label":"","chartType":"line","xformat":"%H:%M:%S","interpolate":"linear","nodata":"No Data","ymin":"","ymax":"","removeOlder":"1","removeOlderUnit":"86400","x":523,"y":168,"wires":[[],[]]},{"id":"cea5258a.b34038","type":"mqtt-broker","z":"","broker":"192.168.1.80","port":"1883","clientid":"node-red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"27c3d951.18a4e6","type":"ui_group","z":"","name":"MiFlora","tab":"156af96f.f8fd27","order":2,"disp":true,"width":"6"},{"id":"156af96f.f8fd27","type":"ui_tab","z":"","name":"Home","icon":"home","order":"1"}]
nygma2004

Flow Info

created 5 months, 1 week ago

Node Types

Core
  • debug (x1)
  • function (x6)
  • json (x1)
  • mqtt in (x1)
  • mqtt-broker (x1)
Other
  • tab (x1)
  • ui_chart (x3)
  • ui_group (x1)
  • ui_tab (x1)
  • ui_text (x6)

Tags

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