I’m trying to configure an input_select component that allows me to set the default audio to play during my wakeup routine. This select is to be dynamically populated from the source list available on SONOS devices, and ultimately should be synced between the two.
I created a script to periodically update the list from SONOS’ source_list but cannot get it to actually match up the two. Instead of being passed as a list, I’m getting the markup as the first, and only option — any ideas? Comma separation doesn’t appear to work here.
script:
update_sonos_faves:
sequence:
- service: input_select.set_options
data_template:
entity_id: input_select.wakeup_audio
options: >
{%- set stte -%}
{%- for stte in states.media_player if "sonos" in stte.object_id -%}
{{ stte.entity_id if loop.first }}
{%- endfor -%}
{%- endset -%}
{%- set stte = states|selectattr("entity_id", "equalto", stte)|list|first -%}
{{ stte.attributes.source_list }}
Templates itself cannot return lists. If you want to return a list, construct the data_template to contain lists and they will be preserved. Example of using data_template to create a script to set color based on input value:
script:
dynamic_light:
sequence:
service: light.turn_on
entity_id: light.kitchen_lights
data_template:
rgb_color:
- "{% if color == 'red' %}255{% else %}0{% endif %}"
- "{% if color == 'green' %}255{% else %}0{% endif %}"
- "{% if color == 'blue' %}255{% else %}0{% endif %}"