Template Select Entities

I may be misunderstnding you here but this can only pull the previous state object of the entity it’s being used in and the options are part of that state object. this will always bork when the entity if first initialised.

Forgive me if I did misunderstand you :).

I think I misunderstood you… :wink:

I probably assumed you meant the previous state, as in trigger.from_state. But, it’s simply the entity before the template has been processed. I mean, what else could ‘this’ be? Clairvoyant?

The issue is when the options are populated. If options: were processed and populated before processing state: then it should work (assuming this is a reference and not a copy). Even using `options: “{{ state_attr(‘select.foo’,‘options’)[0] }}” doesn’t work.

There’s some fun behavior, too.

Check out these two templates:

template:
  - triggers:
      - trigger: event
        event_type: fire_three
    select:
      - default_entity_id: select.options_three
        options: "{{ [ 'One', 'Two', 'Three' ] }}"
        state: One
        select_option:

  - triggers:
      - trigger: event
        event_type: fire_four
    select:
      - default_entity_id: select.options_four
        options: "{{ [ 'One', 'Two', 'Three' ] }}"
        state: Wrong
        select_option:

The first one, the very first time you fire it will populate the state with ‘One’, but the second one, with the “Wrong” option, leave the state as unknown. So, the code that checks for a valid option knows the options, but they are not available to the template…

(Plus, it doesn’t write to the logs that an invalid option was used.)

Obviously, could always just do this:

  - triggers:
      - trigger: event
        event_type: fire_eight
    variables:
      select_options: "{{ [ 'One', 'Two', 'Three' ] }}"
    select:
      - default_entity_id: select.options_eight
        options: "{{ select_options }}"
        # when setting a default
        state: "{{ select_options[0] }}"
        select_option: