# How to detect that a device is offline (bulb not connected to electricity for instance)?

**URL:** <https://discourse.nodered.org/t/how-to-detect-that-a-device-is-offline-bulb-not-connected-to-electricity-for-instance/57873>\
**Category:** General\
**Tags:** zigbee, home-assistant\
**Created:** [6 February 2022 12:45 UTC](https://discourse.nodered.org/t/how-to-detect-that-a-device-is-offline-bulb-not-connected-to-electricity-for-instance/57873 "2022-02-06T12:45:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelherrera](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rafaelherrera](https://discourse.nodered.org/u/rafaelherrera)\
**Post date:** [6 February 2022 12:45 UTC](https://discourse.nodered.org/t/how-to-detect-that-a-device-is-offline-bulb-not-connected-to-electricity-for-instance/57873/1 "2022-02-06T12:45:39Z")

</div>

Hello,

I wanted to control a light when the other one in the same room is not connected to my home assistant via zigbee2mqtt (because a physical switch diconnected the bulb from electricity).

It is a simple case of setting on a night light when the main one is off via physical switch (main one is a zigbee bulb but switch is not smart).

In other words, I wanted to detect that the state of my light is "disconnected" instead of classical on/off.

Any ideas on how I can detect this "disconnected" state ? (I'm fine with everything else, it is just this state that is missing in my flow)

Thank you !!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 February 2022 13:07 UTC](https://discourse.nodered.org/t/how-to-detect-that-a-device-is-offline-bulb-not-connected-to-electricity-for-instance/57873/2 "2022-02-06T13:07:14Z")

</div>

MQTT has the concept of birth and "Last Will & Testament" messages. A lot of us use these to provide an indication as to whether something is off- or on-line.

They do depend on the client supporting them though and require a "heartbeat" type of message - a message that is sent on a known period.

If the device doesn't support that directly, you can simulate it from Node-RED by sending a periodic message to the device that elicits a reply. If the reply isn't received in the right timescale, you can mark the device offline.

Some examples:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/4788c9138f532cba243138676ee01843752057bb.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/832c6e006d23bd6b161fd6d66758e2b1c09626d2.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58c1a66895b8afc1392acdfeb87ac52908a9c653.png)

Where devices don't use MQTT natively, I sometimes use a simple timestamp instead, particularly where the device doesn't have a heartbeat and maybe spends most of its time offline (battery operated). The timestamp shows the last time I saw anything from the device:

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

(Note the amusing number of unknown 433MHz devices my RFXtrx433E has detected in our neighberhood over the last 3 months! Mostly wireless smoke detectors.)

---

<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:** [6 February 2022 16:29 UTC](https://discourse.nodered.org/t/how-to-detect-that-a-device-is-offline-bulb-not-connected-to-electricity-for-instance/57873/3 "2022-02-06T16:29:34Z")

</div>

> [@TotallyInformation](#):
>
> Note the amusing number of unknown 433MHz devices

Its not too bad until one clashes, the ghosts have switched the fan on again 🤪

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 February 2022 16:36 UTC](https://discourse.nodered.org/t/how-to-detect-that-a-device-is-offline-bulb-not-connected-to-electricity-for-instance/57873/4 "2022-02-06T16:36:37Z")

</div>

Haha, used to have that problem with a previous wireless bell - clashed with something in the house opposite ☹

Probably will be running down the 433MHz stuff over time though. Zigbee is so much better all round. Except for the DIY sensors - Zigbee is still too complex there for now. I'll stick with Wi-Fi for those.

---

<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:** [7 April 2022 16:37 UTC](https://discourse.nodered.org/t/how-to-detect-that-a-device-is-offline-bulb-not-connected-to-electricity-for-instance/57873/5 "2022-04-07T16:37:39Z")

</div>

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