Dynamic list of Destinations based on Zones, and useable by Waze

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 }}

what’s that? I dont see that on my media_players…

a for the restore, yes Ive encountered that too ofc, but set 1 option in the config of the input_select, to have it always startup with me and my better half, so I can spot the most important travel time right away :wink:

I dont have a zone Home, and the system defaults to my configuration gps coordinates, and those seem not to be useable in this travel time, throwing an error no lat/long is available.

If I create a Home zone in Yaml, as the docs suggest to override the auto zone, its messes up all other logic in my system where trackers and home is required… a lot of trouble over something not worht the while. Why bother restoring this in the first place.

Second to that, could we use a core input entity for that, those are restored at startup, and I suppose you could use that in your automation?

last_called is an attribute on Alexa Media Players.

I don’t see an option like that through the UI…

My Home zone is the built-in zone


What is your auto zone called?

Yes, you could use a core input_text rather the custom var to save the last targeted destination. I chose var since I already am using it…

With the HA 2022.4 enhancement adding a state to zones, I found my automation to update waze was triggering every time a zone state changed. I fumbled around a bit with my automation that was triggered on event state_changed with the condition value_template: ‘{{ trigger.event.data.entity_id.startswith(’‘zone.’’) }}’ to eliminate running actions where it was a zone state that changed. I ended up abandoning that and now have:

sensor:
  - name: Zones
    unique_id: zone_list
    state: '{{ states.zone | count }}'
    attributes:
      entities: >
       {{ states.zone | map(attribute='entity_id')|select|list }}

automation:

  alias: Update Destinations from Zones
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.zones
    id: state_changed
  condition: []
  action:
  - service: input_select.set_options
    target:
      entity_id: input_select.destination
    data:
      options: '{{ states.zone | map(attribute="name") | list }}'
  - service: notify.persistent_notification
    data:
      title: Zones
      message: Waze destination list updated
  mode: parallel
  max: 20

This triggers if a zone is added or deleted or if a zone’s entity_id has changed.