Probing MQTT switch status

I have this problem where if a device has been improperly powered off, the MQTT status will still appear as On because the esp8266 is not able to send back any telemetry. I currently have a separate script which monitor the devices so that it will inform Home Assistant to switch it off once the device is disconnected.

I wonder if anyone did this purely within Home-Assistant? For example making a timer script that will reset every time it receive a MQTT telemetry and will turn off the device if it time out?

How about this MQTT feature: http://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament

this is awesome, i didn’t know this exist.