Sure, no problem. I was already intended to do that.
I got these running.
B.t.w. these Xiaomi sensor do not publish battery every time.
So sometimes I got a reading and sometimes not, and then 'null' will be published and then ofcourse no battery data in Domoticz.
I have to figure out how to solve that, but it could be better solved in Domoticz by not replacing the data with nothing.
This is my Node-red first ever, so coding might not be the best way, so please correct if there is a more efficient way.
This was more like a quick and dirty to see if it works.
My test domoticz is currently running the Zigbee controler and Node-red and is publishing to my mosquitto on the production system.
Of couse you have to change the servers and zigbee device addresses in the code.
Code: Select all
[{"id":"74016149.f403","type":"mqtt in","z":"8188c534.77e7e8","name":"THB","topic":"zigbee2mqtt/0x00158d00022cbcad","qos":"2","broker":"54b04e64.e1422","x":210,"y":240,"wires":[["3bd30ad7.b12a16"]]},{"id":"73b1b108.435a8","type":"debug","z":"8188c534.77e7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":990,"y":180,"wires":[]},{"id":"705118a8.0cf9d8","type":"comment","z":"8188c534.77e7e8","name":"Xiaomi Mi Smart Home Temperature / Humidity Sensor","info":"https://xiaomi-mi.com/sockets-and-sensors/aqara-temperature-and-humidity-sensor/\n\nWSDCGQ11LM","x":360,"y":160,"wires":[]},{"id":"3bd30ad7.b12a16","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":370,"y":240,"wires":[["a4376d59.45fef"]]},{"id":"989fbc27.9c0e1","type":"change","z":"8188c534.77e7e8","name":"Temperature Humidity","rules":[{"t":"delete","p":"payload.pressure","pt":"msg"},{"t":"delete","p":"payload.humidity","pt":"msg"},{"t":"delete","p":"payload.voltage","pt":"msg"},{"t":"set","p":"payload.idx","pt":"msg","to":"552","tot":"num"},{"t":"set","p":"payload.nvalue","pt":"msg","to":"0","tot":"num"},{"t":"move","p":"payload.temphumi","pt":"msg","to":"payload.svalue","tot":"msg"},{"t":"delete","p":"payload.temperature","pt":"msg"},{"t":"move","p":"payload.battery","pt":"msg","to":"payload.Battery","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":240,"wires":[["b50d2c76.b8846","73b1b108.435a8"]]},{"id":"b50d2c76.b8846","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":990,"y":240,"wires":[]},{"id":"a4376d59.45fef","type":"function","z":"8188c534.77e7e8","name":"Convert THB","func":"var temp = msg.payload.temperature;\nvar humi = msg.payload.humidity;\nvar pres = msg.payload.pressure;\nvar batt = msg.payload.battery;\nvar forecast = \"5\"\nvar humistat = \"5\"\n\nif (pres < 966) {\n forecast = \"4\"\n} else if (pres < 993) {\n forecast = \"3\"\n} else if (pres < 1007) {\n forecast = \"2\"\n} else if (pres < 1013) {\n forecast = \"1\"\n} else {\n forecast = \"0\"\n}\n\nif (humi < 31) {\n humistat = \"2\"\n} else if (humi > 69) {\n humistat = \"3\"\n} else if (humi > 34 && humi < 66 && temp > 21 && temp < 27) {\n humistat = \"1\"\n} else {\n humistat = \"0\"\n}\n\n\nmsg.payload.temperature = temp.toString();\nmsg.payload.humidity = humi.toString();\nmsg.payload.pressure = pres.toString()+\";\"+forecast;\nmsg.payload.battery = Math.round(batt);\nmsg.payload.temphumi = temp.toString()+\";\"+humi.toString()+\";\"+humistat;\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":240,"wires":[["989fbc27.9c0e1","d882ea2c.a7b6f8"]]},{"id":"d882ea2c.a7b6f8","type":"change","z":"8188c534.77e7e8","name":"Barometer","rules":[{"t":"delete","p":"payload.voltage","pt":"msg"},{"t":"delete","p":"payload.temperature","pt":"msg"},{"t":"delete","p":"payload.humidity","pt":"msg"},{"t":"delete","p":"payload.temphumi","pt":"msg"},{"t":"set","p":"payload.idx","pt":"msg","to":"553","tot":"num"},{"t":"set","p":"payload.nvalue","pt":"msg","to":"0","tot":"num"},{"t":"move","p":"payload.pressure","pt":"msg","to":"payload.svalue","tot":"msg"},{"t":"move","p":"payload.battery","pt":"msg","to":"payload.Battery","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":320,"wires":[["af0169ca.91a728","182fe774.2ff9c9"]]},{"id":"af0169ca.91a728","type":"debug","z":"8188c534.77e7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":380,"wires":[]},{"id":"182fe774.2ff9c9","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":990,"y":320,"wires":[]},{"id":"40149863.198668","type":"comment","z":"8188c534.77e7e8","name":"Xiaomi Mi Smart Home Occupancy Sensor","info":"https://xiaomi-mi.com/sockets-and-sensors/xiaomi-mi-occupancy-sensor/\n\nRTCGQ01LM","x":320,"y":440,"wires":[]},{"id":"614e4d93.e19474","type":"mqtt in","z":"8188c534.77e7e8","name":"PIR Zolder","topic":"zigbee2mqtt/0x00158d0001b192fd","qos":"2","broker":"54b04e64.e1422","x":220,"y":520,"wires":[["f673a083.e94cc"]]},{"id":"da1292d5.8d0d4","type":"debug","z":"8188c534.77e7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":580,"wires":[]},{"id":"f673a083.e94cc","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":370,"y":520,"wires":[["bb6c57b.96869a8"]]},{"id":"bb6c57b.96869a8","type":"function","z":"8188c534.77e7e8","name":"Convert PIR","func":"var occu = msg.payload.occupancy;\nvar batt = msg.payload.battery;\n\nif (occu === true) {\n msg.payload.occupancy = \"On\";\n} else {\n msg.payload.occupancy = \"Off\";\n}\nmsg.payload.battery = Math.round(batt);\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":520,"wires":[["4d650218.b6d83c"]]},{"id":"4d650218.b6d83c","type":"change","z":"8188c534.77e7e8","name":"Motion","rules":[{"t":"delete","p":"payload.voltage","pt":"msg"},{"t":"set","p":"payload.command","pt":"msg","to":"switchlight","tot":"str"},{"t":"set","p":"payload.idx","pt":"msg","to":"554","tot":"num"},{"t":"move","p":"payload.occupancy","pt":"msg","to":"payload.switchcmd","tot":"msg"},{"t":"move","p":"payload.battery","pt":"msg","to":"payload.Battery","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":520,"wires":[["da1292d5.8d0d4","bc3f7964.9da148"]]},{"id":"bc3f7964.9da148","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":990,"y":520,"wires":[]},{"id":"54b04e64.e1422","type":"mqtt-broker","z":"","name":"Zigbee","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"domoticz/bridge/state","birthQos":"0","birthPayload":"online","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"a61018b4.359498","type":"mqtt-broker","z":"","name":"Domoticz","broker":"domoticz.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]