Automation on homeassistant shutdown event no longer working

For a year or so I’ve had these two automations running:

- alias: HomeAssistant startup notification
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: script.house_announce_diningroom
      data_template:
        tts_msg: "Home Assistant, System startup complete"
- alias: HomeAssistant shutdown notification
  trigger:
    platform: homeassistant
    event: shutdown
  action:
    - service: media_player.volume_set
      data:
        entity_id: media_player.dining_room_speaker
        volume_level: 0.4
    - delay: 00:00:01
    - service: script.house_announce_diningroom
      data_template:
        tts_msg: "Home Assistant, System shutdown initiated"

This is documented in the Automation docs here.

These worked fine for months, but at some point a few months back the shutdown one stopped triggering. The startup one continues to work. I’ve been meaning to figure it out for ages but kept procrastinating :crazy_face:

It’s not huge deal but it was nice to get an announcement when restart was proceeding normally rather than waiting in suspense keeping an eye out for the dreaded notification badge about a config error. On my RPi3B the shutdown announcement would be maybe 10-20 seconds after I clicked the restart button.

Has anyone got a still-working shutdown automation? Any ideas why mine no longer works?

You probably need to add a base_url to your tts config. This was broken in the update that split the homeassistant base_url into internal_url and external_url.

Ive added it to the configuration in the homeassistant: level.

homeassistant:
  name: Ha Rpi4
  internal_url: !secret base_url

thinking if it would be needed anywhere, (and not only for tts: )

it’s set now globally, and working fine for tts:

Interesting. I thought I saw a few posts in the release notes thread that indicated it was required in the ttt setup as well.
I’ve added my internal and external URL as my old base URL but have no way to test if tts is actually working (as I am not home for another year and have no microphone in the place).

a, the 5000 miles you were talking about. Sounds exciting, hope you have a magical time abroad!

can confirm it works though, used heavily this setup :wink:

1 Like

first of all since you did not post your script.house_announce_diningroom not sure how you called the TTS since the breaking changes have been evolved this pass months. Also, @tom_l is correct that TTS requires external_url so google home can reach your information. So, I hope my explanations is clear and you can find your fixed.

Sorry, I don’t understand. Why would base_url affect TTS at shutdown but not TTS at startup?

This thread has gone a bit weird. It seems to contain posts from another thread? I already read Maristhvdb’s comment about ‘5000 miles’ in another thread earlier today. :thinking:

hmmm, you may have been mind reading, but I have only posted it here… or?

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.