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

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) 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:




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 ?

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

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

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.


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


In the Tasmota Menu it looks like this:

If I send it to sonoff/sonoff095 instead of cmnd, then it shows up here:

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

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"?

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


payload = "on"

I repeat my question...

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

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

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


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:



cmnd/power payload:On

Normal Tasmota commands over MQTT are (from Tasmota site;

## Commands over MQTT[~](

To send commands and view responses you'll need an [MQTT client](

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


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[~](

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`]( command and options associated with it.

#### 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[~](

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.

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


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