Zigbee2MQTT

Xiaomi, Ikea TRÅDFRI, Philips Hue and more.

Moderator: leecollings

EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

Tnx for the answer.
I did it a little bit differently.

Code: Select all

if (Math.round(batt) > 1) {
    msg.payload.battery = Math.round(batt);
} else {
    delete msg.payload.battery;
}
This works too, but the fact that the property is not present is handled by Domoticz as 'nill'
So the battery value is gone in Domoticz. So this is a Domoticz problem.
But the good news is that after a while the battery value is present at every update from the devices.

I also added the "zigbee2mqtt/bridge/state" topic and log the "online" and "offline" to Domoticz.
In that same topic there is also (every 5 min.) a payload a string[5] with a content of something around "49.5"
Anyone any idea what that could be, temperature of zigbee chip???
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

Tnx to hints from @ben53252642 I could simplify/optimize the code, and removed the bug.

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":260,"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":200,"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":180,"wires":[]},{"id":"3bd30ad7.b12a16","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":370,"y":260,"wires":[["a4376d59.45fef","3b003f27.3ca0d"]]},{"id":"b50d2c76.b8846","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":990,"y":260,"wires":[]},{"id":"a4376d59.45fef","type":"function","z":"8188c534.77e7e8","name":"Convert Temp - Humi","func":"var temp = msg.payload.temperature;\nvar humi = msg.payload.humidity;\nvar batt = msg.payload.battery;\n//var humistat = \"0\";\n\ndelete msg.payload.temperature;\ndelete msg.payload.humidity;\ndelete msg.payload.pressure;\ndelete msg.payload.battery;\ndelete msg.payload.voltage;\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.idx =  552\n//msg.payload.humidity = humi.toString();\n//msg.payload.pressure = pres.toString()+\";\"+forecast;\nmsg.payload.nvalue = 0\nmsg.payload.svalue = temp.toString()+\";\"+humi.toString()+\";\"+humistat;\nmsg.payload.battery = Math.round(batt);\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":260,"wires":[["b50d2c76.b8846","73b1b108.435a8"]]},{"id":"af0169ca.91a728","type":"debug","z":"8188c534.77e7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":400,"wires":[]},{"id":"182fe774.2ff9c9","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":990,"y":340,"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":420,"wires":[]},{"id":"614e4d93.e19474","type":"mqtt in","z":"8188c534.77e7e8","name":"PIR Zolder","topic":"zigbee2mqtt/0x00158d0001b192fd","qos":"2","broker":"54b04e64.e1422","x":220,"y":500,"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":560,"wires":[]},{"id":"f673a083.e94cc","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":370,"y":500,"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\ndelete msg.payload.voltage;\ndelete msg.payload.occupancy;\nmsg.payload.command = \"switchlight\";\nmsg.payload.idx = 554;\nif (occu === true) {\n    msg.payload.switchcmd = \"On\";\n} else {\n    msg.payload.switchcmd = \"Off\";\n}\nmsg.payload.battery = Math.round(batt);\nmsg.payload.battery = 23;\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":500,"wires":[["bc3f7964.9da148","da1292d5.8d0d4"]]},{"id":"bc3f7964.9da148","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":990,"y":500,"wires":[]},{"id":"7d844a0a.645044","type":"mqtt in","z":"8188c534.77e7e8","name":"State","topic":"zigbee2mqtt/bridge/state","qos":"2","broker":"54b04e64.e1422","x":210,"y":80,"wires":[["1a6703ab.900e3c"]]},{"id":"da53f017.8e4f6","type":"debug","z":"8188c534.77e7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":20,"wires":[]},{"id":"1a6703ab.900e3c","type":"function","z":"8188c534.77e7e8","name":"Convert to JSON","func":"var data = msg.payload;\n//console.log(\"payload data: length = \" + data.length);\ndata = data.trim();\n//console.log(\"trimmed data: length = \" + data.length);\ndata = '{\"command\" : \"addlogmessage\", \"message\" : '+'\"Zigbee bridge '+data+'\"'+'}'\nmsg.payload = JSON.parse(data);\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":80,"wires":[["66fd3235.3adafc"]]},{"id":"66fd3235.3adafc","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":710,"y":80,"wires":[["837c41df.05272","da53f017.8e4f6"]]},{"id":"837c41df.05272","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":990,"y":80,"wires":[]},{"id":"3b003f27.3ca0d","type":"function","z":"8188c534.77e7e8","name":"Convert Barometer","func":"var temp = msg.payload.temperature;\nvar humi = msg.payload.humidity;\nvar pres = msg.payload.pressure;\nvar batt = msg.payload.battery;\n\ndelete msg.payload.temperature;\ndelete msg.payload.humidity;\ndelete msg.payload.pressure;\ndelete msg.payload.battery;\ndelete msg.payload.voltage;\ndelete msg.payload.pressure;\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 = \"3\";\n} else if (pres < 1033) {\n    forecast = \"0\";\n} else {\n    forecast = \"1\";\n}\n\nmsg.payload.idx = 553\nmsg.payload.nvalue = 0\nmsg.payload.svalue = pres.toString()+\";\"+forecast;\nmsg.payload.battery = Math.round(batt);\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":320,"wires":[["182fe774.2ff9c9","af0169ca.91a728"]]},{"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":""}]
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 »

@EddyG I'm learning Node-Red as well

You should also be able to use only a Single Domoticz MQTT, not sure if you can use only a single source MQTT as I have yet to receive my Zigbee adapters but in my UPS Flow I've got 3 functions sending to a single MQTT at the same time non-stop for about 12 hours without problems.

Structure the functions like this so the idx, svalue and nvalue etc... don't get sent to the MQTT unless more than 1

Code: Select all

// inputvoltage
msg.payload = {};
msg.payload.inputvoltage = global.get('msg.payload.inputvoltage');
if (msg.payload.inputvoltage > 1) {
msg.payload.idx = 1128 ;
msg.payload.nvalue = 0 ;
msg.payload.svalue = msg.payload.inputvoltage;0;
}

return msg;
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

So you think that in 1 MQTT message there can be 2 Domoticz devices (idx)? How?
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 »

example node-red2.JPG
example node-red2.JPG (155.72 KiB) Viewed 5373 times
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

Yes, so simple. Perhaps I should read the Node-red manual before I start programming. :oops:
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

My finished version of getting data from 2 Xiaomi devices (PIR and Temp/Hum/Baro) into Domoticz.
Put in a function to get all the devices in the network to the log in domoticz.
And did some extra naming to the topics.

Code: Select all

[{"id":"74016149.f403","type":"mqtt in","z":"8188c534.77e7e8","name":"THB","topic":"zigbee2mqtt/ZolderTHB","qos":"2","broker":"54b04e64.e1422","x":110,"y":420,"wires":[["3bd30ad7.b12a16"]]},{"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":260,"y":380,"wires":[]},{"id":"3bd30ad7.b12a16","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":270,"y":420,"wires":[["a4376d59.45fef","3b003f27.3ca0d"]]},{"id":"b50d2c76.b8846","type":"mqtt out","z":"8188c534.77e7e8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"a61018b4.359498","x":910,"y":360,"wires":[]},{"id":"a4376d59.45fef","type":"function","z":"8188c534.77e7e8","name":"Convert Temp - Humi","func":"var temp = msg.payload.temperature;\nvar humi = msg.payload.humidity;\nvar batt = msg.payload.battery;\n//var humistat = \"0\";\n\ndelete msg.payload.temperature;\ndelete msg.payload.humidity;\ndelete msg.payload.pressure;\ndelete msg.payload.battery;\ndelete msg.payload.voltage;\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.idx =  552\n//msg.payload.humidity = humi.toString();\n//msg.payload.pressure = pres.toString()+\";\"+forecast;\nmsg.payload.nvalue = 0\nmsg.payload.svalue = temp.toString()+\";\"+humi.toString()+\";\"+humistat;\nmsg.payload.battery = Math.round(batt);\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":420,"wires":[["b50d2c76.b8846","da1292d5.8d0d4"]]},{"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":220,"y":500,"wires":[]},{"id":"614e4d93.e19474","type":"mqtt in","z":"8188c534.77e7e8","name":"PIR","topic":"zigbee2mqtt/ZolderPIR","qos":"2","broker":"54b04e64.e1422","x":110,"y":540,"wires":[["f673a083.e94cc"]]},{"id":"da1292d5.8d0d4","type":"debug","z":"8188c534.77e7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":910,"y":300,"wires":[]},{"id":"f673a083.e94cc","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":270,"y":540,"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\ndelete msg.payload.voltage;\ndelete msg.payload.battery;\ndelete msg.payload.occupancy;\nmsg.payload.command = \"switchlight\";\nmsg.payload.idx = 554;\nif (occu === true) {\n    msg.payload.switchcmd = \"On\";\n} else {\n    msg.payload.switchcmd = \"Off\";\n}\nmsg.payload.battery = Math.round(batt);\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":540,"wires":[["da1292d5.8d0d4","b50d2c76.b8846"]]},{"id":"7d844a0a.645044","type":"mqtt in","z":"8188c534.77e7e8","name":"State","topic":"zigbee2mqtt/bridge/state","qos":"2","broker":"54b04e64.e1422","x":110,"y":100,"wires":[["1a6703ab.900e3c"]]},{"id":"1a6703ab.900e3c","type":"function","z":"8188c534.77e7e8","name":"Make JSON string","func":"var data = msg.payload;\n//console.log(\"payload data: length = \" + data.length);\ndata = data.trim();\n//console.log(\"trimmed data: length = \" + data.length);\ndata = '{\"command\" : \"addlogmessage\", \"message\" : '+'\"Zigbee bridge '+data+'\"'+'}'\nmsg.payload = JSON.parse(data);\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":100,"wires":[["66fd3235.3adafc"]]},{"id":"66fd3235.3adafc","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":470,"y":100,"wires":[["b50d2c76.b8846","da1292d5.8d0d4"]]},{"id":"3b003f27.3ca0d","type":"function","z":"8188c534.77e7e8","name":"Convert Barometer","func":"var temp = msg.payload.temperature;\nvar humi = msg.payload.humidity;\nvar pres = msg.payload.pressure;\nvar batt = msg.payload.battery;\n\ndelete msg.payload.temperature;\ndelete msg.payload.humidity;\ndelete msg.payload.pressure;\ndelete msg.payload.battery;\ndelete msg.payload.voltage;\ndelete msg.payload.pressure;\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 = \"3\";\n} else if (pres < 1033) {\n    forecast = \"0\";\n} else {\n    forecast = \"1\";\n}\n\nmsg.payload.idx = 553\nmsg.payload.nvalue = 0\nmsg.payload.svalue = pres.toString()+\";\"+forecast;\nmsg.payload.battery = Math.round(batt);\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":460,"wires":[["b50d2c76.b8846","da1292d5.8d0d4"]]},{"id":"11eb6908.5eee17","type":"comment","z":"8188c534.77e7e8","name":"Status online/offline of the Zigbee coordinator.","info":"","x":230,"y":60,"wires":[]},{"id":"aef96916.b51028","type":"comment","z":"8188c534.77e7e8","name":"Logging from Zigbee coordinator","info":"","x":190,"y":180,"wires":[]},{"id":"cea2594c.e73858","type":"mqtt in","z":"8188c534.77e7e8","name":"Logging","topic":"zigbee2mqtt/bridge/log","qos":"2","broker":"54b04e64.e1422","x":110,"y":220,"wires":[["7c62a018.cddf7"]]},{"id":"235df1a2.464c5e","type":"mqtt out","z":"8188c534.77e7e8","name":"Devices","topic":"zigbee2mqtt/bridge/config/devices","qos":"","retain":"","broker":"54b04e64.e1422","x":280,"y":280,"wires":[]},{"id":"f2a95a42.1e1068","type":"inject","z":"8188c534.77e7e8","name":"","topic":"","payload":"Request","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":280,"wires":[["235df1a2.464c5e"]]},{"id":"7c62a018.cddf7","type":"json","z":"8188c534.77e7e8","name":"","property":"payload","action":"","pretty":false,"x":270,"y":220,"wires":[["1bbe5026.f52f8"]]},{"id":"1bbe5026.f52f8","type":"function","z":"8188c534.77e7e8","name":"Proces Devices","func":"var array = [];\nif (msg.payload.type == \"devices\") {\n    var arr = [msg.payload.message];\n    for (var i=0; i<arr.length;i++) {\n        array.push({payload: arr[i]});\n    }\n}\nreturn array;","outputs":1,"noerr":0,"x":440,"y":220,"wires":[["1fa51983.c02156"]]},{"id":"1fa51983.c02156","type":"split","z":"8188c534.77e7e8","name":"Split Devices","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":630,"y":220,"wires":[["da1292d5.8d0d4","b9ce8118.1abe3"]]},{"id":"b9ce8118.1abe3","type":"function","z":"8188c534.77e7e8","name":"Log to Domoticz","func":"var tmp = \"model \"+msg.payload.model+\" - ieeeAddr \"+msg.payload.ieeeAddr;\nvar data = '{\"command\" : \"addlogmessage\", \"message\" : '+'\"Zigbee device: '+tmp+'\"'+'}'\nmsg.payload = JSON.parse(data);\nreturn msg;\n","outputs":1,"noerr":0,"x":500,"y":280,"wires":[["b50d2c76.b8846"]]},{"id":"6a0ed29c.7083ac","type":"comment","z":"8188c534.77e7e8","name":"Documentation","info":"'friendly_name' should be an easy to remember name.\nThat friendly_name is also part of the incomming Topic.\n'Request' gives all the devices in the network in the debug window.\n\nChange:\nTopic in THB and PIR to the 'friendly_name'\nChange Domoticz IDX (msg.payload.idx) in the 3 Converters\n\n//configuration.yaml\n\nhomeassistant: false\npermit_join: true\nmqtt:\n  base_topic: zigbee2mqtt\n  server: 'mqtt://localhost'\nserial:\n  port: /dev/ttyACM0\n  disable_led: true\nadvanced:\n  log_level: info\ndevices:\n  '0x00158d0001b192fd':\n    friendly_name: 'ZolderPIR'\n    retain: false\n    qos: 1\n  '0x00158d00022cbcad':\n    friendly_name: 'ZolderTHB'\n    retain: false\n    qos: 1\n","x":900,"y":60,"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":""}]
blauwebuis
Posts: 331
Joined: Wednesday 21 December 2016 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: current
Contact:

Re: Zigbee2MQTT

Post by blauwebuis »

Would it theoretically be possible to turn this into a python plugin? Or to integrate this into Domoticz?
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 »

blauwebuis wrote: Saturday 28 July 2018 14:13 Would it theoretically be possible to turn this into a python plugin? Or to integrate this into Domoticz?
Theoretically yes, it's definately possible to create a Python plugin.

Given the extraordinary device support and that Home Assistant have now created their own plugin, I think a Domoticz plugin needs to be created asap. (similar in scope to the OpenZWave plugin).

Eg, ability to add and remove devices etc... all built into the plugin.

https://github.com/Koenkk/zigbee2mqtt/w ... ed-devices
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 »

This afternoon 3x CC2531 and 1x CC Debugger arrived,

Was able to program all 3 CC2531's in about 5 minutes total, note use the debug cable for the CC2531's not the one that came in the CC Debugger box (I was not able to get a green light with that cable).

Got a Xiaomi push button connected via zigbee2mqtt, so far very impressed!

Can checkout what HomeAssistant have done with their plugin here

https://www.youtube.com/watch?v=uhMrcIA ... e=youtu.be

Code: Select all

2018-8-7 23:34:43 INFO MQTT publish, topic: 'zigbee2mqtt/bridge/log', payload: '{"type":"pairing","message":"device incoming"}'
2018-8-7 23:34:48 INFO MQTT publish, topic: 'zigbee2mqtt/removed', payload: '{"battery":"100.00","voltage":3052,"click":"single"}'
2018-8-7 23:34:53 INFO MQTT publish, topic: 'zigbee2mqtt/removed', payload: '{"battery":"100.00","voltage":3052}'
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

Re: Zigbee2MQTT

Post by salopette »

Cool! How did you connect / set up the stick with Domoticz?

Maybe there is a plugin for domoticz?
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 »

Xiaomi Button Model: WXKG01LM

Functions:
* Click
* Double Click
* Triple Click
* Quadruple Click
* Many Click
* Long Click (Hold for about 1.5 seconds)
* Long Click Button Release

Create selector switch in Domoticz with levels (in order):
click 10
double 20
triple 30
quadruple 40
many 50
long 60
long_release 70

Suggest setting the "Selector Style" of the switch to "Select Menu".

Enter the Zigbee ID into the "Xiaomi Button" MQTT then enter the IDX into the Node Red "Format Data" function

Code: Select all

[{"id":"754b5cba.b792d4","type":"mqtt in","z":"f962b96d.7044c8","name":"zigbee2mqtt/out","topic":"zigbee2mqtt/xiaomitestbutton","qos":"2","broker":"6e165f21.f7645","x":300,"y":40,"wires":[["9f9ffb94.e2bba8"]]},{"id":"9f9ffb94.e2bba8","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":450,"y":40,"wires":[["586c4fb7.44f7d"]]},{"id":"d990bc47.0aa8c","type":"mqtt out","z":"f962b96d.7044c8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"cd51966f.aa7e38","x":750,"y":40,"wires":[]},{"id":"586c4fb7.44f7d","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"// Xiaomi WXKG01LM Button\nif (typeof msg.payload.click !== 'undefined' && msg.payload.click !== null){\nvar click = msg.payload.click.toString();\nvar batt = Math.round(msg.payload.battery);\nmsg.payload.idx = 1217 ;\n\ndelete msg.payload.click;\ndelete msg.payload.duration;\ndelete msg.payload.battery;\ndelete msg.payload.voltage;\n\nif(click == 'single') {\n var level = 10\n} else if (click == 'double') {\n var level = 20\n} else if (click == 'triple') {\n var level = 30\n} else if (click == 'quadruple') {\n var level = 40\n} else if (click == 'many') {\n var level = 50\n} else if (click == 'long') {\n var level = 60\n} else if (click == 'long_release') {\n var level = 70\n}\nmsg.payload.nvalue = 2 ;\nmsg.payload.level = level;\nmsg.payload.svalue = level.toString();\nmsg.payload.Battery = batt;\nreturn msg;\n}","outputs":1,"noerr":0,"x":590,"y":40,"wires":[["d990bc47.0aa8c"]]},{"id":"6e165f21.f7645","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":"cd51966f.aa7e38","type":"mqtt-broker","z":"","name":"Domoticz","broker":"192.168.0.5","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Last edited by ben53252642 on Monday 20 August 2018 0:36, edited 15 times in total.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

Nice! :D
Little trick for beter readability.
This is my configuration.yaml file in my test enviroment. If you change 'friendly_name' to somewhat meaning full.
That name will then be used as the topic name -> 'zigbee2mqtt/ZolderTHB'

Code: Select all

homeassistant: false
permit_join: true
mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://localhost'
serial:
  port: /dev/ttyACM0
  disable_led: true
advanced:
  log_level: info
  channel: 11
devices:
  '0x00158d0001b192fd':
    friendly_name: 'ZolderPIR'
    retain: false
    qos: 1
  '0x00158d00022cbcad':
    friendly_name: 'ZolderTHB'
    retain: false
    qos: 1
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 »

Xiaomi Mi power plug ZigBee (on/off, power measurement) Model: ZNCZ02LM

https://github.com/Koenkk/zigbee2mqtt/w ... ed-devices

Control power plug on / off from Domoticz

Received power usage in Domoticz sensor

Code: Select all

[{"id":"bfb978ea.1c29a8","type":"mqtt in","z":"f962b96d.7044c8","name":"","topic":"domoticz/out","qos":"2","broker":"cd51966f.aa7e38","x":310,"y":140,"wires":[["6e3cd26.8d72b2c"]]},{"id":"c8d4fb13.30ca38","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"// Virtual Sensor Type: Electric (Instant+Counter)\n// Must choose type \"Computed\" or it will not work\nvar power = msg.payload.power.toString();\nmsg.payload.idx = 1215 ;\nmsg.payload.nvalue = 0 ;\nmsg.payload.svalue = power;0;\nreturn msg;\n","outputs":1,"noerr":0,"x":690,"y":200,"wires":[["80442fa5.5053e"]]},{"id":"6d2eec89.b606f4","type":"function","z":"f962b96d.7044c8","name":"Get Device Info","func":"if(msg.payload.idx == '1214') {\nif(msg.payload.nvalue == '0') {\n    msg.payload.state = 'OFF'\n}\nif(msg.payload.nvalue == '1') {\n    msg.payload.state = 'ON'\n}\nreturn msg;\n}","outputs":1,"noerr":0,"x":600,"y":140,"wires":[["3fb0ea7f.fc1cd6"]]},{"id":"6e3cd26.8d72b2c","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":450,"y":140,"wires":[["6d2eec89.b606f4"]]},{"id":"3fb0ea7f.fc1cd6","type":"mqtt out","z":"f962b96d.7044c8","name":"zigbee2mqtt/in","topic":"zigbee2mqtt/massagechair/set","qos":"","retain":"","broker":"cd51966f.aa7e38","x":780,"y":140,"wires":[]},{"id":"a72f1084.5c017","type":"comment","z":"f962b96d.7044c8","name":"Massage Chair Switch","info":"","x":120,"y":140,"wires":[]},{"id":"403248de.8336e8","type":"mqtt in","z":"f962b96d.7044c8","name":"zigbee2mqtt/out","topic":"zigbee2mqtt/massagechair","qos":"2","broker":"6e165f21.f7645","x":400,"y":200,"wires":[["e36288fb.8e9178"]]},{"id":"2c40ce27.36da12","type":"comment","z":"f962b96d.7044c8","name":"Massage Chair Switch Watts Sensor","info":"","x":160,"y":200,"wires":[]},{"id":"e36288fb.8e9178","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":550,"y":200,"wires":[["c8d4fb13.30ca38"]]},{"id":"80442fa5.5053e","type":"mqtt out","z":"f962b96d.7044c8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"cd51966f.aa7e38","x":850,"y":200,"wires":[]},{"id":"cd51966f.aa7e38","type":"mqtt-broker","z":"","name":"Domoticz","broker":"192.168.0.5","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"6e165f21.f7645","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":""}]
CaptureZNCZ02LM.JPG
CaptureZNCZ02LM.JPG (71.23 KiB) Viewed 5028 times

Next up is working on out how control my 6 Phillips Hue lightstrips, implementing it in Node Red then decommissioning my Hue Hub.

I'm really impressed with this Zigbee2MQTT and CC2531 system, I'd be surprised if anyone with Domoticz is using multiple Zigbee hubs in a couple years time. Is this the future? :D

EddyG thanks for the tip!
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 »

EddyG thanks to help from JVDZ it is possible to send the battery status to devices via MQTT

viewtopic.php?f=56&t=24419&p=188355#p188355

Screen Shot 2018-08-10 at 5.24.22 am.png
Screen Shot 2018-08-10 at 5.24.22 am.png (56.26 KiB) Viewed 4979 times
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

Still having trouble with my RTCGQ01LM motion sensor (https://xiaomi-mi.com/sockets-and-senso ... cy-sensor/)
I can only get it working with a Domoticz switch changed to Switch Type 'Motion Sensor'
But that does not allow me to use 'udevice'
Any ideas?
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Zigbee2MQTT

Post by jvdz »

This is an On/Off switch ... right?
What did you specify in the formula for the field values in Node-red?

Jos

Edit: Just tested with a MotionSensor dummy switch and this worked:

Code: Select all

var msg;
msg.payload = {};
msg.payload.idx = 435 ;
var batt = 50;
msg.payload.nvalue = 1 ;
msg.payload.svalue = "On";
msg.payload.Battery = batt;
return msg;
Use this for Off:

Code: Select all

msg.payload.nvalue = 0;
msg.payload.svalue = "Off";
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

Tnx. Yes, that was the trick. :D
Sometimes solutions are sooooo simple...
Pitty that the battery is 100%, although the sensor is already a few months in operation.
Other sensors show already 95%.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee2MQTT

Post by EddyG »

I have looked a little bit further into the battery issue.
Both battery level and voltage are send.
The one that is sending 100% battery level has a voltage of 3.025 Volts
That's more than the nominal voltage of the lithium cell.
I suppose that the internal circuit of measuring voltage is not accurate enough.
Time will tell....
quack3d
Posts: 86
Joined: Sunday 26 March 2017 17:03
Target OS: -
Domoticz version:
Contact:

Re: Zigbee2MQTT

Post by quack3d »

Is there a benefit to using Zigbee2MQTT over ZiGate for instance? https://www.domoticz.com/wiki/Zigate
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest