# How to turn on a MQTT switch?

**URL:** <https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237>\
**Category:** General\
**Tags:** mqtt\
**Created:** [8 October 2024 10:26 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237 "2024-10-08T10:26:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndKe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andke/32/73023_2.png) [@AndKe](https://discourse.nodered.org/u/AndKe)\
**Post date:** [8 October 2024 10:26 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/1 "2024-10-08T10:26:47Z")

</div>

This are the properties of the switch in MQTT:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85ccf9f2dd73de357830d989b3039b413e286c5e.png)

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.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [8 October 2024 10:36 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/2 "2024-10-08T10:36:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![AndKe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andke/32/73023_2.png) [@AndKe](https://discourse.nodered.org/u/AndKe)\
**Post date:** [8 October 2024 10:45 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/3 "2024-10-08T10:45:55Z")

</div>

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](https://www.zigbee2mqtt.io/devices/4512768.html#namron-4512768)

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)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [8 October 2024 10:50 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/4 "2024-10-08T10:50:21Z")

</div>

topic:

```auto
zigbee2mqtt/FRIENDLY_NAME/set

eg:

zigbee2mqtt/bar_switch/set

```

payload:

```auto
{"state_l2": "TOGGLE"}

```

---

<div class="post-metadata">

**Author:** ![AndKe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andke/32/73023_2.png) [@AndKe](https://discourse.nodered.org/u/AndKe)\
**Post date:** [8 October 2024 10:53 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/5 "2024-10-08T10:53:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [8 October 2024 11:07 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/6 "2024-10-08T11:07:39Z")

</div>

> [@AndKe](#):
>
> device: [Namron 4512768 control via MQTT | Zigbee2MQTT](https://www.zigbee2mqtt.io/devices/4512768.html#namron-4512768)

Well, they do mention that in the documentation 😉

> 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"}` .

---

<div class="post-metadata">

**Author:** ![AndKe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andke/32/73023_2.png) [@AndKe](https://discourse.nodered.org/u/AndKe)\
**Post date:** [8 October 2024 11:14 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/7 "2024-10-08T11:14:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [8 October 2024 14:59 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/8 "2024-10-08T14:59:55Z")

</div>

[MQTT Explorer](https://mqtt-explorer.com) 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 October 2024 14:59 UTC](https://discourse.nodered.org/t/how-to-turn-on-a-mqtt-switch/92237/9 "2024-10-22T14:59:57Z")

</div>

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