diff --git a/source/_cookbook/perform_actions_based_on_input_select.markdown b/source/_cookbook/perform_actions_based_on_input_select.markdown index 63372ff3325..140aa6390fe 100644 --- a/source/_cookbook/perform_actions_based_on_input_select.markdown +++ b/source/_cookbook/perform_actions_based_on_input_select.markdown @@ -75,3 +75,96 @@ automation: data: entity_id: media_player.nursery ``` +A little bit more complex example that uses [`input_select`](/components/input_select/) and template do decide what and in which [Chromecast](components/media_player.cast/) play. + +```yaml +input_select: + radio_station: + name: Radio Station + options: + - Z88.3 + - Virgin + - RMC + - rmcHQ + - 105 + - None + initial: None + icon: mdi:radio + radio_player: + name: Radio Player + options: + - Mansarda + - Doccia + - Bed + - Bath + - Salotto + - Salotto Video + - None + initial: None + icon: mdi:airplay + +automation: + - alias: Stop Streaming Radio + trigger: + - platform: state + entity_id: input_select.radio_station + to: "None" + action: + service: media_player.turn_off + data_template: + entity_id: >{% raw %} + {% if is_state("input_select.radio_player", "Mansarda") %}{% endraw %} + media_player.bed_2{% raw %} + {%-elif is_state("input_select.radio_player", "Doccia") %}{% endraw %} + media_player.bed_3{% raw %} + {%-elif is_state("input_select.radio_player", "Bed") %}{% endraw %} + media_player.bed{% raw %} + {%-elif is_state("input_select.radio_player", "Bath") %}{% endraw %} + media_player.bath{% raw %} + {%-elif is_state("input_select.radio_player", "Salotto") %}{% endraw %} + media_player.salotto{% raw %} + {%-elif is_state("input_select.radio_player", "Salotto Video") %}{% endraw %} + media_player.salotto_video{% raw %} + {% else %}{% endraw %} + none{% raw %} + {% endif %}{% endraw %} + + - alias: Stream Radio - Template + trigger: + - platform: state + entity_id: input_select.radio_station + action: + - service: media_player.play_media + data_template: + entity_id: >{% raw %} + {% if is_state("input_select.radio_player", "Mansarda") %}{% endraw %} + media_player.bed_2{% raw %} + {%-elif is_state("input_select.radio_player", "Doccia") %}{% endraw %} + media_player.bed_3{% raw %} + {%-elif is_state("input_select.radio_player", "Bed") %}{% endraw %} + media_player.bed{% raw %} + {%-elif is_state("input_select.radio_player", "Bath") %}{% endraw %} + media_player.bath{% raw %} + {%-elif is_state("input_select.radio_player", "Salotto") %}{% endraw %} + media_player.salotto{% raw %} + {%-elif is_state("input_select.radio_player", "Salotto Video") %}{% endraw %} + media_player.salotto_video{% raw %} + {% else %}{% endraw %} + none{% raw %} + {% endif %}{% endraw %} + media_content_id: >{% raw %} + {% if is_state("input_select.radio_station", "Z88.3") %}{% endraw %} + http://ice.zradio.org/z/high.mp3{% raw %} + {%-elif is_state("input_select.radio_station", "Virgin") %}{% endraw %} + http://icecast.unitedradio.it/Virgin.mp3{% raw %} + {%-elif is_state("input_select.radio_station", "RMC") %}{% endraw %} + http://icecast.unitedradio.it/RMC.mp3{% raw %} + {%-elif is_state("input_select.radio_station", "rmcHQ") %}{% endraw %} + http://icecast.unitedradio.it/rmcHQ.mp3{% raw %} + {%-elif is_state("input_select.radio_station", "105") %}{% endraw %} + http://icecast.unitedradio.it/Radio105.mp3{% raw %} + {% else %}{% endraw %} + none{% raw %} + {% endif %}{% endraw %} + media_content_type: 'audio/mp4' +```