Listen_event for "homeassistant_stop"

This isn’t working… How should AD listen for HA shutdown?

I don’t remember the syntax of the event or whether you can listen for the shutdown, or have to listen for the startup. Write a simple app, that listens for all events and puts out a log message with the event name. Then do a shut down and see what the spelling/capitalization, etc is for the events you are looking for.

You can attempt to listen for the HASS event but it may well not get picked up by AD because it is busy shutting down and reconnecting things.

AppDaemon does have an event for HASS starting which you can use to imply that home assistant has shutdown and later restarted …

I’m attempting to monitor the status of HA, say, if it were to get shutdown and AD didn’t (I’m in containers). Can I listen on the “trying to reconnect” message AD logs when that happens?

There is no way to listen on the reconnecting messages, in fact I stop all apps if AppDaemon is down, but when it comes back up you will be informed.

From the docs -

Using AppDaemon, it is possible to subscribe to specific events as well as fire off events.

In addition to the Home Assistant supplied events, AppDaemon adds 2 more events. These are internal to AppDaemon and are not visible on the Home Assistant bus:

  • appd_started - fired once when AppDaemon is first started and after Apps are initialized
  • ha_started - fired every time AppDaemon detects a Home Assistant restart

I could look at a “lost connection with Home Assistant” kind of event I suppose, but all the apps are currently dormant when HASS is offline - that may be something worth looking into though.

In fact thinking about it, there is no need to disable the scheduler - it has nothing to do with HASS really, I should just disallow any calls into hass, maybe log an error if an app tries.

1 Like

It would be linux specific, but how about something at the OS level??? Check to see if there is still a homeassistant process running…

I should be able to do something a little more elegant from within AppDaemon, see my edits above.

1 Like

Would love to see something like that. Been working on reliability automations and such. This one will help me make sure HA isn’t down when it shouldn’t be.

OK, I like the idea, it’s on my list for a future release :slight_smile: In fact it aligns well with 2 other pieces of work I have been doing behind the scenes :slight_smile:

1 Like

Any chance remote access to the dashboard is on your list?

There is every chance its on the list, just no idea when I will get to it, although it is closer now the beta is done. I still think that NGINX is by far the best solution. Regarding all of the issues with addresses, that actually should be better now as the server binds to 0.0.0.0/0 instead of a specific IP address so you may be able to get it working.

OK, this will be in the next release. New behavior:

  • When disconnected from HASS, Apps will continue to run
  • Schedules will continue to be honored
  • Any operation reading locally cached state will succeed
  • Any operation requiring a call to HASS will log a warning and return without attempting to contact hass
  • When has goes down or becomes disconnected, an event called ha_disconnected will fire
2 Likes

Love it. Thanks for the quick response on this one. Will watch for the next release.

i can place the dashboard behind nginx. tried it and it works good.
but there is no pasword protection, so then i need to find out how i can setup pasword protection with nginx.
a possibility to have pasword protection from the dashboards like it is in HA would be preferred.

You can use the . htpasswd file to setup authentication on your reverse proxy!

how?
can you tell me what i need in the NGINX config?