Issues with a normal and simple script

I have this simple script:

lista_radio:
  alias: Lista Radio
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: media-source://radio_browser/62b0d769-6c12-410a-92da-00a6e6afc616
      media_content_type: music
    target: >
      entity_id: >
        {% if is_state("input_select.media_players", "Salotto Audio") %} media_player.salotto_audio
        {% elif is_state("input_select.media_players", "Nest Hub") %} media_player.nest_hub        
        {% elif is_state("input_select.media_players", "Salotto Sonos") %} media_player.salotto
        {% elif is_state("input_select.media_players", "Studio") %} media_player.studio
        {% elif is_state("input_select.media_players", "Echo Plus") %} media_player.echo_plus
        {% elif is_state("input_select.media_players", "Echo Show") %} media_player.echo_show
        {% elif is_state("input_select.media_players", "Echo Show 5") %} media_player.echo_show_5
        {% elif is_state("input_select.media_players", "Google Home") %} media_player.google_home
        {% elif is_state("input_select.media_players", "Google Home Mini") %} media_player.google_home_mini
        {% elif is_state("input_select.media_players", "Home") %} media_player.home
        {% elif is_state("input_select.media_players", "S22") %} media_player.companion_app
        {% elif is_state("input_select.media_players", "Tablet A8") %} media_player.tablet
        {% elif is_state("input_select.media_players", "iMac") %} media_player.imac                                              
        {% endif %}
  mode: single
  icon: mdi:radio

and in the dashboard i have a simple card:

                        type: entities
                        entities:
                          - input_select.media_players
                          - script.lista_radio
                          - script.media_stop

But it doesn’t work. I can select the media player, but when i press activate the script i get nothing from every media player i choose.
Can somebody help me to trace where is the error?

You have an extra > after target: which should not be there. You can also make your script more efficient by using a dictionary rather than such a long series of elif’s

lista_radio:
  alias: Lista Radio
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: "media-source://radio_browser/62b0d769-6c12-410a-92da-00a6e6afc616"
      media_content_type: music
    target: 
      entity_id: >
        {% set mapper = { "Salotto Audio": "media_player.salotto_audio",
        "Nest Hub": "media_player.nest_hub",
        "Salotto Sonos": "media_player.salotto",
        "Studio": "media_player.studio",
        "Echo Plus": "media_player.echo_plus",
        "Echo Show": "media_player.echo_show",
        "Echo Show 5": "media_player.echo_show_5",
        "Google Home": "media_player.google_home",
        "Google Home Mini": "media_player.google_home_mini",
        "Home": "media_player.home",
        "S22": "media_player.companion_app",
        "Tablet A8": "media_player.tablet",
        "iMac": "media_player.imac" } %}                            
        {{ mapper.get(states("input_select.media_players")) }}
  mode: single
1 Like

Thanks for the suggestion i did not know, but after making these changes the script is still not working…
EDIT: Sorry, was wrong… i forgot to toggle away the > after target.
Now all is working!!
Thanks again…