Open broadcastthebadger opened 4 years ago
I have the 6 button Aqara Opple Switch. Able to set it up, here is my script.
Had an issue before as I need to update my Zigbee2MQTT, and re-pair the Opple Switch
{ "accessory": "mqttthing", "type": "statelessProgrammableSwitch", "name": "Room Multi Switch", "topics": { "getSwitch": [ { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return JSON.parse(message).action;" }, { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return JSON.parse(message).action;" }, { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return JSON.parse(message).action;" }, { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return JSON.parse(message).action;" }, { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return JSON.parse(message).action;" }, { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return JSON.parse(message).action;" } ], "getBatteryLevel": { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return JSON.parse(message).battery;" }, "getStatusLowBattery": { "topic": "zigbee2mqtt/0x04cf8cdf3c791ad9", "apply": "return message < 20;" } }, "switchValues": [ [ "button_1_single", "button_1_double", "button_1_hold" ], [ "button_2_single", "button_2_double", "button_2_hold" ], [ "button_3_single", "button_3_double", "button_3_hold" ], [ "button_4_single", "button_4_double", "button_4_hold" ], [ "button_5_single", "button_5_double", "button_5_hold" ], [ "button_6_single", "button_6_double", "button_6_hold" ] ], "restrictSwitchValues": [ 0, 1, 2 ], "logMqtt": true }
@broadcastthebadger You're sending JSON to MQTT-Thing, so you need to decode this either with an apply function (https://github.com/arachnetech/homebridge-mqttthing/blob/master/docs/Configuration.md#apply-functions) or using the JSON codec (https://github.com/arachnetech/homebridge-mqttthing/blob/master/docs/Codecs.md#json-codec-json).
For the latter, you'd need to add something like:
"codec": "json",
"jsonCodec": {
"properties": {
"switch": "action"
}
}
Also switchValues
must be an array of 3 switch values corresponding to single-press, double-press and long-press respectively, and shouldn't be inside topics
.
Confirmed: the following config works for me:
{
"accessory": "mqttthing",
"type": "statelessProgrammableSwitch",
"name": "4 Way Switch",
"url": "homebridge",
"logMqtt": true,
"topics": {
"getOnline": "zigbee2mqtt/bridge/state",
"getSwitch": "zigbee2mqtt/0x04cf8cdf3c791ad9"
},
"switchValues": [
"button_1_single",
"button_1_double",
"button_1_hold"
],
"codec": "json",
"jsonCodec": {
"properties": {
"switch": "action"
}
}
}
[7/20/2020, 00:00:43] [4 Way Switch] Received MQTT: zigbee2mqtt/0x04cf8cdf3c791ad9 = {"linkquality":115,"battery":100,"voltage":3116,"action":"button_1_double"}
[7/20/2020, 00:00:43] [4 Way Switch] Received button_1_double - switch state is now 1
[7/20/2020, 00:01:11] [4 Way Switch] Received MQTT: zigbee2mqtt/0x04cf8cdf3c791ad9 = {"linkquality":115,"battery":100,"voltage":3116,"action":"button_1_single"}
[7/20/2020, 00:01:11] [4 Way Switch] Received button_1_single - switch state is now 0
[7/20/2020, 00:01:19] [4 Way Switch] Received MQTT: zigbee2mqtt/0x04cf8cdf3c791ad9 = {"linkquality":115,"battery":100,"voltage":3116,"action":"button_1_hold"}
[7/20/2020, 00:01:19] [4 Way Switch] Received button_1_hold - switch state is now 2
Thanks, @the3future - your example shows the 'apply function' method which I'm sure would work perfectly for @broadcastthebadger too. It's slightly more flexible as you can do different/additional processing on different topics (as you're doing with 'low battery').
@arachnetech thanks for the advice. I've updated my config file to match yours and read as so...
{
"accessory": "mqttthing",
"type": "statelessProgrammableSwitch",
"name": "4 Way Switch",
"username": "XXXX",
"password": "XXXX",
"logMqtt": true,
"topics": {
"getSwitch": [
{
"getOnline": "zigbee2mqtt/bridge/state",
"topic": "zigbee2mqtt/4wayswitch"
},
{
"getOnline": "zigbee2mqtt/bridge/state",
"topic": "zigbee2mqtt/4wayswitch"
},
{
"getOnline": "zigbee2mqtt/bridge/state",
"topic": "zigbee2mqtt/4wayswitch"
},
{
"getOnline": "zigbee2mqtt/bridge/state",
"topic": "zigbee2mqtt/4wayswitch"
}
]
},
"switchValues": [
[
"button_1_single",
"button_1_double",
"button_1_hold"
],
[
"button_2_single",
"button_2_double",
"button_2_hold"
],
[
"button_3_single",
"button_3_double",
"button_3_hold"
],
[
"button_4_single",
"button_4_double",
"button_4_hold"
],
{
"codec": "json",
"jsonCodec": {
"properties": {
"switch": "action"
}
}
}
]
},
[7/20/2020, 10:12:40] [4 Way Switch] Received MQTT: zigbee2mqtt/4wayswitch = {"linkquality":99,"battery":100,"voltage":3125,"action":"button_1_single"}
[7/20/2020, 10:12:40] [4 Way Switch] Warning: switch0 received [{"linkquality":99,"battery":100,"voltage":3125,"action":"button_1_single"}] which is not in configured values {"button_1_single":0,"button_1_double":1,"button_1_hold":2}
[7/20/2020, 10:12:40] [4 Way Switch] Warning: switch1 received [{"linkquality":99,"battery":100,"voltage":3125,"action":"button_1_single"}] which is not in configured values {"button_2_single":0,"button_2_double":1,"button_2_hold":2}
[7/20/2020, 10:12:40] [4 Way Switch] Warning: switch2 received [{"linkquality":99,"battery":100,"voltage":3125,"action":"button_1_single"}] which is not in configured values {"button_3_single":0,"button_3_double":1,"button_3_hold":2}
[7/20/2020, 10:12:40] [4 Way Switch] Warning: switch3 received [{"linkquality":99,"battery":100,"voltage":3125,"action":"button_1_single"}] which is not in configured values {"button_4_single":0,"button_4_double":1,"button_4_hold":2}
If I change the switch values to
"switchValues": [
{
"button_1_single": 0,
"button_1_double" : 1,
"button_1_hold": 2
},
Then I get this output
[7/20/2020, 10:08:38] [4 Way Switch] Warning: switch0 received [{"linkquality":84,"battery":100,"voltage":3125,"action":"button_1_release"}] which is not in configured values {"[object Object]":4}
[7/20/2020, 10:08:38] [4 Way Switch] Warning: switch1 received [{"linkquality":84,"battery":100,"voltage":3125,"action":"button_1_release"}] which is not in configured values {"[object Object]":4}
[7/20/2020, 10:08:38] [4 Way Switch] Warning: switch2 received [{"linkquality":84,"battery":100,"voltage":3125,"action":"button_1_release"}] which is not in configured values {"[object Object]":4}
[7/20/2020, 10:08:38] [4 Way Switch] Warning: switch3 received [{"linkquality":84,"battery":100,"voltage":3125,"action":"button_1_release"}] which is not in configured values {"[object Object]":4}
Could you get a single switch to work using my config?
switchValues
needs to be an array of values, or an array of arrays of values for multiple switches. It shouldn't be an array of objects.
However, I think the main problem is that you've put this inside switchValues
:
{
"codec": "json",
"jsonCodec": {
"properties": {
"switch": "action"
}
}
}
codec
and jsonCodec
need to be at the same level as logMqtt
and topics
.
The single setup you suggested worked fine but trying to impliment the same getswitch topic broke the configuration
Here's my config for 2 switches. Give it a try:
{
"accessory": "mqttthing",
"type": "statelessProgrammableSwitch",
"name": "ButtonIKEA",
"url": "mqtt://x.x.x.x",
"logMqtt": true,
"topics": {
"getOnline": "zigbee2mqtt/bridge/state",
"getSwitch": [
"zigbee2mqtt/buttonIKEA",
"zigbee2mqtt/buttonIKEA"
]
},
"switchValues": [
[
"on",
"brightness_move_up",
"brightness_stop"
],
[
"off",
"brightness_move_down",
"brightness_stop"
]
],
"restrictSwitchValues": [
0,
1
],
"codec": "json",
"jsonCodec": {
"properties": {
"switch0": "action",
"switch1": "action"
}
}
}
Aqara stateless switch not working. Homebridge logs show that MQTT messages are being received by MQTTThing but the switch values are causing a problem. Having followed the guide on how to change the default switch values, the problem continues. Config and logs below...
Config file: "type": "statelessProgrammableSwitch", "name": "4 Way Switch", "username": "pi", "password": "Architects", "logMqtt": true, "topics": { "getOnline": "zigbee2mqtt/bridge/state", "getSwitch": "zigbee2mqtt/0x04cf8cdf3c791ad9", "switchValues": { "button_1_single": 0, "button_1_double": 1, "button_1_hold": 2 } }, "accessory": "mqttthing"
Logs: