HA Shutdown Automations Don't work?

Hi, I’m trying to create an automation that runs when HA is shutting down. My automation is triggered by the “homeassistant” platform, see below. The trigger seems to work because the notification service runs, but the service to turn off an automation doesn’t.

I’ve confirmed the automation and script runs fine by manually executing the automation. I review the logbook and the execution time of the automation and notice that it’s not executed when I shutdown HA. However, the discord notification runs fine, which is odd. Is there a limitation on what service can run when HA is shutting down?

FWIW I’m running HA Core on Docker machine. And the reason I’m trying to turn off that one automation as part of the shutdown process is because for some reason HA turns my NVidia Shield Media Player state to “Idle” on every shutdown (I don’t know why), and so it essentially turns on my TV everytime I restart HA because I have an automation to turn on my Home Theatre when the Shield is On.

  alias: Run on Home Assistant Shutdown
  description: Tasks to perform when Home Assistant shuts down
  initial_state: true
  trigger:
    - platform: homeassistant
      event: shutdown
  action:
    - service: script.home_assistant_shutdown
home_assistant_shutdown:
  alias: Home Assistant Shutdown
  description: Actions to take when Home Assistant shuts down
  sequence:
    - service: automation.turn_off
      entity_id: automation.shield_turn_on_shield_tv_harmony_activity_when_shield_apps_opened_directly
    - service: notify.discord
      data:
        message: Home Assistant has stopped
        target: !secret discord_channel_id_admin

Seems to only work for the HassOS image. See this topic: Home Assistant STOP Automation not working

The problem with shutdown automations is timing. If the integration you’re using has already moved into the stopping process, the automation appears not to work.

I’ve tried a few automations like that, and while some work reliably, others don’t (including setting an input_datetime). The answer unfortunately is experimentation.

1 Like

Can you not achieve the same outcome by setting the automation you want disabled-

initial_state: false

Whenever HA restarts the automation will be off.

Or we could try to fix this:

No, unfortunately I need the automation on at all times. The only reason I want to turn it off is because of that issue with the Shield state turning to “idle” on shutdown which then causes my HT setup to turn on.

I like the way you think. Don’t know where to start with figuring out that issue. I do have ADB connected to the shield. Thanks for sharing that other post. At least I know now this automation thing won’t work. I guess only way is to figure out this Shield issue. :frowning:

I think what jive was suggesting was that at startup you could wait 10 seconds (or so) and then turn the automation on.
Ie. It would be on all the time apart from those 10 seconds

1 Like

Posting the triggers for any automations that control it would be a good start.

I’ve played around with the homeassistant shutdown event a fair bit in an attempt to get some of my light switch LED’s to notify me when HA was shutdown. (The LED would turn on during starup, and turn off during shutdown.)

I was not successful. I can confirm that zwave shuts down long before any zwave commands can trigger on the homeassistant shutdown event.