I tested it and can confirm that version populates options
.
Ideally it would not lose its state after a restart/reload but storing/restoring the state is limited to Trigger-based Template Sensor/Binary_Sensor.
From the docs:
The state, including attributes, of trigger-based sensors and binary sensors is restored when Home Assistant is restarted. The state of other trigger-based template entities is not restored.
Given that a Trigger-based Template Select currently offers no additional functionality compared to its simpler cousin, the Template Select, my preference would be to use a Template Select. Plus it’s easy to set a default option
value.
The following example is based on Didgeridrew’s example (link posted above).
select:
- name: "My Select X"
options: "{{ ['one', 'two', 'three', 'four'] }}"
state: "{{ this.attributes.options[0] | default('None', true) }}"
optimistic: true
select_option:
- service: select.select_option
target:
entity_id: select.my_select_x
data:
option : "{{ option }}"
The OP’s Template Select would look like this:
- select:
- name: Home Mode
unique_id: home_mode
icon: |
mdi:{{ {
'Daytime': 'weather-sunny',
'Evening': 'weather-sunset',
'Night': 'weather-night',
'Sleep': 'sleep',
'Away': 'shield-home',
'Guest': 'kabaddi',
'Basic': 'weather-night',
'Sleep': 'auto-mode'}.get(this.state, 'auto-mode') }}
options: |
{{ ['Daytime', 'Evening', 'Night', 'Sleep', 'Basic', 'Manual', 'Guest', 'Away'] }}
state: "{{ this.attributes.options[0] | default('None', true) }}"
select_option:
- service: select.select_option
target:
entity_id: select.home_mode
data:
option : "{{ option }}"
optimistic: true
NOTE
This Template Select exhibits the same problem mentioned by gabrielmazor. After you make two selections, the icon stops changing.