Page 1 of 14

Zigbee2MQTT

Posted: Sunday 27 May 2018 9:36
by 1981nick1981
During my experiments with home assistant I came across the project zigbee2mqtt. This project uses parts that are available on Ali Express to make a zigbee hub. Which makes the hub of xiaomi, hue, ikea, etcetera unnecessary. I think this will probably also work with domoticz.

https://github.com/Koenkk/zigbee2mqtt

Wiki:
https://github.com/Koenkk/zigbee2mqtt/wiki

Re: Zigbee2MQTT

Posted: Wednesday 11 July 2018 16:13
by blauwebuis
Did you get this to work? Looks awesome.

Re: Zigbee2MQTT

Posted: Tuesday 17 July 2018 8:25
by 1981nick1981
This works well in Home Assistant. Even the Aqara cube that does not work via the gateway works with this. Normally this should also be able to work with domoticz, but then a driver needs to be made.

Re: Zigbee2MQTT

Posted: Wednesday 18 July 2018 10:49
by blauwebuis
A driver?

Isn't this already a driver that translates signals to MQTT? So doesn't Domoticz just need to pull in the MQTT messages?

Re: Zigbee2MQTT

Posted: Thursday 19 July 2018 21:46
by EddyG
I got it running on my test system.
The reason I am doing this that my Xiaomi gateway only connects to a Chinees server.
So all? traffic is going to China, and I do not want that.
Now I am looking for a way to translate to messages to the 'domoticz/in' and 'domoticz/out'
The topics I get are:
domoticz/bridge/log
domoticz/0x00158d00022cbcad
where 0x00158d00022cbcad is the Zigbee device (address).
Could anyone point me the way how to resolve this?

Re: Zigbee2MQTT

Posted: Thursday 19 July 2018 22:41
by jvdz
EddyG wrote: Thursday 19 July 2018 21:46 Now I am looking for a way to translate to messages to the 'domoticz/in' and 'domoticz/out'
The topics I get are:
domoticz/bridge/log
domoticz/0x00158d00022cbcad
where 0x00158d00022cbcad is the Zigbee device (address).
Could anyone point me the way how to resolve this?
Interesting topic.
Node-red should be able to receive, translate and send those message to Domoticz.

Jos

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 12:41
by EddyG
I got it almost working in node-red.
I already converted this output from the zigbee device

Code: Select all

{ temperature: 26.29, humidity: 57.7, pressure: 1004, battery: "88.33", voltage: 2965 }
to

Code: Select all

{ idx: 21, nvalue: 0, svalue: 26.29 }
My domoticz log shows:

Code: Select all

2018-07-21 12:34:15.639 MQTT: Topic: domoticz/in, Message: {"idx":21,"nvalue":0,"svalue":25.9}
2018-07-21 12:34:15.438 Error: MQTT: Invalid data received!
The problem lies proberly in the "svalue":25,9
How can I convert the property "svalue":25,9 to "svalue": "25,9" (2 double quotes extra for string.)
Because when I do this command it works.

Code: Select all

 mosquitto_pub -h localhost -m '{ "idx" : 21, "nvalue" : 0, "svalue" : "25.0" }' -t 'domoticz/in'
I am new in node-red, so it might be very simpel

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 14:01
by EddyG
In the meantime I found the answer.
I put a function inbetween the JSON output and the assembly of the new JSON object.
The .toString() did the job, like I wrote, its easy.
But there might be better ways to do it, please tell....

At the end I now have Zigbee2MQTT hardware and software working with domoticz without the Chinese in the middle.
And btw it is cheap too. Total cost for controller and flashing tool from AliExpress € 22,32
I go on trying to connect other Zigbee devices too.

I also got the joined Temperature/Humidity device working, but only with a fixed Humidity status of 'Comfortable'
Barometer device (same unit) is working too.
Does anyone have a javascript to calculate Temperature and Humidity to a Humidity Status?
Does anyone have an idea how to calculate the Prediction?

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 16:28
by EddyG
:D Got humidity status and prediction working too.
Node-red is more valuable then I tought. :D

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 16:37
by ben53252642
This needs to be integrated into Domoticz asap!

Finally a solution to replace the 3 proprietary zigbee hubs in my setup. Will lower the cost of using Zigbee since I won't need to maintain 3 separate hubs and reduce power usage. :)

I've just ordered a few dongles (I always keep a couple of spare controllers), I don't have the skills to integrate this directly into Domoticz but I can create scripts to do it manually.

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 17:07
by tezzlicious
Just got it up and running. Has some great potential. The range is also quite nice, picking up the Aqara Door Sensor from approx. 25-30 meters in the garden with 2 walls in between. Wish I had the time to explore it further. Looking forward to progress being made on this.

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 17:57
by ben53252642
Hardware requirements

I was able to get:

1x CC Debugger
https://www.aliexpress.com/item/Wholesa ... 74637.html

1x Download cable
https://www.aliexpress.com/item/Downloa ... 78130.html

3x CC2531 USB Adapters
https://www.aliexpress.com/item/Wireles ... 63830.html

With epacket delivery 13 - 20 days to Australia for a total of $72.23 AUD.

Pretty reasonable considering I got THREE usb adapters when I'd usually be paying around $85 AUD for a single Z-Wave stick...

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 19:34
by EddyG
tezzlicious wrote: Saturday 21 July 2018 17:07 Just got it up and running. Has some great potential. The range is also quite nice, picking up the Aqara Door Sensor from approx. 25-30 meters in the garden with 2 walls in between. Wish I had the time to explore it further. Looking forward to progress being made on this.
Did also get the data in Domoticz via Node-red, or an other way?

Re: Zigbee2MQTT

Posted: Saturday 21 July 2018 23:43
by jvdz
EddyG wrote: Saturday 21 July 2018 16:28 :D Got humidity status and prediction working too.
Node-red is more valuable then I tought. :D
Could you share the node-red code please as I like to do something similar?

Cheers,
Jos

Re: Zigbee2MQTT

Posted: Sunday 22 July 2018 9:58
by EddyG
Sure, no problem. I was already intended to do that.
I got these running.
https://xiaomi-mi.com/sockets-and-senso ... ty-sensor/
https://xiaomi-mi.com/sockets-and-senso ... cy-sensor/

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":""}]

Re: Zigbee2MQTT

Posted: Sunday 22 July 2018 10:49
by jvdz
Thanks for sharing the code... Looks fine to me but Iám not a Node-red buff either yet. :D
I think you took the logic for the forcast from buien radar?
Either way I believe you missed one piece of the logic and think it should be:

Code: Select all

	if (pres < 966) {
		forecast = "4"
	} else if (pres < 993) {
		forecast = "3"
	} else if (pres < 1007) {
		forecast = "2"
	} else if (pres < 1013) {
		forecast = "3"
	} else if (pres < 1033) {
		forecast = "0"
	} else {
		forecast = "1"
	}
Jos

Re: Zigbee2MQTT

Posted: Sunday 22 July 2018 10:58
by EddyG
Tnx. Yes I found the code logic in buienrader and was to hasty. :mrgreen:
And the initialisation of the vars I now set to:

Code: Select all

var forecast = "1"
var humistat = "0"

Re: Zigbee2MQTT

Posted: Sunday 22 July 2018 11:38
by ben53252642
EddyG I've successfully imported your code into Node-Red (very nice)!

One thing I noticed, you have seperate temp+hum and baro sensor (idx 552 and 553), you know you can have a combined Temp+Hum+Baro sensor in Domoticz?

Look in the create virtual sensor.

Re: Zigbee2MQTT

Posted: Sunday 22 July 2018 11:51
by EddyG
Yes, I know.
But I 'hate' the fact that those devices have the same name in both Domoticz Menus.
That is why I seperated those devices. But you can ofcourse have output to 1 Domoticz device.

Re: Zigbee2MQTT

Posted: Sunday 22 July 2018 15:28
by ben53252642
EddyG wrote: Sunday 22 July 2018 9:58 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.
Try this example (editing as needed) for the battery, if the result is not more than 1 it should fail so a null doesn't get sent.

Code: Select all

-- inputvoltage
var inputvoltage = msg.payload[1].value;
    inputvoltagestr = inputvoltage.toString();
    inputvoltageint = inputvoltagestr.substring(0, inputvoltagestr.length-1);
if (inputvoltageint > 1) {
    msg.payload.inputvoltage = inputvoltageint
}
Put this in a debug connected to it: msg.payload.inputvoltage