I am trying to get a low-battery warning for my various Insteon Leak sensors, which talk to HA through MQTT. In addition to wet/dry, they each connect daily for a ‘heartbeat’. This shows up in HA as a timestamp entity. I pulled one battery out and sure enough, the timestamp of that sensor’s heartbeat still shows the last day it was successful. So, I need an automation that notifies me when any of those heartbeat sensors’ entities states gets to be more than 2 days ago. But it’s not formatted nicely, so I am stuck.
Right now, the State of the Entity i’m playing with says this “2022-04-22T22:48:32+00:00”.
Can anyone help me make an automation that constantly monitors those entities and fires whenever that timestamp strays further than 2 days from current time?
This takes the current UTC time converts it to unix time subtracts the last updated time of the entity converted to unix time, makes it a integer and checks if it is past two days. It true it will trigger the automation.
Thank you for the response. I have a couple of questions:
My actual heartbeat entity is sensor.ls_attic_ac_pan_heartbeat. Should I just swap that into the template so it reads “states.sensor.ls_attic_ac_pan_heartbeat.last_upated” (instead of light.living_room)?
You use the “last_updated” but I am not sure that’s right because my heartbeat entity says it was last updated 3 hours ago, but the entity itself gives me the last successful heartbeat from April 22. Are you sure this solution would need to reference “last_updated”?