Open noppie opened 4 years ago
Nobody?
One thing I've found is that zigbee2mqtt encodes the bare JS tokens true
and false
, whereas mqttthing needs the strings 'true'
and 'false'
. So maybe try
return JSON.parse(message).state?'true':'false'
Mqttthing now accepts true and false directly too, which may help.
Did you get this working? If not, perhaps you could share the MQTT messages the Tradfi switches send and I’ll test...
I would like to do the same thing. In answer to arachnetech, this is the MQTT message:
[OnOffController] Received MQTT: zigbee2mqtt/0xccccccfffee3a12f = {"update_available":true,"linkquality":18,"click":"on"}
On the basis that "click" is the payload topic, this is the Config I used I also used ".state" as well, neither worked:
{ "accessory": "mqttthing", "type": "switch", "name": "OnOffController", "onValue": "ON", "offValue": "OFF", "topics": { "getOn": { "topic": "zigbee2mqtt/0xccccccfffee3a12f", "apply": "return JSON.parse(message).click" }, "setOn": "zigbee2mqtt/0xccccccfffee3a12f/set" }, "logMqtt": true }
Apologies for my ignorance if this is a really simple fix, but I am newbie to this
The JSON in your MQTT has a lower-case on
, but your onValue
is ON
. MQTT-Thing is case-sensitive, so I suspect you need to change to:
"onValue": "on",
"offValue": "off",
... or you could use (also untested) the JSON codec like this:
{
"accessory": "mqttthing",
"type": "switch",
"name": "OnOffController",
"onValue": "on",
"offValue": "off",
"topics": {
"getOn": "zigbee2mqtt/0xccccccfffee3a12f",
"setOn": "zigbee2mqtt/0xccccccfffee3a12f/set"
},
"logMqtt": true,
"codec": "json",
"jsonCodec": {
"properties": {
"on": "click"
}
}
}
Thanks to @arachnetech I've finally got my switch to work.
The click
event is deprecated. It’s recommended to use the action
event instead. You can set it in the zigbee2mqtt configuration.yaml
https://www.zigbee2mqtt.io/devices/E1743.html
You can even get the battery level:
{
"accessory": "mqttthing",
"type": "switch",
"name": "OnOffController",
"url": "mqtt://192.168.0.XXX",
"onValue": "on",
"offValue": "off",
"topics": {
"getOn": {
"topic": "zigbee2mqtt/0xec1bbdfffe9a3948",
"apply": "return JSON.parse(message).action;"
},
"setOn": "zigbee2mqtt/0xec1bbdfffe9a3948/set",
"getBatteryLevel": {
"topic": "zigbee2mqtt/0xec1bbdfffe9a3948",
"apply": "return JSON.parse(message).battery;"
}
},
"integerValue": false,
"logMqtt": true
},
I've added the config to the wiki @arachnetech
Did anyone manage to add the Ikea Tradfri Switch? (On-OFF) and long press to dim the lights?
Tried this: { "accessory": "mqttthing", "type": "switch", "name": "OnOffController", "onValue": "ON", "offValue": "OFF", "topics": { "getOn": { "topic": "zigbee2mqtt/ID", "apply": "return JSON.parse(message).state" }, "setOn": "zigbee2mqtt/ID/set" } }
But it doesn't work