Zigbee2MQTT

Xiaomi, Ikea TRÅDFRI, Philips Hue and more.
MikeF
Posts: 227
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: Zigbee2MQTT

Post by MikeF » Thursday 11 October 2018 16:05

I've just managed to pair a Hive Active Warm White Light successfully with zigbee2mqtt, by resetting the light as described here: https://github.com/Koenkk/zigbee2mqtt/w ... ng-devices.

However, resetting the light means that the Hive app - and the Domoticz Hive plugin - lose the device. To get it back, I have to reset the bulb, but then zigbee2mqtt seems to lose it - what I am doing wrong? :?

Whilst paired with zigbee2mqtt, I've found that the following topics work:

Code: Select all

topic: zigbee2mqtt/light_2/set payload: {"state": "OFF"}
topic: zigbee2mqtt/light_2/set payload: {"state": "ON"}
topic: zigbee2mqtt/light_2/set payload: {"brightness": 128}
(brightness can be from 0 to 255).
The last two can be combined, e.g.,

Code: Select all

zigbee2mqtt/light_2/set payload: {"state": "ON", "brightness": 255}
I don't know what other messages are available - or how to find out. Any suggestions?

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Thursday 11 October 2018 19:30

You either need to use Zigbee2MQTT or the Hive plugin

If you want to control the device in Domoticz using Zigbee2MQTT this flow should work (import it)

Code: Select all

[{"id":"bfb978ea.1c29a8","type":"mqtt in","z":"f962b96d.7044c8","name":"","topic":"domoticz/out","qos":"2","broker":"cd51966f.aa7e38","x":330,"y":140,"wires":[["6e3cd26.8d72b2c"]]},{"id":"6d2eec89.b606f4","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"var idx = msg.payload.idx;\nvar nvalue = msg.payload.nvalue;\nmsg.payload = {}\n\nif (idx == '1214' && typeof idx !== 'undefined' && idx !== null){\nif(nvalue == '0') {\n    msg.payload.state = 'OFF'\n}\nif(nvalue == '1') {\n    msg.payload.state = 'ON'\n}\n\n\nreturn msg;\n}","outputs":1,"noerr":0,"x":610,"y":140,"wires":[["3fb0ea7f.fc1cd6"]]},{"id":"6e3cd26.8d72b2c","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":470,"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":"cd51966f.aa7e38","type":"mqtt-broker","z":"","name":"MQTT","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
You will need to edit the "Format Data" node (enter the Domoticz virtual switch IDX) and the "zigbee2mqtt/in" node (the name of the device to control in Zigbee2MQTT.

Note this flow is for controlling ON / OFF functions, I'm not going to invest any time in altering it as I don't know if you will be using Zigbee2MQTT for sure, it's probably about 15 minutes work to add brightness controls.

MikeF
Posts: 227
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: Zigbee2MQTT

Post by MikeF » Thursday 11 October 2018 23:51

Thanks for your reply, ben53252642.

Yes, you're right, I don't know (yet) whether I will be using Zigbee2MQTT for sure. I'm quite pleased that I have managed to get a CC2531 sniffer working, and that I have successfully paired it with a Hive Active Light (which is already supported by Zigbee2MQTT). I'm just experimenting at the moment, but I'm inspired by the potential to get rid of the proprietary Hive bridge and control Hive devices fully locally.

As the OP on this thread: 'Read British Gas Hive Heating temperature' (viewtopic.php?f=38&t=6837) I wrote a number of scripts to integrate the Hive Active Heating system with Domoticz. I've only just implemented the Hive plugin which was developed from these by imcfarla and roadsnail, but it appears that I can either use Zigbee2MQTT or the Hive plugin, but not both.

I've imported the flow you produced into Node-RED (thanks), and I'm sure I will be able to extend it to add brightness controls.

I'll keep experimenting!

Mike

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Wednesday 17 October 2018 13:11

A flow I'm using for the Xiaomi Vibration / Tilt / Fall sensor (in this case to detect if the cats kitty litter is cleaning).

Code: Select all

[{"id":"530d5d9f.5093b4","type":"mqtt in","z":"f962b96d.7044c8","name":"zigbee2mqtt/out","topic":"zigbee2mqtt/tiltsensorkittylitter","qos":"2","broker":"6e165f21.f7645","x":340,"y":520,"wires":[["3e7b496c.47da76"]]},{"id":"3e7b496c.47da76","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":490,"y":520,"wires":[["9c2b4c34.56b38"]]},{"id":"50f44b51.8bf294","type":"mqtt out","z":"f962b96d.7044c8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"cd51966f.aa7e38","x":790,"y":520,"wires":[]},{"id":"a631e71a.4e12c8","type":"comment","z":"f962b96d.7044c8","name":"Kitty Litter Tilt Sensor","info":"","x":140,"y":520,"wires":[]},{"id":"9c2b4c34.56b38","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"// Variables\nvar anglex = msg.payload.angle_x;\nvar angley = msg.payload.angle_y;\nvar anglez = msg.payload.angle_z;\nvar anglexabsolute = msg.payload.angle_x_absolute;\nvar angleyabsolute = msg.payload.angle_y_absolute;\nvar rssi = msg.payload.linkquality;\nvar batt = msg.payload.battery;\nvar time = Math.round((new Date()).getTime() / 1000);\n\n// Store battery level in context if received\nif (typeof batt !== 'undefined' && batt !== null && batt >= 1){\n    context.set(\"storedbatterylevel\", batt);\n}\n\n// Get data from context\nvar previousposition = context.get(\"position\");\nvar lastseen = context.get(\"lastseen\");\nvar battery = context.get(\"storedbatterylevel\");\n\n// Variable\nvar secondssincelastseen = (time - lastseen);\n\n// Store position events\nif(angleyabsolute >= 155) {\n    context.set(\"position\", 'Down');\n    var currentposition = 'Down';\n}else if(angleyabsolute < 155) {\n    context.set(\"position\", 'Up');\n    var currentposition = 'Up';\n}\n\n// Conditions for trigger\nif(currentposition !== previousposition && angleyabsolute > 135 && angleyabsolute < 180 && anglexabsolute > 75 && anglexabsolute < 90 && secondssincelastseen > 3 | typeof lastseen === 'undefined') {    \n\n// Clear unwanted objects\nmsg.payload = {}\n\n// Domoticz states\nif(currentposition === 'Down') {\n    var positionstate = 'On'\n    msg.payload.nvalue = 1;\n} else if (currentposition === 'Up') {\n    var positionstate = 'Off'\n    msg.payload.nvalue = 0;\n}\n\ncontext.set(\"lastseen\", time);\nmsg.payload.idx = 1275 ;\nmsg.payload.svalue = positionstate;\nif (typeof battery !== 'undefined' && battery !== null){msg.payload.Battery = Math.round(battery)}\nmsg.payload.position = currentposition;\nrssi = Math.round(rssi / 11);\nif (rssi > 11) {rssi = 11;}\nmsg.payload.RSSI = rssi;\nreturn msg;\n}","outputs":1,"noerr":0,"x":630,"y":520,"wires":[["50f44b51.8bf294"]]},{"id":"6e165f21.f7645","type":"mqtt-broker","z":"","name":"MQTT","broker":"127.0.0.1","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":"MQTT","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
The sensor only sends battery readings occasionally so I've chosen to store them in context as new battery levels are received and re-use the reading when sending data to Domoticz.

salopette
Posts: 46
Joined: Tuesday 07 March 2017 22:03
Target OS: Raspberry Pi
Domoticz version: V3.6882
Location: Germany
Contact:

Re: Zigbee2MQTT

Post by salopette » Sunday 21 October 2018 20:55

I'm a total beginner in node red, could someone maybe do some guidance on how to get the Xiaomi devices in domoticz?
Did Zigbee2Mqtt and the c2531 stick already running, and wanted to embed everything about Node red, but does not know how?

Thank you

MikeF
Posts: 227
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: Zigbee2MQTT

Post by MikeF » Monday 22 October 2018 17:38

ben53252642 wrote:
Sunday 19 August 2018 19:23

I've modified it slightly for a sensor that I just installed (also Xiaomi) but it's for Temp + Hum + Baro in a single sensor.

Code: Select all

[{"id":"ccd928ae.df6e08","type":"mqtt in","z":"f962b96d.7044c8","name":"zigbee2mqtt/out","topic":"zigbee2mqtt/bedroomwindowtempsensor","qos":"2","broker":"6e165f21.f7645","x":340,"y":340,"wires":[["30c7887d.0db668"]]},{"id":"30c7887d.0db668","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":490,"y":340,"wires":[["903fbd0c.967e8"]]},{"id":"37f9ac4c.00d154","type":"mqtt out","z":"f962b96d.7044c8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"cd51966f.aa7e38","x":790,"y":340,"wires":[]},{"id":"903fbd0c.967e8","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"var temp = msg.payload.temperature;\nvar humi = msg.payload.humidity;\nvar pres = msg.payload.pressure;\nvar batt = msg.payload.battery;\nvar rssi = msg.payload.linkquality;\n\nmsg.payload = {}\n\n// Humidity Status\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// Pressure Status\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 =  1221\nmsg.payload.nvalue = 0\nmsg.payload.svalue = temp.toString()+\";\"+humi.toString()+\";\"+humistat+\";\"+pres.toString()+\";\"+forecast;\nif (typeof batt !== 'undefined' && batt !== null){\nmsg.payload.Battery = Math.round(batt);\n}\nif (typeof rssi !== 'undefined' && rssi !== null){\nrssi = Math.round(rssi / 12);\nif (rssi > 12) {\n    rssi = 12;\n}\nmsg.payload.RSSI = rssi;\n}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":340,"wires":[["37f9ac4c.00d154"]]},{"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":""}]
I've just implemented one of these (Xiaomi Aqara WSDCGQ11LM) using this flow, but I'm not clear how often it is supposed to publish messages - I'm getting quite sporadic results:

Code: Select all

zigbee2mqtt:info 2018-10-22 15:33:38 MQTT publish, topic: 'zigbee2mqtt/temp_1', payload: '{"temperature":24.87,"linkquality":162,"humidity":37.1,"pressure":1023.86,"battery":"95.00","voltage":2985}'
zigbee2mqtt:info 2018-10-22 15:33:38 MQTT publish, topic: 'zigbee2mqtt/temp_1', payload: '{"temperature":24.87,"linkquality":162,"humidity":37.1,"pressure":1023,"battery":"95.00","voltage":2985}'
zigbee2mqtt:info 2018-10-22 15:43:10 MQTT publish, topic: 'zigbee2mqtt/temp_1', payload: '{"temperature":24.69,"linkquality":162,"humidity":37.1,"pressure":1023,"battery":"95.00","voltage":2985}'
zigbee2mqtt:info 2018-10-22 15:43:10 MQTT publish, topic: 'zigbee2mqtt/temp_1', payload: '{"temperature":24.69,"linkquality":162,"humidity":36.2,"pressure":1023,"battery":"95.00","voltage":2985}'
zigbee2mqtt:info 2018-10-22 15:43:10 MQTT publish, topic: 'zigbee2mqtt/temp_1', payload: '{"temperature":24.69,"linkquality":162,"humidity":36.2,"pressure":1023,"battery":"95.00","voltage":2985}'
zigbee2mqtt:info 2018-10-22 16:23:39 MQTT publish, topic: 'zigbee2mqtt/temp_1', payload: '{"temperature":24.69,"linkquality":162,"humidity":36.2,"pressure":1023,"battery":"100.00","voltage":3055}'
zigbee2mqtt:info 2018-10-22 16:23:39 MQTT publish, topic: 'zigbee2mqtt/temp_1', payload: '{"temperature":24.46,"linkquality":162,"humidity":34.85,"pressure":1023.38,"battery":"100.00","voltage":3055}'

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Monday 22 October 2018 17:44

MikeF, I wouldn't worry too much, the sensor sends data (when the sensor sends data), I don't believe we have any control over this. I've been getting pretty regular temperature updates which is nice and the battery seems to be holding up well.

MikeF
Posts: 227
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: Zigbee2MQTT

Post by MikeF » Monday 22 October 2018 17:45

OK, thanks!

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Monday 22 October 2018 17:53

Also MikeF there is a new version of that flow which improves handling of the signal RSSI, suggest using the latest version here:

Code: Select all

[{"id":"ccd928ae.df6e08","type":"mqtt in","z":"f962b96d.7044c8","name":"zigbee2mqtt/out","topic":"zigbee2mqtt/bedroomwindowtempsensor","qos":"2","broker":"6e165f21.f7645","x":360,"y":360,"wires":[["30c7887d.0db668"]]},{"id":"30c7887d.0db668","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":510,"y":360,"wires":[["903fbd0c.967e8"]]},{"id":"37f9ac4c.00d154","type":"mqtt out","z":"f962b96d.7044c8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"cd51966f.aa7e38","x":810,"y":360,"wires":[]},{"id":"903fbd0c.967e8","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"var temp = msg.payload.temperature;\nvar humi = msg.payload.humidity;\nvar pres = msg.payload.pressure;\nvar batt = msg.payload.battery;\nvar rssi = msg.payload.linkquality;\n\nmsg.payload = {}\n\nif (typeof temp !== 'undefined' && temp !== null){\n\n// Humidity Status\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// Pressure Status\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 =  1221\nmsg.payload.nvalue = 0\nmsg.payload.svalue = temp.toString()+\";\"+humi.toString()+\";\"+humistat+\";\"+pres.toString()+\";\"+forecast;\nmsg.payload.Battery = Math.round(batt);\nrssi = Math.round(rssi / 11);\nif (rssi > 11) {rssi = 11;}\nmsg.payload.RSSI = rssi;\n\nreturn msg;\n}","outputs":1,"noerr":0,"x":650,"y":360,"wires":[["37f9ac4c.00d154"]]},{"id":"6e165f21.f7645","type":"mqtt-broker","z":"","name":"MQTT","broker":"127.0.0.1","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":"MQTT","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

User avatar
remb0
Posts: 1002
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Zigbee2MQTT

Post by remb0 » Monday 29 October 2018 13:14

I created an article about the project and the python plugin for Domoticz.
credits to the original projects, I only try to combine the info and make it easier for domoticz fans.

I will continue to add info with collected feedback. (if you already have feedback or willing to contribute info pm)
https://gadget-freakz.com/diy-zigbee-gateway/

Furiousz23
Posts: 27
Joined: Saturday 30 December 2017 21:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Zigbee2MQTT

Post by Furiousz23 » Monday 29 October 2018 17:08

@remb0: Great article! I already replied on your FB post about the already flashed usb sticks on marktplaats.nl :mrgreen: . But this topic is also very usefull for me to get all the info i need :). Can`t wait to get started to get rid of the Xiaomi problems i`m experiencing now!

l0gic
Posts: 154
Joined: Tuesday 08 October 2013 9:35
Target OS: Linux
Domoticz version: Latest
Contact:

Re: Zigbee2MQTT

Post by l0gic » Wednesday 31 October 2018 12:38

Morning guys,
I've ordered my kit and currently awaiting delivery so in the meantime I've been setting up node-red and having a play at the command line to get my head around it in preparation for kit arrival.

Looking at the node-red flows that people have posted they all seem to be one way,either into Domoticz or out from Domoticz.
I understand that is fine for things like switches and sensors perhaps but what about hardware like lights?
Is there any process for an 'ack' back from the hardware to indicate the message was received and the new state?
I'm assuming that 'ack' type responses are part of the zigbee protocol, I've looked but been unable to get a definitive answer.

Is the 'ack' path a separate return flow that needs to be built?

In the meantime I'm swimming in the shallow end of the node-red pool. :)

Any clarity would be gratefully received!

Cheers

Kevin
Non credus crepitus

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Wednesday 31 October 2018 13:54

@l0gic there are enough flows developed now that adding support for a new device is mostly just copy and paste.

RE ack, my understanding is what you want could be achieved by tuning into the devices MQTT topic eg:

DomoticzMQTT > Sends on command to a light @ Zigbee2MQTTDEVICE
Zigbee2MQTTDEVICE > listen for response > do whatever you want with it

I haven't gone to this level as I don't see any need for it in my applications but it should be possible.

When you pair a light to Zigbee2MQTT you will get an output in the Zigbee2MQTT console looking something like this:

{"contact":true,"linkquality":70,"battery":"100.00","voltage":3055}

If you post it in this thread we should be able to help you create a flow to control the device if you need assistance.

Cheers

l0gic
Posts: 154
Joined: Tuesday 08 October 2013 9:35
Target OS: Linux
Domoticz version: Latest
Contact:

Re: Zigbee2MQTT

Post by l0gic » Wednesday 31 October 2018 17:05

@ben53252642 thanks for the response.
This is just a thought process at the moment until my kit arrives.

I am not yet that comfortable with the whole zigbee/node-red/Domoticz wrap yet, I'll need some hardware to understand if I will actually need the 'ack' response. Depends on the situation I guess, time will tell.
I was a bit bemused why it didn't seem the be discussed on here, perhaps I'm overthinking things.

I've managed to emulate zigbee hardware using mosquitto_client into node-red and onto Domoticz so I'm feeling quite happy at the moment.

Side question, has anyone had any success with the Ikea kit?
Thinking bulbs, motion detectors and switches. I have all of them so will be interested if anyone has had success.

Cheers

Kevin
Non credus crepitus

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Wednesday 31 October 2018 17:58

I’ve got 22 devices connected to my CC2531 via Zigbee2MQTT

Philips Hue Lightstrips v2
Xiamoi Power Plug
Xiaomi Vibration, Tilt, Fall sensor
Xiaomi Motion Sensor
Xiaomi Door Sensor
Xiaomi Button
Xiaomi Honeywell Smoke Detector
Xiaomi Flood Sensor
Xiaomi Temp Hum Baro Sensor

I've got flows for all the above devices.

I have (currently in the post) the following additional devices which I'll be creating flows for (all motion sensors):

https://www.amazon.com/gp/product/B00TB ... UTF8&psc=1
https://www.amazon.com/gp/product/B0713 ... UTF8&psc=1
https://www.amazon.com/gp/product/B07F8 ... UTF8&psc=1
https://www.aliexpress.com/item/Battery ... 46382.html

I also had one of these on order but recently cancelled it, stock is unavailable. Still I am interested in supporting this sensor if it becomes available.
https://www.amazon.com/gp/product/B07HN ... UTF8&psc=1

l0gic
Posts: 154
Joined: Tuesday 08 October 2013 9:35
Target OS: Linux
Domoticz version: Latest
Contact:

Re: Zigbee2MQTT

Post by l0gic » Wednesday 31 October 2018 18:09

Nice diverse selection you have there!

I've just been playing with node-red and connected a debug directly to domoticz/out
Interesting data flow!
Non credus crepitus

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Wednesday 31 October 2018 18:20

You have to filter the output, eg:

Code: Select all

[{"id":"bfb978ea.1c29a8","type":"mqtt in","z":"f962b96d.7044c8","name":"","topic":"domoticz/out","qos":"2","broker":"cd51966f.aa7e38","x":330,"y":140,"wires":[["6e3cd26.8d72b2c"]]},{"id":"6d2eec89.b606f4","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"var idx = msg.payload.idx;\nvar nvalue = msg.payload.nvalue;\nmsg.payload = {}\n\nif (idx == '1214' && typeof idx !== 'undefined' && idx !== null){\nif(nvalue == '0') {\n    msg.payload.state = 'OFF'\n}\nif(nvalue == '1') {\n    msg.payload.state = 'ON'\n}\n\n\nreturn msg;\n}","outputs":1,"noerr":0,"x":610,"y":140,"wires":[["3fb0ea7f.fc1cd6"]]},{"id":"6e3cd26.8d72b2c","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":470,"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":"cd51966f.aa7e38","type":"mqtt-broker","z":"","name":"MQTT","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Put a debug on the end of Format Data and add a valid IDX of an On / Off switch from Domoticz, you can remove the input to Zigbee2MQTT obviously as you don't yet have it connected.

l0gic
Posts: 154
Joined: Tuesday 08 October 2013 9:35
Target OS: Linux
Domoticz version: Latest
Contact:

Re: Zigbee2MQTT

Post by l0gic » Wednesday 31 October 2018 18:32

ben53252642 wrote:
Wednesday 31 October 2018 18:20
You have to filter the output,
Yup, I only did it to see the format of the messages <just geeking> :)

node-red flow structure question, is it better to have;
1, multiple flows dedicated one per idx / zigbee name plus processes
or
2, one input and have multiple filters and associated processes

I'm guessing 1 for ease future management and support but would be interested in views.

Kevin
Non credus crepitus

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Zigbee2MQTT

Post by ben53252642 » Thursday 01 November 2018 8:40

lOgic, if you have lots of the same device type, eg say 40 roof lights, you can do something like this which I do for my Hue Lightstrips.

Look at the Format Data section, the "zigbee2mqtt/in" values are assigned dynamically.

I wouldn't say I notice any performance difference single vs combined, however I think its easier to create a combined dynamic flow like below if you have many of the same device type.

Code: Select all

[{"id":"fb7148f.58630b8","type":"comment","z":"ecbf4921.26b488","name":"Philips Hue Plus Lightstrips","info":"","x":150,"y":120,"wires":[]},{"id":"48eebee9.f9ecc","type":"mqtt in","z":"ecbf4921.26b488","name":"","topic":"domoticz/out","qos":"2","broker":"cd51966f.aa7e38","x":350,"y":60,"wires":[["a9756327.ccade"]]},{"id":"80a1c890.346428","type":"function","z":"ecbf4921.26b488","name":"Domoticz Control","func":"var idx = msg.payload.idx;\n\n// Domoticz IDX to Zigbee2MQTT Device Name Map\nif (idx == '1258'){\n    devicename = 'lightstrip2ndbathroommirror';\n} else if (idx == '1260'){\ndevicename = 'lightstripkittylitter';\n} else if (idx == '1261'){\ndevicename = 'lightstripmainbathmirror';\n} else if (idx == '1262'){\ndevicename = 'lightstripmbrwardrobe';\n} else {\n    devicename = null;\n}\n\nif (typeof devicename !== 'undefined' && devicename !== null){\n\nvar nvalue = msg.payload.nvalue;\nvar brightness = msg.payload.svalue1;\nvar r = msg.payload.Color.r;\nvar g = msg.payload.Color.g;\nvar b = msg.payload.Color.b;\nvar colortemp = msg.payload.Color.ww;\nmsg.payload = {}\n\nif(nvalue == '0') {\n    msg.payload.state = 'OFF'\n}\nif(nvalue == '1' || nvalue == '10') {\n    msg.payload.state = 'ON';\n    msg.payload.brightness = Math.round(brightness * 255 / 100);\n    if (r === 0 && b === 0 && g === 0) {\n    msg.payload.color_temp = Math.round(500 / 255 * colortemp);\n    msg.payload.transition = 1;\n    }else{\n    msg.payload.color = {\"r\":r,\"g\":g,\"b\":b};\n    msg.payload.transition = 1;\n}\n}\n\nmsg.topic = 'zigbee2mqtt/'+devicename+'/set';\n\nreturn msg;\n}","outputs":1,"noerr":0,"x":650,"y":60,"wires":[["f7ed5194.3f7f9"]]},{"id":"a9756327.ccade","type":"json","z":"ecbf4921.26b488","name":"","property":"payload","action":"","pretty":false,"x":490,"y":60,"wires":[["80a1c890.346428"]]},{"id":"772e44e0.eeb13c","type":"template","z":"ecbf4921.26b488","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n<head></head>\n<body>\n<h1>API:</h1>\n<h3>Usage: /hueapi?devicename=huetest&state=on&brightness=100&r=50&g=170&b=2&colortemp=0&transition=1</h3>\n<h3>or</h3>\n<h3>Usage: /hueapi?devicename=huetest&state=on&brightness=100&r=0&g=0&b=0&colortemp=270&transition=1</h3>\n<h4>Note: this page is always displayed regardless if command is successful or not.</h4>\n</body>\n</html>","x":490,"y":180,"wires":[["bf0118ca.6ffa08"]]},{"id":"d13ff611.844ac8","type":"http in","z":"ecbf4921.26b488","name":"","url":"/hueapi","method":"get","upload":false,"swaggerDoc":"","x":350,"y":120,"wires":[["84c8aed7.2462a","772e44e0.eeb13c"]]},{"id":"bf0118ca.6ffa08","type":"http response","z":"ecbf4921.26b488","name":"","x":610,"y":180,"wires":[]},{"id":"84c8aed7.2462a","type":"function","z":"ecbf4921.26b488","name":"HTTP Control","func":"var state = msg.req.query.state;\nvar brightness = msg.req.query.brightness;\nvar r = msg.req.query.r;\nvar g = msg.req.query.g;\nvar b = msg.req.query.b;\nvar colortemp = msg.req.query.colortemp;\nvar devicename = msg.req.query.devicename;\nvar transition = msg.req.query.transition;\nmsg.payload = {}\n\n\nmsg.payload.state = state;\nmsg.payload.brightness = brightness;\nmsg.payload.transition = transition;\nif (r === '0' && g === '0' && b === '0') {\nmsg.payload.color_temp = colortemp;\n}else{\nmsg.payload.color = {\"r\":r,\"g\":g,\"b\":b};\n}\nmsg.topic = 'zigbee2mqtt/'+devicename+'/set';\n\nreturn msg;\n","outputs":1,"noerr":0,"x":520,"y":120,"wires":[["f7ed5194.3f7f9"]]},{"id":"f7ed5194.3f7f9","type":"mqtt out","z":"ecbf4921.26b488","name":"zigbee2mqtt/in","topic":"","qos":"","retain":"","broker":"cd51966f.aa7e38","x":700,"y":120,"wires":[]},{"id":"cd51966f.aa7e38","type":"mqtt-broker","z":"","name":"MQTT","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Also since Domoticz is limited in its RGBWW control, I created a http api I can call from Lua scripts to get complete control (eg duration of fade when switching on)

http://noderedip:1880/hueapi

Eg from Lua:

Code: Select all

os.execute ('curl -s "http://192.168.0.5:1880/hueapi?devicename=lightstripmbrwardrobe&state=on&brightness=254&r=0&g=0&b=0&colortemp=323&transition=0.5" &')
or with a delay

Code: Select all

os.execute ('(/bin/sleep 4 && /usr/bin/curl -s "http://192.168.0.5:1880/hueapi?devicename=lightstripmainbathmirror&state=on&brightness=254&r=0&g=0&b=0&colortemp=351&transition=0.5")&')

l0gic
Posts: 154
Joined: Tuesday 08 October 2013 9:35
Target OS: Linux
Domoticz version: Latest
Contact:

Re: Zigbee2MQTT

Post by l0gic » Thursday 01 November 2018 12:03

Thanks Ben,
I'll try and group similar types together as you suggest.
I've also found that the comment item can hold enough to enable me to add enough to give me an idea of what flow does what.

...hurry up Mr Postman....
Non credus crepitus

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests