Add mediaplayer with input_boolean

I’m trying to turn mediaplayer on/off in the entity_id queue with input_booleans.
What am I doing wrong?

service: media_player.play_media
data:
  media_content_type: music
  enqueue: replace
  media_content_id: http://77.109.144.109:8000/topsrp128
target:
  entity_id: |
    {% if is_state('input_boolean.player_og_wohnzimmer_musik', 'on') %}
      - media_player.og_wohnzimmer_musik
    {% endif %}
    {% if is_state('input_boolean.player_og_wc_musik', 'on') %}
      - media_player.og_wc_musik
    {% endif %}
    {% if is_state('input_boolean.player_eg_diele_musik', 'on') %}
      - media_player.eg_diele_musik
    {% endif %}
    {% if is_state('input_boolean.player_eg_bad_musik', 'on') %}
      - media_player.eg_bad_musik
    {% endif %}
    {% if is_state('input_boolean.player_keller_musik', 'on') %}
      - media_player.keller_musik
    {% endif %}

You’re confusing form with function… and you’re missing entity_id under target

Each of your if statements return a string like "- media_player.og_wohnzimmer_musik". While the result of your series of ifs looks like a dashed list, it will not be interpreted as a list. All the yaml interpreter is “seeing” is a long weird string that doesn’t match the pattern it expects for targets of the media_player.play_media service.

service: media_player.play_media
data:
  media_content_type: music
  enqueue: replace
  media_content_id: "http://77.109.144.109:8000/topsrp128"
target:
  entity_id: |
    {{ ['input_boolean.player_og_wohnzimmer_musik',
    'input_boolean.player_og_wc_musik',
    'input_boolean.player_eg_diele_musik',
    'input_boolean.player_eg_bad_musik',
    'input_boolean.player_keller_musik']
    | select('is_state', 'on') 
    | map('replace', 'input_boolean.player_', 'media_player.') 
    | list }}
1 Like

Wow, this is working perfect.
Thank you so much!