MQTT - Using message timestamp as a heartbeat


I’m in the process of moving from OH2 to 3 and taking the opportunity to review/improve my configuration given that its a bit of a mess through years of my patchy script development.

Also over the years I’ve also found ZWAVE a bit too unreliable for sensors and therefore moved to MQTT based sensors on ESP8266/Arduino self built devices.

To ensure that a ESP sensor didn’t go offline without alerting me, I coded them to publish a “heartbeat” MQTT message every 60 secs to a heartbeat channel and my OH script would read the channel to ensure there is a regular update and alert accordingly by setting a virtual switch on or off. Its a bit of a patchy approach, but it works fine.

I just wondered if others have any suggestions of a more modern approach which could utilise the message timestamp of my heartbeat messages to the channel? So OH would read the timestamp of the message to ensure its recent rather than the message inside the channel. Or would you use OH to publish a message to a queue and then get the ESP device to subscribe and return a message on the same queue?

I really like the MQTT/ESP approach, but don’t want to miss messages since a sensor went offline (which thankfully doesn’t happen often)

Many thanks

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

You can also let the broker handle it through LWT

You don’t even need to decode timestamps in general.
See the expire feature - you could set any regularly updated Item to expire after regular time + a bit, set state to UNDEF to indicate it’s lost, detect changes to UNDEF by rule for alerting.

But for MQTT, use the purpose designed LWT feature.

Many thanks to you both. LWT is exactly what I need to use and that link contained some helpful guidance.

I just need to update my Arduino code now.

Thanks again