Using REST API to alert when sensors drop offline - advice on what metric to track


I am writing a Python program to alert me when a sensor goes offline. I use the REST API and call /api/states and then parse the resulting output. Everything works fine except for one issue related to my Aqara binary water sensors. Specifically, it seems that last_updated and last_changed only update when the sensors update status. These are water sensors and so they never change unless there is water which will hopefully never happen! As a result, these date fields never update. (I tried checking the fields on the power entity but they do not change much either.) These devices are active as I see them reporting in on the ZHA page.

Now I happen to have a local button that has issues and note that it reports power ‘state’ as ‘unavailable’ when it disconnects. This brings me to my question. Would alerting if power state is anything other than a number be an effective strategy to achieve the desired goal? Obviously, this seems to be the case with the button, but I am trying to understand that is expected universal behavior.

If the answer to the above is “that won’t work”, can anyone provide any ideas on how I might accomplish this?


I have a couple of sensors that I consider critical.

I use PING to confirm their status.

Just another option…

I like that idea, but it only works with WiFi sensors. I do not think that Zigbee sensors are pingable since they are not on the traditional LAN.