Hi All,
I’ve been trying to set up an automation to dynamically select_source for my Sonos system. I’m trying to use an input_select to do this. It seems that I can’t get the source field to work when there are “if” conditions. The automation seems to work if I input a static source.
Here’s a sample of my input_select code in configuration.yaml:
input_select:
sonos_source:
name: Sonos Source
options:
- alternative
- club
- Japanese
- 98.0
- 98.7
- 91.3
- kiss 92
- Line-in
- TV
initial: TV
icon: mdi:radio
and here is a sample of my automation code from my automations.yaml
- alias: sonos_music
trigger:
platform: state
entity_id: input_select.sonos_source
action:
- service: media_player.select_source
data_template:
entity_id: media_player.sonos_bedroom
source: >
{% if is_state("input_select.sonos_source", "alternative") -%}
"Alternative.m3u"
{%- elif is_state("input_select.sonos_source", "club") -%}
"Club.m3u"
{%- elif is_state("input_select.sonos_source", "Japanese") -%}
"Japanese.m3u"
{%- elif is_state("input_select.sonos_source", "98.0") -%}
"Power 98 FM 98.0 (Top 40/Pop)"
{%- elif is_state("input_select.sonos_source", "98.7") -%}
"987 98.7 (Top 40/Pop)"
{%- elif is_state("input_select.sonos_source", "kiss 92") -%}
"Kiss92 92.0 (Adult Contemporary)"
{%- elif is_state("input_select.sonos_source", "91.3") -%}
"One FM 91.3 (Rock)"
{%- else -%}
"Line-in"
{%- endif %}
Does anyone know if this is a bug or how to get it working as show at the bottom of the link below?
https://home-assistant.io/cookbook/perform_actions_based_on_input_select/
Thanks!