How to turn on a MQTT switch?

This are the properties of the switch in MQTT:

In "MQTT out node", what should I set as the topic?
Currently it is: zigbee2mqtt/bar_switch
And what do I set the payload to, in order to toggle it for test purposes?

I've tried many combinations of "state_l1:TOGGLE" , "l1:TOGGLE" and adding "/l1" to the topic.

A bit more information is needed like...

  • What platform are you using (e.g. Raspberry Pi or PC or other)?
  • Are you using Node-RED or Home Assistant?
  • Are you using a local MQTT broker or a remote broker?
  • What is the name/type of device you are trying to switch/control?
  • Have you tried a simple back-to-back test with a local broker?

A Linux server is running docker with Node-red , MQTT, Zigbee2MQTT , locally.
the broker name is "zigbee2mqtt" device name "bar_switch"
device: Namron 4512768 control via MQTT | Zigbee2MQTT

Not sure what you mean by " * Have you tried a simple back-to-back test with a local broker?"
Zigbee2MQTT controls it just fine.

Additional information: NodeRed is processing many incoming zigbee devices, this is just the only one that I am trying to send data to. So the basic setup is working, I just need to know what the topic, and the payload is to be set to, in order to turn on a switch. (or toggle it)

topic:

zigbee2mqtt/FRIENDLY_NAME/set

eg:

zigbee2mqtt/bar_switch/set

payload:

{"state_l2": "TOGGLE"}
1 Like

Perfect, thank you, I had no chance of guessing that format :slight_smile:

Well, they do mention that in the documentation :wink:

To control this switch publish a message to topic zigbee2mqtt/FRIENDLY_NAME/set with payload {"state_l2": "ON"} , {"state_l2": "OFF"} or {"state_l2": "TOGGLE"} .

1 Like

ok, this is kind of embarrassing, but I did not look there for help on what I thought was a NodeRed -specific question, apparently the format is quite universal.

MQTT Explorer is used by a few here to see what messages are being sent to and from the Broker. Takes out the guess work, as you can test by publishing your own commands directly, this would eliminate things like Node-RED causing problems (hastily adding - which it doesn't).

Not sure how this would work with Docker though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.