Zigbee2MQTT

Xiaomi, Ikea TRÅDFRI, Philips Hue and more.
l0gic
Posts: 158
Joined: Tuesday 08 October 2013 9:35
Target OS: Linux
Domoticz version: Latest
Contact:

Re: Zigbee2MQTT

Post by l0gic » Friday 07 December 2018 16:23

Hi guys,
my hardware has arrived to day (at last!)
Tried to set up a Xiaomi button switch using the earlier example and hit some issues, only some actions arrived at the Domoticz switch.

Long story short, I've received a Xiaomi Button Model: WXKG11LM rather than a WXKG01LM
This button is feature limited in comparison, it offers just single click, double click, hold and release plus just to add to the fun there is a new payload called action which is related to hold and release.

So I have the following actions with this switch;
"click":"single"
"click":"double"
"action":"hold"
"action":"release"

So I've modified the format data function to the following;

Code: Select all

// Xiaomi Button Model: WXKG11LM

if (typeof msg.payload.click !== 'undefined'){
 var click = msg.payload.click.toString();
 var action = ' ';
}
if (typeof msg.payload.action !== 'undefined'){
 var click = ' ';
 var action = msg.payload.action.toString();
}
var batt = Math.round(msg.payload.battery);
msg.payload.idx = 612 ;

delete msg.payload.click;
delete msg.payload.duration;
delete msg.payload.battery;
delete msg.payload.voltage;

if(click == 'single') {
 var level = 10
} else if (click == 'double') {
 var level = 20
} else if (action == 'hold') {
 var level = 30
} else if (action == 'release') {
 var level = 40
}
msg.payload.nvalue = 2 ;
msg.payload.level = level;
msg.payload.svalue = level.toString();
msg.payload.Battery = batt;
return msg;
which seems to cover the options.

Off to play with the cube next....

p.s. if anyone can tell me how to package up the required flow I'll post it up here.

ATB

Kevin

EDIT Worked out how to export flow

Code: Select all

[{"id":"441a77f0.9c89c8","type":"mqtt in","z":"e136808d.ab3ee","name":"zigbee2mqtt/XiaomiButtonSwitch01","topic":"zigbee2mqtt/XiaomiButtonSwitch01","qos":"2","broker":"a2ca6e39.69968","x":180,"y":260,"wires":[["3298ab7d.304524"]]},{"id":"3298ab7d.304524","type":"json","z":"e136808d.ab3ee","name":"","property":"payload","action":"","pretty":false,"x":410,"y":260,"wires":[["20493cdd.b946d4"]]},{"id":"3e22449b.75b7cc","type":"mqtt out","z":"e136808d.ab3ee","name":"","topic":"domoticz/in","qos":"2","retain":"","broker":"e0b700ec.7593","x":750,"y":260,"wires":[]},{"id":"20493cdd.b946d4","type":"function","z":"e136808d.ab3ee","name":"Format Data","func":"// Xiaomi Button Model: WXKG11LM\n\nif (typeof msg.payload.click !== 'undefined'){\n var click = msg.payload.click.toString();\n var action = ' ';\n}\nif (typeof msg.payload.action !== 'undefined'){\n var click = ' ';\n var action = msg.payload.action.toString();\n}\nvar batt = Math.round(msg.payload.battery);\nmsg.payload.idx = 612 ;\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 (action == 'hold') {\n var level = 30\n} else if (action == 'release') {\n var level = 40\n}\nmsg.payload.nvalue = 2 ;\nmsg.payload.level = level;\nmsg.payload.svalue = level.toString();\nmsg.payload.Battery = batt;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":260,"wires":[["3e22449b.75b7cc"]]},{"id":"6602a106.24e15","type":"comment","z":"e136808d.ab3ee","name":"Xiaomi Button Model: WXKG11LM Multi Click","info":"","x":210,"y":220,"wires":[]},{"id":"a2ca6e39.69968","type":"mqtt-broker","z":"","name":"Domoticz box MQTT","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":"e0b700ec.7593","type":"mqtt-broker","z":"","name":"Domoticz box MQTT","broker":"localhost","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 l0gic on Friday 07 December 2018 21:17, edited 1 time in total.
Non credus crepitus

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

Re: Zigbee2MQTT - Xiaomi Cube Model: MFKZQ01LM

Post by l0gic » Friday 07 December 2018 21:09

Well I've had a quick go with the cube and have produced the following,

Code: Select all

[{"id":"f9e0eecc.48aaa","type":"mqtt in","z":"e136808d.ab3ee","name":"zigbee2mqtt/XiaomiCube01","topic":"zigbee2mqtt/XiaomiCube01","qos":"2","broker":"a2ca6e39.69968","x":140,"y":160,"wires":[["d9b2d9f0.43b598"]]},{"id":"d9b2d9f0.43b598","type":"json","z":"e136808d.ab3ee","name":"","property":"payload","action":"","pretty":false,"x":370,"y":160,"wires":[["a0bb21a6.0e61a"]]},{"id":"ad324acf.bc69e8","type":"mqtt out","z":"e136808d.ab3ee","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"e0b700ec.7593","x":730,"y":160,"wires":[]},{"id":"a0bb21a6.0e61a","type":"function","z":"e136808d.ab3ee","name":"Format Data","func":"// Xiaomi Cube Model: MFKZQ01LM\nif (typeof msg.payload.action !== 'undefined' && msg.payload.action !== null){\nvar action = msg.payload.action.toString();\nvar batt = Math.round(msg.payload.battery);\nmsg.payload.idx = 613 ;\n\ndelete msg.payload.action;\ndelete msg.payload.duration;\ndelete msg.payload.battery;\ndelete msg.payload.voltage;\ndelete msg.payload.linkquality;\ndelete msg.payload.from_side;\ndelete msg.payload.to_side;\ndelete msg.payload.angle;\ndelete msg.payload.side;\n\nif(action == 'slide') {\n var level = 10\n} else if (action == 'rotate_left') {\n var level = 20\n} else if (action == 'rotate_right') {\n var level = 30\n} else if (action == 'flip90') {\n var level = 40\n} else if (action == 'flip180') {\n var level = 50\n} else if (action == 'shake') {\n var level = 60\n} else if (action == 'fall') {\n var level = 70\n} else if (action == 'tap') {\n var level = 80\n} else if (action == 'wakeup') {\n var level = 90\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":530,"y":160,"wires":[["ad324acf.bc69e8"]]},{"id":"fe568972.353bd8","type":"comment","z":"e136808d.ab3ee","name":"Xiaomi Cube Model: MFKZQ01LM","info":"","x":160,"y":120,"wires":[]},{"id":"a2ca6e39.69968","type":"mqtt-broker","z":"","name":"Domoticz box MQTT","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":"e0b700ec.7593","type":"mqtt-broker","z":"","name":"Domoticz box MQTT","broker":"localhost","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 stripped out the following for now,
  • from_side (side 0 - 5) Used with flip actions
  • to_side (side 0 - 5) Used with flip actions
  • angle (+ve if rotated right, -ve if rotated left) Used with rotate actions
  • side (0 - 5 used with tap to indicate upper face) Used with rotate actions
If required I guess they could be used but there is no obvious 'sideness' to the cube apart from the logo on the top.
Hence being stripped for now.

Having fun :D

I need to buy some different ones now I'm satisfied that it all works well!

Kevin
Non credus crepitus

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

Re: Zigbee2MQTT

Post by ben53252642 » Friday 07 December 2018 23:04

Very cool! I was going to say writing a flow for the cube would be one of the harder flows to write but you seem to be doing well.

I've got a git folder here that I've been adding various flows to (I need to update it), some of the flows in this thread are more up to date.

Feel free to create folders and add there if you like (it's linked to from the Admin Panel).

https://github.com/ben423423n32j14e/zig ... adminpanel

https://github.com/ben423423n32j14e/zig ... er/devices

To export from Node-Red, select the nodes you want to export, go into the menu at top right, click export and then clipboard. It's as simple as copy and paste.

Cheers

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

Re: Zigbee2MQTT

Post by l0gic » Saturday 08 December 2018 0:32

Cheers!
The flow above for the cube includes the following,
slide = 10
rotate_left = 20
rotate_right = 30
flip90 = 40
flip180 = 50
shake = 60
fall = 70
tap = 80
wakeup = 90

I'm now setting up the code in lua to get the cube to actually do stuff, not convinced wakeup is of any real use as it only happens when the cube actually wakes up after inactivity.

cheers
Non credus crepitus

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

Re: Zigbee2MQTT

Post by l0gic » Saturday 08 December 2018 12:09

Morning Ben,
just installed your Admin Panel and I've hit issues.
I get a continuous

node: e3c890e4.398e2
function : (error)
"TypeError: Cannot read property
'length' of undefined"

in the debug panel

The url page displays but is blank in that it doesn't carry any information, only the sections (Devices, Status, Permit join/ Remove device, Logging level/Rename device) are visible.

I've tried regrabbing the flow in case there was any dodgy characters without any success.
I've disabled it for now but any pointers would be appreciated.
Non credus crepitus

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

Re: Zigbee2MQTT

Post by ben53252642 » Sunday 09 December 2018 2:09

"'length' of undefined" means it's not getting data from Zigbee2MQTT (a configuration issue).

Double check the configuration of all the MQTT nodes (looking in each of the sub flows).

Eosfoto
Posts: 5
Joined: Wednesday 07 November 2018 13:06
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: @Home
Contact:

Re: Zigbee2MQTT

Post by Eosfoto » Sunday 09 December 2018 18:03

Is there somewhere a workaround how to get it working on a Synology NAS?
And if there isn't, would someone be so nice and help me with this over PM?

User avatar
EddyG
Posts: 334
Joined: Monday 02 November 2015 6:54
Target OS: Raspberry Pi
Domoticz version: 4.10252
Location: Rhenen, Netherlands
Contact:

Re: Zigbee2MQTT

Post by EddyG » Sunday 16 December 2018 14:55

How can I prevent that Zigbee2MQTT clutters my syslog file with all zigbee2mqtt messages which also go to my 'normal' logfile?
Regards,
Eddy

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

Re: Zigbee2MQTT

Post by ben53252642 » Sunday 16 December 2018 15:17

EddyG, I start every component of my system manually in a particular order.

For example at the top of the script, startup is aborted if the system can not confirm it has the correct time:

Code: Select all

# Set timezone and get the current time from NTP server
export TZ=Australia/Melbourne
settime=$(ntpdate time.google.com 2> /dev/null)
if [[ ! $settime ]]; then
echo "Unable to get time, retrying..."
settime=$(ntpdate time.google.com 2> /dev/null)
sleep 1
if [[ ! $settime ]]; then
echo "Unable to get time, aborting..."
exit
fi
fi
Eg, I have an entry in /etc/init.d for "startup" which is just a bash file which I've got then starting every component.

This is how I am starting Zigbee2MQTT on my system:

Code: Select all

# Zigbee2MQTT
update-rc.d zigbee2mqtt disable # Make sure auto start via init is disabled
service zigbee2mqtt stop # Make sure the service is stopped
mkdir -p /tmp/zigbee2mqtt/log
ln -sf /tmp/zigbee2mqtt/log.txt /opt/zigbee2mqtt/data/log.txt
ln -sf /tmp/zigbee2mqtt/state.json /opt/zigbee2mqtt/data/state.json
ln -sf /tmp/zigbee2mqtt/log /opt/zigbee2mqtt/data
service zigbee2mqtt start
/etc/init.d/zigbee2mqtt

Code: Select all

#!/bin/sh
### BEGIN INIT INFO
# Provides: echobridge
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop:
# Description: Starts Amazon Echo Hue Bridge
### END INIT INFO

case "$1" in
'start')
        cd /opt/zigbee2mqtt
        sudo -u root /usr/bin/screen -S zigbee2mqtt -d -m npm start
        ;;
'stop')
        sudo -u root pkill -f "zigbee2mqtt"
        ;;
*)
        echo "Usage: $0 { start | stop }"
        ;;
esac
exit 0
As you can see I create symlinks for the log files and put them to tmp in ram to save writes to the disk.

I've got dozens of symlinks putting various files to tmp / ram, very rarely will I let log files actually touch the hard disk (writes to disk always decrease the life expectancy of storage).

User avatar
EddyG
Posts: 334
Joined: Monday 02 November 2015 6:54
Target OS: Raspberry Pi
Domoticz version: 4.10252
Location: Rhenen, Netherlands
Contact:

Re: Zigbee2MQTT

Post by EddyG » Sunday 16 December 2018 15:41

The question was/is how do I prevent that the logging which is going to dir /var/log/zigbee also goes to the syslog file in /var/log/syslog.
The logging is double and I do not need the logging in my syslog file.

Logging to tmp files in ram does not give answer on system crashes, because logging is gone.

I am using Berryboot so I do not have to worry about degrading SD-card or harddisks.
B.t.w. that works perfect, a Berryboot on my Synology, where I make snapshots every hour for 3 months.
Regards,
Eddy

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

Re: Zigbee2MQTT

Post by ben53252642 » Sunday 16 December 2018 15:45

Not sure, I suggest posting in the Zigbee2MQTT git.

Agree RE the Berryboot setup, I've run that before, it's probably the best Raspberry Pi setup for Domoticz I know of.

That said I now consider ECC memory to be absolutely critical in my setup so I've moved to a proper server.

Dual cpu's each 8 core Xeon, with 48gb of ECC ram and 3500mb read / 2500mb write SSD with 10gbe networking. :)

User avatar
EddyG
Posts: 334
Joined: Monday 02 November 2015 6:54
Target OS: Raspberry Pi
Domoticz version: 4.10252
Location: Rhenen, Netherlands
Contact:

Re: Zigbee2MQTT

Post by EddyG » Sunday 16 December 2018 16:08

I have a solution, but that is a workaround.
Something like that should be in the Zigbee2MQTT config file.
Regards,
Eddy

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest