MQTT Switch to Set and Get State of Decoupling of Xiaomi Switch(es)

I have a number of wired Xiaomi wall switches around the house with some of the buttons directly controlling the power relay(s) and others decoupled so that the power relay is constantly on and the bulbs, being powered, are controlled (on/off/brightness) over zigbee.

Typically you would only need to decouple the switch once and that’s it, but I’d like to set up MQTT switches to monitor the states of the switch buttons’ decoupling modes and be able to set the state, by turning on/off the MQTT switch.

The Z2M page for the switch has the MQTT topics and payloads required for setting and getting the states, but I’m not sure how to use these in the MQTT switch configuration, especially since the get topic calls with a payload, but needs to listen to a different topic and its payload to confirm the state.

E.g.:

Set:
Topic: zigbee2mqtt/[FRIENDLY_NAME]/system/set
Payload: "{“operation_mode”: {“button”: “left”, “state”: “decoupled”}}

Get:
Topic: zigbee2mqtt/[FRIENDLY_NAME]/system/get
Payload: "{“operation_mode”: {“button”: “left”}}

Get response:
Topic: zigbee2mqtt/[FRIENDLY_NAME]
Payload: {“operation_mode_right”:“control_left_relay”}

Can the MQTT switch handle this or do I need to use an additional sensor to listen for the response and then use the value in a value_template for the MQTT switch?

This is my attempt thus far, pretty sure it’s not going to work though:

- platform: mqtt
    name: "Lounge Coupling Button Left"
    state_topic: "zigbee2mqtt/Lounge Double Wired Wall Switch/system/get"
    state_on: "{\"operation_mode\": {\"button\": \"left\"} }"
    state_off: "{\"operation_mode\": {\"button\": \"left\"} }"
    command_topic: "zigbee2mqtt/Lounge Double Wired Wall Switch/system/set"
    payload_on: "{\"operation_mode\": {\"button\": \"left\",\"state\": \"control_left_relay\"} }"
    payload_off: "{\"operation_mode\": {\"button\": \"left\",\"state\": \"decoupled\"} }"

Any help is greatly appreciated.

Hi all, I’m also facing the same problem. I have tried googling and this is the closest I got.

Hi, i want to have a simple switch on off to be able to enable/disale a motion sensor, i can’t get it to work … a simple boolean toogle switch is it too much to ask ?

i have aqara motion sensor, phillips hue lights and i managed the turn on/off in nodered

i came from nodered, i had all my light and motion sensor working in nodered, i’m changing to HA but keeping the business in nodered (love the flows) and in nodered dashboard, it is so simple to add a toogle switch =(, i’m happy to have HA now but the YAML will gonna kill me, it is horrific

thanks for reading

I discovered the helpers inputBoolean it work well :slight_smile: