Monitoring MQTT sensor alive

Hi guys,

I started building some “WIFI sensor” using wemos D1 and some temperature sensor. The first one I built is for my pool temperature.

So, I built a “sensor box” with a db18b20 and a wemos d1. The program on the D1 take the tempeture and post it via MQTT each 5 minutes.

This part is good ans work great.

What I want to add is something to monitor that the “sensor box” is still working. A “non-working” box is one that didn’t update my MQTT sensor since more than 5 minutes.

I would like to use the Alert feature of HomeAssistant based and an input_boolean called “MQTT pool sensor alive”.

I then built 2 automation to make the input_boolean ON and OFF.

First automation trigger on

{{ as_timestamp(now()) - as_timestamp(states.sensor.pooltemperature.last_updated) | int > 300 }}`

and set my input_boolean to OFF.

Second automation trigger on

{{ as_timestamp(now()) - as_timestamp(states.sensor.pooltemperature.last_updated) | int < 301 }}

and set my input_boolean to ON

But my automation is not trigered and I don’t know why. Anyone has an idea ?
Is there a better way to do my sensor monitoring ?

Thanks

This is normally done with the Last WIll and Testament (LWT) feature of MQTT. If the client (your Wemos D1) sets this up, the broker will send out a message to a specified topic when the client disconnects - such as when it loses power.

Thanks !
I didn’t know about this.
Work like I want, now, i’m facing problem with input_boolean but i’ll post something else :slight_smile:

1 Like