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
- Push notification with the current state of an input_boolean helper
- Change the value by calling service Boolean input: turn on
- 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