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