Not to sure, did a quick google and found this yaml which may help.
Unavailable Sensor Detection and Notification (github.com)
Here is a link to the thread I found it from: Sensor - Unavailable/Offline Detection - Share your Projects! - Home Assistant Community (home-assistant.io)
I personally do not detect when devices go offline, as it happens far to often, but that is do to poor WIFI which will soon be replaced with a better Access Point.