# MQTT message not seeming to work

**URL:** <https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705>\
**Category:** General\
**Created:** [28 April 2020 22:46 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705 "2020-04-28T22:46:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 April 2020 22:46 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/1 "2020-04-28T22:46:16Z")

</div>

I have a couple of `Tasmota` devices connected.

Looking, the `LWT` message is retained. So I would think that when the machine is powered up the message is received and should be affected.

Sorry it is a bit _messed up_ in layout, but this is the code:

```auto
[{"id":"3f35b888.962a","type":"mqtt in","z":"26262ba1.62dcbc","name":"Bulb-1 *","topic":"BULB-1/#","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":2480,"y":300,"wires":[["49320631.8fafc8","3c073047.1c12"]],"info":"This needs editing for different BULBS"},{"id":"3c073047.1c12","type":"switch","z":"26262ba1.62dcbc","name":"TOPICS *","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"BULB-1/cmnd/power1","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2660,"y":300,"wires":[["c0671188.49e67","f0e5a33c.047358"],["ff9438db.05a24","4af31854.bb2928"]],"outputLabels":["State","LWT"],"info":"This needs editing for different BULBS"},{"id":"ff9438db.05a24","type":"switch","z":"26262ba1.62dcbc","name":"LWT","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Online","vt":"str"},{"t":"eq","v":"Offline","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2480,"y":390,"wires":[["c1e2fde4.9eac38","650e33e.943974c"],["6f2a3190.8deba8"]]},{"id":"6f2a3190.8deba8","type":"function","z":"26262ba1.62dcbc","name":"BAN","func":"msg = {icon: '<font color = \"red\"><i class=\"fa fa-ban fa-3x\"></i></font>'};\nreturn msg;","outputs":1,"noerr":0,"x":2650,"y":420,"wires":[["ac1d9aac.bbcae"]]},{"id":"ac1d9aac.bbcae","type":"change","z":"26262ba1.62dcbc","name":"Disable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2850,"y":420,"wires":[["c8ea1741.fbff8"]]},{"id":"c8ea1741.fbff8","type":"ui_button","z":"26262ba1.62dcbc","name":"BULB#1","group":"7893c6c4.30ede","order":2,"width":"1","height":"2","passthru":false,"label":"{{msg.icon}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"X","payloadType":"str","topic":"","x":3060,"y":380,"wires":[["b31baea6.87a2f"]]},{"id":"378c0403.8cda04","type":"mqtt-broker","z":"","name":"MQTT HOST","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"7893c6c4.30ede","type":"ui_group","z":"","name":"BULB-1","tab":"aa487daa.33c1c","order":4,"disp":true,"width":"3","collapse":false},{"id":"aa487daa.33c1c","type":"ui_tab","z":"","name":"Real_World_Control","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

```

The idea is that if a `LWT` message is received with `Offline` it puts a `fa-ban` icon on the button and disables it.

But the button is active and has the wrong icon.

 ![Screenshot from 2020-04-29 08-44-16](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/0838726eb7ba4a86f70e5d593b1ccddfa81bdd52.png)

This is a picture from `MQTT Explorer` showing the message is retained:

 ![Screenshot from 2020-04-29 08-57-59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/807a646d7903a052022066f925b096d2f871c798.png)

The BAUHN-1 is unplugged and is showing the right icon/s.

The bulb is also unplugged and showing the wrong icon.

(Where's the elephant?)

---

<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:** [29 April 2020 06:12 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/2 "2020-04-29T06:12:43Z")

</div>

> [@Trying\_to\_learn](#):
>
> when the machine is powered up

Which machine, node red or tasmota?  
Either way start by putting a debug node on the mqtt in node to see where the problem is. If it is node red startup that is the problem then do a full deploy to initiate the problem.

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [29 April 2020 06:43 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/3 "2020-04-29T06:43:19Z")

</div>

I think you got the LWT idea wrong. The LWT is a „hidden“ (I don‘t think that mqtt explorer shows this) value of a topic which is submitted during connect. This value will replace the actual value as soon as the device loose the connection unexpected without a proper disconnect.  
I do not know tasmota but in esp easy you can define a LWT and value in the mqtt protocol section. In case of the homie convention it should be set to:  
`homie/device/$state = „lost“`  
The device sending a „ready“ to this topic and when it does loose connection the broker will issue the LWT containing „lost“.  
(Before deepsleep instead the device will send „sleeping“ and disconnect graceful so LWT don’t kick in)  
So perhaps first check if this mechanism works.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 April 2020 06:58 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/4 "2020-04-29T06:58:14Z")

</div>

My apologies.

The computer.

The `tasmota` stuff is plugged in (or not) doing its stuff.

I power on the machine (this) and load NR. Or more so the browser and load the page/s.

The `bulb` is powered down. The `LWT` messages is `Offline` - as shown in MQTT explorer.  
And it is retained.

The computer power up and gets the most up to date MQTT messages.  
Therefore I would expect the `Offline` message to be received and the icons changed to the `ban` ones as shown on the left of the screen.

I do have `debug` nodes on the `MQTT in` nodes. I didn't include them in the export but shall turn them on and see if I get anything next time.

Thanks.

Just what I am seeing: MQTT explorer showing me the messages (after booting) and the web page (edit screen of NR) (sorry) dashboard showing me the wrong icons.

Confusing.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [29 April 2020 08:50 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/5 "2020-04-29T08:50:59Z")

</div>

you say LWT is retained... but how have you configured the broker ? unless you configure it to retain things to disk it will be retained in memory and so lost when you reboot (assuming it's the device that is being rebooted).

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 April 2020 08:57 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/6 "2020-04-29T08:57:05Z")

</div>

Oh. Interesting.

This is what I understand and what is:  
The broker is on another machine.  
The broker can `retain` messages if desired.

I power up ~~the~~ this machine and NR starts.  
I load my browser and look at the page. It is not showing the _correct_ icon for the device.

Loading MQTT explorer it shows the message exists and is retained.

So when NR starts: shouldn't it get all the retained messages?  
(and so have the correct icon showing)

Sorry I wasn't clearer. Got a few _train wrecks_ happening.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [29 April 2020 09:10 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/7 "2020-04-29T09:10:51Z")

</div>

On a new tab, can you add an MQTT in node and subscribe it to the LWT topic and feed it to a debug node with status enabled

Deploy the flow

Does the debug node pick up the value of the LWT?

Stop Node-RED and restart it again

Does the debug node pick up the value of the LWT?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 April 2020 09:36 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/8 "2020-04-29T09:36:30Z")

</div>

Arrrrrr....

Interesting.

If I do the `MQTT` node listening to `BULB-2/#` it doesn't show much. (anything)

I do this because that is how it is in the flow.

But if I change the `MQTT` node to `BULB-2/tele/#` I get the LWT messge.

Hmmmmmmmm

Interesting.

I am doing _downstream_ parsing of the message to reduce the number of `MQTT` nodes.

But that seems flawed.

I'll try it by adding extra `MQTT` nodes with longer paths in their _topic_ field.

I'll get back to you in some days when The machine has been cycled a few times.

---

<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:** [29 April 2020 10:08 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/9 "2020-04-29T10:08:50Z")

</div>

> [@Trying\_to\_learn](#):
>
> If I do the `MQTT` node listening to `BULB-2/#` it doesn't show much. (anything)  
> But if I change the `MQTT` node to `BULB-2/tele/#` I get the LWT messge

If that is true then there is something very wrong somewhere. `BULB-2/#` should show you all the same subscriptions as `BULB-2/tele/#` and more. Are you sure you have specified the right broker?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 April 2020 10:16 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/10 "2020-04-29T10:16:32Z")

</div>

Yeah, well..... Initial tests are showing that is true.

`BULB-2/#` gets nothing if I deploy.

But if I make it `BULB-2/tele/LWT` and deploy: I get the LWT message.

Testing continues.

---

<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:** [29 April 2020 10:35 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/11 "2020-04-29T10:35:49Z")

</div>

What happens if you then change it back to `BULB-2/#`? If it then shows the problem may be that you did not do a full deploy. If you don't do a full deploy you are not guaranteed to get retained messages as the node thinks it has sent them already. Always do a full deploy when doing this sort of test.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 April 2020 10:50 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/12 "2020-04-29T10:50:08Z")

</div>

Typically for me things are now working after my reporting the problem.

How ever, I shall continue to monitor how things work.

---

<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:** [13 May 2020 10:50 UTC](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705/13 "2020-05-13T10:50:09Z")

</div>

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