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

Tags: #<Tag:0x00007f7398959fd0> #<Tag:0x00007f7398959ee0> #<Tag:0x00007f7398959df0>

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.