Automation on homeassistant shutdown event no longer working

Huh I must be going mad :grin:

Anyway the point is that I’m wondering if something has changed with the shutdown event.

My TTS is working, I’ve never experienced any issues with that. As I mentioned in my original post this shutdown event problem started a few months ago, long before the split internal/external URLs. it was sometime around HA 0.98 I believe. Edit: after looking at release dates I don’t know what version it was. It was about 6 months ago :grinning:!

Just pointing out that the startup TTS works. The shutdown one doesn’t. It’s the same script. Everyone seems to have missed it so I’ve gone back and emboldened that sentence in my original post :laughing:

I think your media being called at the same time. Which make the 2nd TTS does not working. You should try making the delay into longer which allow your media to finish the 1st one and run the TTS

That’s not a template. But I don’t think that would stop your script from running.

Yeah the script is fine. My TTS is all working. My setup uses script.house_announce_diningroom dozens of times a day.

I’m wondering if there is something wrong with the shutdown event and wanted to hear from anyone else who uses it.

I think I’ve ruled out issues with the volume_set or the delay being a problem. I use that exact sequence in other situations and the 1 second delay works as expected.

I’ve also tested this automation and it also doesn’t fire when I restart. I use these local mp3s in other situations (e.g. if the internet is down), and they definitely work.

- alias: HomeAssistant shutdown notification
  trigger:
    platform: homeassistant
    event: shutdown
  action:
    - service: media_player.play_media
      data_template:                 
        entity_id: media_player.dining_room_speaker            
        media_content_id: http://192.168.0.2:8888/mp3/system-shutdown-initiated.mp3
        media_content_type: 'audio/mp3'

You really should stop using data_template where you don’t have templates. It may work now but may not in future.

No it still sends me automated telegram messages when homeassistant shuts down.

Does quoting your delay help?

delay: '00:00:01'

was thinking of that too. And, like before, (and don’t burn me down for this and say it shouldn’t matter or is impossible…) please let me add this syntax, which has solved issues before:

delay:
  seconds: 1

wait, sorry, missed this. Nm.

Aha! Thanks for that, I was hoping someone had a working example :grin:

I tested it with telegram:


- alias: HomeAssistant shutdown notification
  trigger:
    platform: homeassistant
    event: shutdown
  action:
    - service: notify.telegram_timhiphonex
      data:
        title: 'Shutdown test'
        message: "This is a test"

This works!

I also tried this:

- alias: HomeAssistant shutdown notification
  trigger:
    platform: homeassistant
    event: shutdown
  action:
    - service: script.house_announce_diningroom
      data_template:
        tts_msg: "Home Assistant, System shutdown initiated"
    - service: xiaomi_aqara.play_ringtone
      data:
        ringtone_id: 7
        ringtone_vol: 10
        gw_mac: 04CF8C8FA2AF
    - service: notify.telegram_timhiphonex
      data:
        title: 'Shutdown test'
        message: "This is a test"
    - service: notify.pushover_timhiphonex
      data:
        message: "This is a test"

With this setup the TTS script (the same TTS script that works normally at startup) does not work , but the Xiaomi Gateway ringtone, the telegram notification, and the pushover notification all DO work.

It’s strange that the same TTS script stopped working at shutdown but continues to work at startup. But at least I’ve confirmed the shutdown event is still working. I wonder if media players are no longer available during the shutdown process for some reason? :thinking:

I just want some kind of notification that restart is proceeding normally, I’d prefer a TTS announcement but pushover plus a xiaomi gateway alarm will do :+1: Thanks for the assistance!

Just to add to this, I noticed same thing with the shutdown trigger. It appears that scripts won’t run, but other services will. I tried setting an input_text in a script on shutdown and had no luck. The same action done in the automation using the service directly worked however.

My shutdown automation is not triggering. I just tried adding an input_text.set_value to it but I noticed it’s never been triggered.

alias: HA Shutdown
description: ''
trigger:
  - platform: homeassistant
    event: shutdown
condition: []
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.reset_multisensor
  - service: input_text.set_value
    target:
      entity_id: input_text.saved_destination
    data:
      value: '{{ states("input_select.destination") }}'
mode: single

the boolean is also not on.

Working for me (HAOS 7.1, HA 2022.12.10)

- id: affb7625-0dc2-4075-88a9-6eae3563af6c
  alias: 'Shutdown'
  trigger:
    platform: homeassistant
    event: 'shutdown'
  action:
  - service: notify.telegram_system
    data:
      title: '⚠️ *System shutdown*'
      message: "Home Assistant is shutting down."

How are you shutting down HA? I’ve noticed the only way to get any kind of consistency using the ‘Shutdown’ trigger is when shutting down HA from-within HA.

NOTE: I run HA inside VirtualBox on Windows so YMMV.

I’m running Supervised Home Assistant OS on the Home Assistant Blue ODROID-N2+
I always do it from here…

image

That’s how I restart too. So the difference is I’m running HAOS where as you are running supervised.

What operating system are you using?

I looks like only notify actions are executed when the shutdown event is triggered.

I’ve added some additional automations for testing. All automations has been triggered and I received all notifications. But the input_booleans hasn’t been turned off.

And although the notifications has all been sent the automation overview shows all the automations as never triggered.

  - alias: "Home Assistant - Gestoppt"
    id: "home_assistant_gestoppt"
    trigger:   
      - platform: homeassistant
        event: shutdown         
    action:
      - service: notify.telegram
        data:                  
          message: "Home Assistant wurde gestoppt."
      
  - alias: "Home Assistant - Gestoppt (Test)"
    id: "home_assistant_gestoppt_test"
    trigger:   
      - platform: homeassistant
        event: shutdown      
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.wetter_warnungen_einschalten
          
  - alias: "Home Assistant - Gestoppt (Test 2)"
    id: "home_assistant_gestoppt_test_2"
    trigger:   
      - platform: homeassistant
        event: shutdown     
    action:
      - service: notify.telegram
        data:                  
          message: "Home Assistant wurde gestoppt (Test 2)"           
      - service: input_boolean.turn_off
        entity_id: input_boolean.uhr_einschalten
		
  - alias: "Home Assistant - Gestoppt (Test 3)"
    id: "home_assistant_gestoppt_test_3"
    trigger:   
      - platform: homeassistant
        event: shutdown     
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.besuch      
      - service: notify.telegram
        data:                  
          message: "Home Assistant wurde gestoppt (Test 3)"    		
1 Like

Try this:

      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.uhr_einschalten

Or this:

      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.uhr_einschalten

None of the services for the input_boolean is triggered. Only the notification is sent although it is the last service in the automation.

  - alias: "Home Assistant - Test Shutdown"
    id: "home_assistant_test_shutdown"
    trigger:   
      - platform: homeassistant
        event: shutdown     
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.test_a        
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.test_b      
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.test_c          
      - service: notify.telegram
        data:                  
          message: "Home Assistant wurde gestoppt."    

It seems that at the time the shutdown event is triggered only the notify service works and all other services has already been stopped.

1 Like

Was scratching my head with this too :frowning:
No other idea than create my own Restart HA button with script doing all the housekeeping and then finally call

service: homeassistant.restart

Clumsy but it works :slight_smile:
Best, JR

1 Like