Templating automation with input_select and media player

5y later, but i do hope someone sees this and can help me.

2 input_select, a few choices, shouldnt really be that hard should it… Still im sitting here tearing my hair off.

Error:
“Stopped becouse an error was encoun…”
“URL is relative, but does not start with a /”

alias: Starta_Radio_på_vald_enhet
description: ''
trigger:
  - platform: state
    entity_id:
      - input_select.ljud_kalla
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: input_select.ljud_destination
        state: Av
action:
  - service: media_player.play_media
    data_template:
      entity_id: >
        {% if is_state("input_select.ljud_destination", "Kök") %}
          media_player.kok
        {%-elif is_state("input_select.ljud_destination", "Hall") %}
          media_player.hall
        {%-elif is_state("input_select.ljud_destination", "Vardagsrum") %}
          media_player.hogtalare_vardagsrum
        {%-elif is_state("input_select.ljud_destination", "Hi-Fi") %}
          media_player.chromecastaudio7414
        {%-elif is_state("input_select.ljud_destination", "Sovrum") %}
          media_player.sovrum_2
        {%-elif is_state("input_select.ljud_destination", "Kök+Hall+Vardagsrum")
        %}
          media_player.kok_hall_vardagsrum
        {%-elif is_state("input_select.ljud_destination",
        "Kök+Hall+Vardagsrum+Sovrum") %}
          media_player.kok_hall_vardagsrum_sovrum
        {% else %}
          none
        {% endif %}
      media_content_id: |
        {% if is_state("input_select.ljud_kalla", "Bandit") %}
          media-source://radio_browser/168e0796-3b97-479c-949d-b1871ef07379
        {%-elif is_state("input_select.ljud_kalla", "Rockklassiker") %}
          media-source://radio_browser/9642ad8b-0601-11e8-ae97-52543be04c81
        {%-elif is_state("input_select.ljud_kalla", "Mix Megapol") %}
          media-source://radio_browser/96414222-0601-11e8-ae97-52543be04c81
        {%-elif is_state("input_select.ljud_kalla", "NRJ") %}
          media-source://radio_browser/96342772-0601-11e8-ae97-52543be04c81
        {% else %}
          none
        {% endif %}
      media_content_type: audio/mpeg
mode: single

Please don’t revive old threads, make a new one.

Use choose or a condition to conditionally execute the media_player.play_media service. When the else occurs and the service receives none for the media_content_id, you’ll get this error.

1 Like

Sorry, my bad