# How to send an initial MQTT message to get the status of a tasmota switch?

**URL:** <https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721>\
**Category:** General\
**Created:** [4 December 2021 21:01 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721 "2021-12-04T21:01:40Z")\
**Posts on this page:** 11\
**Page:** 3

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 December 2021 16:04 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/41 "2021-12-05T16:04:41Z")

</div>

> [@belgah](#):
>
> If an alarm occurs and the server (with mqtt broker + red node) is down

Yes, that is an example where you will have to query the alarm source on node-red startup, is that a problem? I note that the subject of the thread is about tasmota switches, which is not the same as an alarm.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 December 2021 16:12 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/42 "2021-12-05T16:12:33Z")

</div>

> [@belgah](#):
>
> I'm pretty sure, that a device which fails to send a request via MQTT will not retry it endlessly until the broker is up again

That depends on the device and how you have programmed it. Some of my devices do exactly that.

I am not sure what you are asking for, are you asking for a standard way of telling connected devices to send their latest status? If so I don't see how this could be done generically, it has to be device dependent as it relies on the device sending the data.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [5 December 2021 17:49 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/43 "2021-12-05T17:49:46Z")

</div>

> [@Colin](#):
>
> If so I don't see how this could be done generically, it has to be device dependent as it relies on the device sending the data.

I haven't fully read the other 40 posts above, so forgive me if I'm misunderstanding the question, But can't the user ask the device for a update via MQTT whenever one is required?

Just post;

```auto
msg.payload = ""
msg.topic = cmnd/tasmota_switch/POWER

```

result on topic `stat/tasmota_switch/POWER` = `ON`

Or to get a full status report...

```auto
msg.payload = 0
msg.topic = cmnd/tasmota_switch/Status

```

result on topic `stat/tasmota_switch/STATUS`  
(with more status data on `/STATUS1`, `/STATUS2`, `/STATUS3`, up to `/STATUS11` depending what you need)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [5 December 2021 20:02 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/44 "2021-12-05T20:02:30Z")

</div>

So if the device is sleeping between updates then I don't see how you could query it from NR as it will not be able to respond ?

The trigger for Mqtt#Connected, can send the "current" state to NR as soon as mqtt connection is made.

This helps with most situations, if the tasmota device is rebooted, powered down, or even sleeping, or the mqtt server is down or Wi-Fi connection is lost, as soon as the connection is made it can send you the "current" state of the device (relay state, temperature, etc).

Or are you meaning that you want to know for example that a switch has changed state from open to closed and BACK again while offline ? So not the current state but, any events that may happened and haven’t been sent to mqtt ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 December 2021 20:16 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/45 "2021-12-05T20:16:13Z")

</div>

> [@Paul-Reed](#):
>
> Just post;
> 
> ```auto
> msg.payload = ""
> msg.topic = cmnd/tasmota_switch/POWER
> 
> ```

Yes, there are various ways of doing it with Tasmota devices, but the OP is asking, I think, for a general solution which works with any MQTT client.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [5 December 2021 20:24 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/46 "2021-12-05T20:24:48Z")

</div>

> [@Colin](#):
>
> for a general solution which works with any MQTT client

Ah OK, the topic title and the first post specifically asks about Tasmota??  
Maybe we need some clarification about what the OP really wants.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 December 2021 21:48 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/47 "2021-12-05T21:48:23Z")

</div>

> [@Paul-Reed](#):
>
> Maybe we need some clarification about what the OP really wants

Indeed, I did ask for that a few posts ago.

---

<div class="post-metadata">

**Author:** ![belgah](https://avatars.discourse-cdn.com/v4/letter/b/b77776/32.png) [@belgah](https://discourse.nodered.org/u/belgah)\
**Post date:** [5 December 2021 22:16 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/48 "2021-12-05T22:16:53Z")

</div>

Sry for the late answer.  
I have reached the new user response limit. -.-  
A little dumb on its own thread...

> [@Sean-McG](#):
>
> Or are you meaning that you want to know for example that a switch has changed state from open to closed and BACK again while offline ? So not the current state but, any events that may happened and haven’t been sent to mqtt ?

No thx, everything is working fine now.

> [@Colin](#):
>
> Yes, there are various ways of doing it with Tasmota devices, but the OP is asking, I think, for a general solution which works with any MQTT client.

Exactly, I'm just use the inject node with the auto trigger after 1s now.  
And with this method I can force every MQTT device to update the state after a restart.

So question answered, thx @ all!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 December 2021 09:45 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/49 "2021-12-06T09:45:25Z")

</div>

> [@belgah](#):
>
> with this method I can force every MQTT device to update the state after a restart.

What if the remote device is not running at this time or the network is down?

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [6 December 2021 12:03 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/50 "2021-12-06T12:03:31Z")

</div>

> [@belgah](#):
>
> use the inject node with the auto trigger after 1s now.

That's exactly what I'm doing, I had removed the automatic injection checkbox just to make the example and the screenshots. It's a shame, if I had known.  
For important devices (ESP8266), like for example a pump that must imperatively empty a tank or it will overflow,  
I use a watchdog that warns me via Telegram and my cell phone.

---

<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:** [20 December 2021 12:03 UTC](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721/51 "2021-12-20T12:03:55Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/how-to-send-an-initial-mqtt-message-to-get-the-status-of-a-tasmota-switch/54721.md?page=2)
