# How to trigger a Tasmota device from Node-Red using MQTT?

**URL:** <https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891>\
**Category:** General\
**Created:** [1 November 2022 12:31 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891 "2022-11-01T12:31:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [1 November 2022 12:31 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/1 "2022-11-01T12:31:45Z")

</div>

Hi all,  
I am using MQTT a lot to get status information from my Tasmota Devices into Node-Red for further usage.  
Next I would like to change the status of one of these devices using MQTT - but sending seems to be much more complicated than reading.

The tasmota website ([MQTT - Tasmota](https://tasmota.github.io/docs/MQTT/#examples)) tells me to do it like that:

`cmnd/tasmota/POWER on`

adapted to my setup it would be:  
`cmnd/sonoff/s095/POWER on`

But if I send this to my MQTT device via Node-Red nothing happens:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc7eb8dc96e0d2bb65babf9f4ff973bde08f2d91.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/609b19975323cea13577d34cef604b933c7ea89f.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3e85cbb2be31f7711d31ad76fb5eaa2282848a9.png)

So I assume something in this setup is wrong. Maybe the "cmnd" command ?  
I am not sure and did not succeed after several different tests.

Maybe somebody here has an idea ?  
BR  
G

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [1 November 2022 12:36 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/2 "2022-11-01T12:36:15Z")

</div>

I think you probably need msg.topic = "cmnd/sonoff/s095/POWER"  
and msg.payload = "on"

---

<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:** [1 November 2022 12:47 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/3 "2022-11-01T12:47:05Z")

</div>

An example of my 'topic' setup for one of my SonOffs is...

![herb](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b0512693c347a9d74bfc3bde64352d76e9d91276.png)  
I send `msg.payload = 1;`  
But as @jbudd says, you can also send `msg.payload = "on"`

Take a look in the Information option, from the main Tasmota menu, to see your MQTT Full Topic name.

![full_topic](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e6d81cfe906e520fe2c75c384c566ee884e6b497.png)

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [1 November 2022 13:38 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/4 "2022-11-01T13:38:25Z")

</div>

If I do it like that, the command shows up as a new MQTT Client in MQTT Explorer:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75506189e13e252d1c0a78198bd95889bf5b21a0.png)

In the Tasmota Menu it looks like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/41726257d9b5b152ee2e9b74b37c8443fb26a423.png)

If I send it to sonoff/sonoff095 instead of cmnd, then it shows up here:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/0/40b3106a4bd71c88f2dc3bb898db340106b3a31d.png)

---

<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:** [1 November 2022 13:44 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/5 "2022-11-01T13:44:34Z")

</div>

I found my topic name (that I use) via the Information option on the Main Menu.

 ![mqtt_info](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d1f320543626e350a904b88649cf76f6328f707b.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [1 November 2022 14:32 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/6 "2022-11-01T14:32:08Z")

</div>

> [@Gawan](#):
>
> I am using MQTT a lot to get status information from my Tasmota Devices into Node-Red for further usage.

So you do know the topic that the device uses to _send_ an MQTT message.  
For regular telemetry it will begin with "tele/"  
Does your working MQTT In node have topic set to "tele/sonoff/095/#" or to "tele/sonoff095/#"?

Have you tried injecting msg.topic = "cmnd/sonoff/095/power" and msg.payload = "on"?  
What about msg.topic = "cmnd/sonoff095/power"?

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [1 November 2022 14:39 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/7 "2022-11-01T14:39:29Z")

</div>

It works now, but it looks weird and I do not understand why it works:

`sonoff/sonoff095/cmnd/power`

payload = "on"

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [1 November 2022 15:04 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/8 "2022-11-01T15:04:21Z")

</div>

I repeat my question...

Have you tried injecting msg.topic = "cmnd/sonoff095/power" and msg.payload = "on"?

---

<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:** [1 November 2022 17:04 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/9 "2022-11-01T17:04:06Z")

</div>

Don't know if this would help, but you can use programs such as MQTT Explorer to log into your MQTT server and see all of the messages going to and from it. It may not immediately help fix any problem, but, with a little experience, it does allow you to see what is going on and make better 'guesses' as to what needs to be done

---

<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:** [1 November 2022 17:25 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/10 "2022-11-01T17:25:56Z")

</div>

The tasmota command structure has always been weird to me, but ok.

```auto
sonoff/sonoff095/cmnd/power

```

I have also set it up like this for my devices.

Note that you can send `1/0`, `true/false` or "on/off" for power triggers.

To memorize/understand the structure, think of it like the http version:

```auto
http://<ip>/cm?cmnd=Power%20On

cmnd=Power%20On

cmnd/power payload:On

```

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [1 November 2022 23:24 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/11 "2022-11-01T23:24:56Z")

</div>

Normal Tasmota commands over MQTT are (from Tasmota site;

```auto
## Commands over MQTT[~](https://tasmota.github.io/docs/MQTT/#commands-over-mqtt)

To send commands and view responses you'll need an [MQTT client](http://www.hivemq.com/blog/seven-best-mqtt-client-tools).

Commands over MQTT are issued to Tasmota by using topic `cmnd/%topic%/<command>` and payload `<parameter>`. If there is no `<parameter>` (an empty MQTT message/payload), a query is sent for current status of the `<command>`.

Tip

If you are using *mosquitto_pub*, you can issue an empty payload using the `-n` command line option. If your MQTT client cannot issue an empty payload, you can use the single character `?` instead.

### Command flow[~](https://tasmota.github.io/docs/MQTT/#command-flow)

The following example will go in depth on what happens when you send an MQTT command.

A device was flashed and configured with the **FullTopic** as default `%prefix%/%topic%/` and the **Topic** set to `tasmota_switch`. We want to see the current status of the switch and change it.

By looking at the commands table we can learn about the [`POWER`](https://tasmota.github.io/docs/Commands/#power) command and options associated with it.

#### Ask the device for status[~](https://tasmota.github.io/docs/MQTT/#ask-the-device-for-status)

cmnd/tasmota_switch/Power ← // an empty message/payload sends a status query
    ↳ stat/tasmota_switch/RESULT → {"POWER":"OFF"}  
    ↳ stat/tasmota_switch/POWER → OFF

We can see that the switch (device's relay) is turned off.

#### Send a command to toggle the relay[~](https://tasmota.github.io/docs/MQTT/#send-a-command-to-toggle-the-relay)

cmnd/tasmota_switch/Power TOGGLE
    ↳ // Power for relay 1 is toggled
    ↳ stat/tasmota_switch/RESULT → {"POWER":"ON"}  
    ↳ stat/tasmota_switch/POWER → ON

We've sent the toggle command and received confirmation that the switch is turned on.

```

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [2 November 2022 06:00 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/12 "2022-11-02T06:00:52Z")

</div>

The console in Tasmota is your friend here

Set teleperiod to (say 60) so it is not updating too fast and then watch the screen - you will see the Tele messages it is sending out - both state and status and when you send a command you can see it come in and whether Tasmota likes it or not

Craig

---

<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:** [1 January 2023 06:01 UTC](https://discourse.nodered.org/t/how-to-trigger-a-tasmota-device-from-node-red-using-mqtt/69891/13 "2023-01-01T06:01:49Z")

</div>

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