How to detect non-responsive sensor

I’ve a Zigbee network that is, in the main, quite reliable, but every once in a while one of the Xiaomi Aqara temperature sensors stops sending temperature updates. This causes problems as it means a heater I have also under control is left on, when it should be turned off when the target temperature is hit.

The solution is usually to re-pair that temp sensor so it comes back to life.

The challenge I have is how can I detect that the sensor has stopped sending temperature updates?

For example, it stopped working this morning, and last sent an update at 04:54. It didn’t send any further updates until I re-paired it at 10:46. What I’d like to do is to trigger an alarm if it doesn’t send an update for about an hour.

I’m guessing what is required is some kind of template trigger based on the last seen attribute. Anyone got any examples? (Not using Node Red please).

In case it’s relevant, the config of the temp sensor from develop tools looks like:

battery: 62
humidity: 38.98
last_seen: '2021-04-14T15:14:39+01:00'
linkquality: 42
pressure: 1027.2
temperature: 23.17
voltage: 2935
unit_of_measurement: °C
friendly_name: Cabin Temp Sensor
device_class: temperature
hide_attributes:
  - templates
  - icon_color

Any suggestions?

Thanks

You can build an automation with a template like below as the trigger.

{{ as_timestamp(states.sensor.date_time_iso.state) | round - as_timestamp( states.sensor.temperature.last_updated ) | round > 3600 }}

This templates subtracts the last state updated timestamp from the timestamp of the present time. This is the time difference of updates in seconds and 3600s means 1 hour.

Ensure that you have enabled iso time sensor in HA. Also change the sensor.temperature to your sensor entity_id.

4 Likes

Perfect - I did come up with an alternative, but not as elegant as yours. Basically, run a script every time a temp update is received, then wait 30 mins and send an alert. Have the script set to restart, so that the wait is restarted each time a new message is received. I think it works, but I like yours more! :slight_smile: