WTH: bug, automation with HA shutdown trigger does not save any changes to input values

When creating an automation that runs at Home Assistant shutdown (or restart), setting an input boolean (or other type) to a specific value doesn’t work properly.

To test this: I created a helper with input_boolean state set to off, no special configurations. I created an automation to do the following at HA shutdown trigger

  1. Push notification with the current state of an input_boolean helper
  2. Change the value by calling service Boolean input: turn on
  3. Push notification with the current state of an input_boolean helper

From the push notifications I see the value is changed, however not preserved after restart.
This also doesn’t work with setting the value to off at first.

alias: HA shutdown
description: ""
trigger:
  - platform: homeassistant
    event: shutdown
condition: []
action:
  - service: notify.mobile_app_me
    data:
      title: "System shutdown part 1"
      message: >-
        Home Assistant is shutting down. State 1st is {{
        states("input_boolean.recovery_state") }}
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.recovery_state
  - service: notify.mobile_app_me
    data:
      title: "System shutdown part 2"
      message: >-
        Home Assistant is shutting down. State now is {{
        states("input_boolean.recovery_state") }}
mode: single

Use case: I want to set an input-boolean to a value when restart is triggered and act on that value on restart. When there’s a sudden power loss, this is not triggered, so I know there has been a power loss

Have you make this work?
I want to do the same but struggling with the same issue.

No it hasn’t been fixed until now. It’s a bug clearly, but I guess not spotted by many people. I entered it for WTH, bit it wasn’t picked up so we can only wait until the team fixes this I guess.

Please open a GitHub issue.

That won’t help. I already did, but it was closed before someone replied or was assigned

HA shutdown trigger: service doesn’t preserve input changes · Issue #76765 · home-assistant/core (github.com)

1 Like

Interesting! I will try your sensor, thanks.

HA bug remains however :wink:

Based on my experiments, when the shutdown event occurs, it’s too late to perform certain actions. Whether that’s by design or error, I’ll leave that to the Core development team to decide.

FWIW, a similar thing occurs at startup. That’s why the Trigger-based Template Sensor I created uses the homeassistant_started event (because it occurs a bit later in startup phase, namely after the Template integration is loaded).