I now have the previous state of my input_select.destination being restored when HA starts up.
The problem I had was that the initial state would be Home
since that’s the only option that HA saves with the input_select.destination; it doesn’t seem to save the dynamically created options.
So, I’m using a simple var. from HACS Variable integration
var:
saved_destination:
friendly_name: Saved Destination
The var gets updated here:
alias: Waze - Update Travel time to destination
description: ''
trigger:
- platform: state
entity_id: input_select.destination
condition: []
action:
- service: homeassistant.update_entity
target:
entity_id: sensor.waze_select_destination
- service: var.set
data:
entity_id: var.saved_destination
value: '{{ states("input_select.destination") }}'
mode: single
and I restore the state of input_select.destination in my HA Startup automation which also triggers an update of the travel time:
alias: HA Startup
description: ''
trigger:
- platform: homeassistant
event: start
condition: []
action:
- service: input_select.set_options
target:
entity_id: input_select.destination
data:
options: '{{ states.zone | map(attribute="name") | list }}'
- service: input_select.select_option
target:
entity_id: input_select.destination
data:
option: '{{ states("var.saved_destination") }}'
- service: python_script.domains_in_use
- service: python_script.entities_in_use
- choose:
- conditions:
- condition: device
type: is_off
device_id: f177253ec75b1464a93bef4e329770ac
entity_id: switch.plug_1
domain: switch
sequence:
- type: turn_on
device_id: f177253ec75b1464a93bef4e329770ac
entity_id: switch.plug_1
domain: switch
- conditions:
- condition: device
type: is_off
device_id: f177253ec75b1464a93bef4e329770ac
entity_id: switch.plug_2
domain: switch
sequence:
- type: turn_on
device_id: f177253ec75b1464a93bef4e329770ac
entity_id: switch.plug_2
domain: switch
- conditions:
- condition: device
type: is_off
device_id: f177253ec75b1464a93bef4e329770ac
entity_id: switch.plug_3
domain: switch
sequence:
- type: turn_on
device_id: f177253ec75b1464a93bef4e329770ac
entity_id: switch.plug_3
domain: switch
default: []
- service: notify.alexa_media_last_called
data:
message: Home Assistant has started
title: Home Assistant
data:
type: tts
- service: homeassistant.update_entity
target:
entity_id: sensor.waze_select_destination
mode: single
I found that if I placed the homeassistant.update_entity for Waze too early in the startup automation, the update did not occur. I played with it quite a bit restarting HA while watching Dev Tools Template in another window so I could see things updating as HA processed startup…
{{states('sensor.ha_current_version') == states('sensor.ha_latest_version')}}
{{states('sensor.ha_current_version')}}
{{ states.media_player|selectattr('attributes.last_called','eq',true)|map(attribute='entity_id')|join }}
{{ states('sensor.last_alexa') }}
Domains in use: {{ states("sensor.overview_domains") }}
Travel time: {{ states("sensor.waze_select_destination") }}m
Saved: {{ states("var.saved_destination") }}
Current: {{ states("input_select.destination") }}
Options: {{ state_attr("input_select.destination","options")|list }}