Next project, radio streaming…
Created 2 sensors (desplayed them in the card and seems to be OK) :
- sensor:
- name: "speaker_selected"
icon: "mdi:speaker"
state: >
{% if is_state("input_select.speaker", "Nest Hub Living") %}
media_player.nest_hub_living
{% elif is_state("input_select.speaker", "Pioneer Receiver") %}
media_player.chromecastaudioliving
{% elif is_state("input_select.speaker", "Sauna") %}
media_player.chromecastaudiosauna
{% elif is_state("input_select.radio", "Pioneer Receiver + Sauna") %}
media_player.chromecastaudio
{% else %}
media_player.chromecastultra
{% endif %}
- name: "URL_radio_station"
icon: "mdi:radio-fm"
state: >
{% if is_state("input_select.radio_station", "Radio 2 West-Vlaanderen") %}
http://icecast.vrtcdn.be/ra2wvl-high.mp3
{% elif is_state("input_select.radio_station", "Joe") %}
https://20723.live.streamtheworld.com/JOE.mp3
{% else %}
http://icecast.vrtcdn.be/mnm-high.mp3
{% endif %}
My first “long” version works fine :
alias: Radio play
sequence:
- service: media_player.volume_set
data:
entity_id: |
{% if is_state("input_select.speaker", "Nest Hub Living") %}
media_player.nest_hub_living
{% elif is_state("input_select.speaker", "Pioneer Receiver") %}
media_player.chromecastaudioliving
{% elif is_state("input_select.speaker", "Sauna") %}
media_player.chromecastaudiosauna
{% elif is_state("input_select.radio", "Pioneer Receiver + Sauna") %}
media_player.chromecastaudio
{% else %}
media_player.chromecastultra
{% endif %}
volume_level: '{{ states("input_number.radio_volume") }}'
- service: media_player.play_media
data:
media_content_id: >
{% if is_state("input_select.radio_station", "Radio 2 West-Vlaanderen")
%}
http://icecast.vrtcdn.be/ra2wvl-high.mp3
{% elif is_state("input_select.radio_station", "Joe") %}
https://20723.live.streamtheworld.com/JOE.mp3
{% else %}
http://icecast.vrtcdn.be/mnm-high.mp3
{% endif %}
media_content_type: music
target:
entity_id: |
{% if is_state("input_select.speaker", "Nest Hub Living") %}
media_player.nest_hub_living
{% elif is_state("input_select.speaker", "Pioneer Receiver") %}
media_player.chromecastaudioliving
{% elif is_state("input_select.speaker", "Sauna") %}
media_player.chromecastaudiosauna
{% elif is_state("input_select.radio", "Pioneer Receiver + Sauna") %}
media_player.chromecastaudio
{% else %}
media_player.chromecastultra
{% endif %}
mode: single
But the “short” version is not working :
alias: Radio play 2
sequence:
- service: media_player.volume_set
data:
entity_id: sensor.speaker_selected
volume_level: '{{ states("input_number.radio_volume") }}'
- service: media_player.play_media
data:
media_content_id: URL_radio_station
media_content_type: music
target:
entity_id: sensor.speaker_selected
mode: single
I presume the problem is the sensor.speaker_selected, which is just text…but how can I get the id of the entity with the name stored in the sensor ?