Zigbee2MQTT: Cannot get my relay working

  • Platform information:
    • Hardware: RPi 3b+
    • OS:
    • Java Runtime Environment: 17
    • openHAB version: 4

I am in the process of changing from OpenHAB Zigbee binding to MQTT and Zigbee2MQTT, to be able to use a wider range of devices. Steep learning curve, so far.
I have a MHCOZY 4-channel relay (MHCOZY TYWB 4ch-RF control via MQTT | Zigbee2MQTT). It worked under the Zigbee binding. Under Z2M I have created a Thing for the device, and Channel and Item for the first of the relays (so far).
OpenHAB has contact with the relay. When I manually swich the relay ON or OFF, this is reflected in OpenHAB. The problem is, I have not found out how to control the relay from OpenHAB.
Using the information on the abovementioned web page, I have set up the channel like this:

UID: mqtt:topic:ccb86d30dd:ReleX4
label: ReleX4
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:ccb86d30dd
  - id: Hovedtermostat
    channelTypeUID: mqtt:switch
    label: Hovedtermostat
    description: ""
      commandTopic: zigbee2mqtt/0xa4c138aa03efa9de/set
      stateTopic: zigbee2mqtt/0xa4c138aa03efa9de/state_l1
      off: '{"state_l1": "OFF"}'
      on: '{"state_l1": "ON"}'

Things look right in MQTT Explorer, but no switching takes place. And I am stuck.

Any ideas?

Try the below for the commandTopic mapping

      off: OFF
      on: ON

I don’t think so. Then you wouldn’t have any way to distinguish between the four diffrernt relays (the “set” topic is on the thing level, not channel level)

You need to create separate channels for each switch. See below as an example for a device with multiple switches

bridgeUID: mqtt:broker:DockerMQTT
  - id: switch1
    channelTypeUID: mqtt:switch
    label: Switch 1
    description: null
      commandTopic: zigbee2mqtt/Bedroom_Lidl_powerstrip/l1/set
      stateTopic: zigbee2mqtt/Bedroom_Lidl_powerstrip/state_l1
      off: OFF
      on: ON
  - id: switch2
    channelTypeUID: mqtt:switch
    label: Switch 2
    description: null
      commandTopic: zigbee2mqtt/Bedroom_Lidl_powerstrip/l2/set
      stateTopic: zigbee2mqtt/Bedroom_Lidl_powerstrip/state_l2
      off: OFF
      on: ON
  - id: switch3
    channelTypeUID: mqtt:switch
    label: Switch 3
    description: null
      commandTopic: zigbee2mqtt/Bedroom_Lidl_powerstrip/l3/set
      stateTopic: zigbee2mqtt/Bedroom_Lidl_powerstrip/state_l3
      off: OFF
      on: ON

Yes, I know I must have one channel per relay. I only finished the first one.
The problem is, as I understand the doc, my device has one common “set” topic for all the relays. In your example, there is a differnt topic for each, which is a different scenario.
Anyway, to be sure, I tried the syntax you sent. It did not work :disappointed_relieved:

In your configuration.yaml what is your output set to.

  output: attribute

With it set it will separate them out. The example I gave was for this device.

What is mqttexplorer outputting?

Yes, now we are talking! That made the trick!
Thanks a lot for your patience with me! :slight_smile:

No problem.

Another tip that you might not know. There is a frontend

and if course a big repository for all kinds of zigbee devices:

1 Like