# MQTT Client - LWT issues

**URL:** <https://community.homey.app/t/mqtt-client-lwt-issues/92180>\
**Category:** Apps\
**Tags:** app, mqtt\
**Created:** [October 18, 2023, 4:41pm UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180 "2023-10-18T16:41:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Busta999](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/busta999/32/10053_2.png) [@Busta999](https://community.homey.app/u/Busta999)\
**Post date:** [October 18, 2023, 4:41pm UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180/1 "2023-10-18T16:41:10Z")

</div>

Hi

I am probably completely getting the call wrong but trying to understand how the MQQT Client App is using LWT

 ![Screenshot 2023-10-18 at 17.32.34](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/4/04b326522e2c59536fbe075eb88047106cc84e5e.png)

 ![Screenshot 2023-10-18 at 17.38.29](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/d/bd86ac25e32474a4f031bc315489b5623b006092.png)

Am I reading this right - but it appears to be declaring that the Homey MQTT Client is offline ?

Because it is online and working fine.

Anyone any ideas ?

Ideally I am looking for NodeRed/Hubs/Homey to reflect the status of this connection

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 18, 2023, 4:51pm UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180/2 "2023-10-18T16:51:29Z")

</div>

> [@Busta999](#):
>
> Am I reading this right - but it appears to be declaring that the Homey MQTT Client is offline ?

If the message is retained (which it is), and you don’t clear or overwrite it, the LWT topic will show the LWT value indefinitely. So you need to reset it when the MQTT Client app connects again.

---

<div class="post-metadata">

**Author:** ![Busta999](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/busta999/32/10053_2.png) [@Busta999](https://community.homey.app/u/Busta999)\
**Post date:** [October 19, 2023, 7:21am UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180/3 "2023-10-19T07:21:32Z")

</div>

Thanks

I believe I am misunderstanding LWT function.

I had thought that LWT was sent by client to MQTT Broker on first connection and that the MQTT Broker executed LWT upon the event of the client disconnect.

I’ll go and read up on it, because it looks like the MQTT client writes LWT to the MQTT Broker declaring it is offline when it first connects and so it reports it is offline when connected.

I’ll figure it out 🙂

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 19, 2023, 7:32am UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180/4 "2023-10-19T07:32:02Z")

</div>

> [@Busta999](#):
>
> I had thought that LWT was sent by client to MQTT Broker on first connection and that the MQTT Broker executed LWT upon the event of the client disconnect.

That’s exactly what it does. But also _literally_ just that. It will not clear the message, or magically replace it by “online”, when the connection is established again.

> [@](#):
>
> I’ll go and read up on it, because it looks like the MQTT client writes LWT to the MQTT Broker declaring it is offline when it first connects and so it reports it is offline when connected.

No, what’s happening is this:

- the client connects, stating its LWT message
- the client disconnects, so the broker posts the LWT message _which is retained_
- the client connects again without clearing or updating the retained LWT message

So the last message posted to the LWT topic is “offline”, and it will remain there until you clear it.

---

<div class="post-metadata">

**Author:** ![Busta999](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/busta999/32/10053_2.png) [@Busta999](https://community.homey.app/u/Busta999)\
**Post date:** [October 19, 2023, 12:37pm UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180/8 "2023-10-19T12:37:46Z")

</div>

Thanks

So I create a flow in Homey to set NodeRed/Hubs/Homey to subscribe and if it ever does not equal online, change it to online?

Then if Homey MQTT Client goes offline it will be changed to offline by the MQTT Broker.

On it

Many thanks for that

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 19, 2023, 12:50pm UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180/9 "2023-10-19T12:50:16Z")

</div>

> [@Busta999](#):
>
> and if it ever does not equal online, change it to online?

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/4/84b5e2c66ac25a0c3b836c160c3dc1301246dc9f.png)

---

<div class="post-metadata">

**Author:** ![Busta999](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/busta999/32/10053_2.png) [@Busta999](https://community.homey.app/u/Busta999)\
**Post date:** [October 19, 2023, 8:54pm UTC](https://community.homey.app/t/mqtt-client-lwt-issues/92180/10 "2023-10-19T20:54:05Z")

</div>

PERFECT

Works a treat !!

Thanks
