Listen to when HA is about to stop (or restart)

Hi folks,

Is there a way to know when Home Assistant is about to restart ?
e.g. If someone goes to Development Tools/YAML/Restart, is there a way to know (programmatically) that this options was triggered?

What I tried:

  • Listening to “homeassistant_stop” in nodered does not work as nodered is stoped before the event is raised.
  • Adding an automation triggered by “homeassistant” (event shutdown) also does not work and this automation is never triggered.

Thank you in advance

I am using this trigger successfully in automations. In my case I am sending rest_commands to put my wall tablets into maintenance mode while Home Assistant is restarting.

I have just successfully reproduced this with a very simple automation that just logs a message:

alias: Test shutdown
trigger:
  - platform: homeassistant
    event: shutdown
action:
  - service: system_log.write
    data:
      message: About to shut down
mode: single

And below a notification when system has started:

- id: system_startup
  alias: 'System Startup'
  trigger:
    platform: homeassistant
    event: start
  action:
  - service: notify.telegram_xxxx
    data:
      title: '✅ *System startup*'
      message: >
        Home Assistant has started.

        {{ now().strftime("%H:%M:%S") }}
1 Like

Thank you for your feedback. That is super strange, I tried to write a value into an input_text just for testing purposes and it was never written. I will give another try.

Same to me…
I have an automation on shutdown where it should set a binary input and then send me a notification thru Signal. The notification works fine, but the input is never set.

Humm, I am not crazy :slight_smile:
So trigger happens in parallel of the shutdown process and you can’t use other HA services as action.

It makes sense, however the notification service always works during the restart. I’he an automation to send me a notification (using Signal Messenger) during shutdown and during starting and it is rock solid on the notifications, but the service to set a helper, which I’d like to use to detect a start without a “controlled” restart, fails 100% of the time.

But just to make clear, I agree with your point… I just don’t understand why this is not the same for all services.