Send Notification when Home assistant die

Hello,

when Hass die, I can see in AppDaemon log:
WARNING AppDaemon: HASS: Disconnected from Home Assistant, retrying in 5 seconds

I would like to send Mqqt message when this occur and do certain things.

Just listen for the plugin_stopped event.

import appdaemon.plugins.hass.hassapi as hass

class MonitorPlugin(hass.Hass):
    def initialize(self):
      self.listen_event(self.plugin_event, "plugin_stopped") # or "plugin_started" when Home Assistant starts.

    def plugin_event(self, event_name, data, kwargs):
      self.log(event_name)
      self.log(data)
      self.log(kwargs)
      # Do whatever you need here.

data will contain a dictionary with the name of the plugin that caused the event, e.g. {‘name’: ‘HASS’}

1 Like

Also is possible to create Input_boolean and try to toggle it every X seconds. If Hass is not responding, warning is raised and boolean will remain a same. This works even when Appdaemon freshly starts or reload apps after editing and Hass is off.

configuration.yaml

input_boolean:
  hass_respond:
    name: "Hass is responding"
    initial: off
    icon: mdi:car

Your APP

self.run_every(self.send_state, datetime.datetime.now() + datetime.timedelta(seconds=1), 'every X seconds')

....
def send_state(self, kwargs):
      last_state = self.get_state("input_boolean.hass_respond", default="off")
      self.log(last_state) 
      self.toggle("input_boolean.hass_respond")
      time.sleep(1)
      state = self.get_state("input_boolean.hass_respond", default="off")
      self.log(state) 
      if last_state != state:
        self._state = True
        self.log("running")
      else:
        self._state = False
        self.log("stopped")
    #Do what You need