(idea) How to detect offline devices, need help to implement

I’ve been racking my brain to determine how to create automation which triggers when a device hasn’t sent an update recently for ZHA. I also considered a number of methods to eliminate my ZHA door sensors so I don’t have to worry about this, but the alternates don’t seem to be worth while.

So after some major looking around in Home Assistant, I came across the last seen time and date. I would really like to implement a scrip which checks every 30 minutes or a specific set of devices had updates. My thinking is that I create automation which starts a timer for 30 minutes, and when that timer finishes, confirms that the last seen of a specific devices is within that window.

So my question is, is there a good method to read the last seen time of a device in a script or automation? I think if I can automate that, I can determine if a device has a dead battery or has gone offline so that my security system or my freezer door alarm doesn’t fault out.

Any ideas would be GREATLY appreciated.

image