I have another solution that doesn’t require an automation within HA.
[{"id":"f2d88d0.d05847","type":"inject","z":"3907b15f.720dde","name":"HASS Connected?","topic":"","payload":"homeassistant.homeAssistant.isConnected","payloadType":"global","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":280,"wires":[["3be94497.d0409c"]]},{"id":"3be94497.d0409c","type":"rbe","z":"3907b15f.720dde","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":310,"y":280,"wires":[["e3ec25ae.6dfb08"]]},{"id":"e3ec25ae.6dfb08","type":"switch","z":"3907b15f.720dde","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":430,"y":280,"wires":[[],[]]}]
There’s a global boolean within the homeassistant object called isConnected. I have a inject node firing the status of that boolean as the payload every second. An RBE node watches for changes (ignoring the initial value). That feeds into a switch node that routes the message based on whether it’s true or false. Then do whatever based on that info. I send a telegram message on both the false and true conditions (Home Assistant Offline/Online). The flow above omits the telegram.