Problem with scripts and template

I have this script to stop the radio speakers:

radio_stop:
  alias: Stop Radio
  sequence:
    - service: media_player.media_stop
      data_template:
        entity_id: >
         {% if is_state("input_select.radio_speakers", "Living Room Audio") %} media_player.salotto_audio
         {% elif is_state("input_select.radio_speakers", "Chromecast Salotto") %} media_player.salotto
         {% elif is_state("input_select.radio_speakers", "Chromecast Camera Letto") %} media_player.camera_da_letto
         {% elif is_state("input_select.radio_speakers", "Google Home") %} media_player.googlehome5670
         {% elif is_state("input_select.radio_speakers", "Google Home Mini") %} media_player.googlehome0461
         {% elif is_state("input_select.radio_speakers", "Echo Plus") %} media_player.echo_plus__di_maurizio
         {% elif is_state("input_select.radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa
         {% endif %}
    - service: input_boolean.turn_off
      entity_id: input_boolean.radio_play
    - service: switch.turn_off
      entity_id: switch.ampli_on
    - service: script.turn_on
      entity_id: script.set_onkyo_status
    - service: media_player.media_stop
      entity_id: media_player.salotto_audio
    - delay: 00:00:00

But as you see, also stopping the speakers, the last media_player.media_stop service stops only one speaker and not what i choose to play at the beginning.

How to change the script to stop the speaker i choose? Maybe a template? But which one as i am at the beginning to understand how templates work.

In your last service, you are stopping the media_player.salotto_audio. So it will stop no matter what.
If you dont want to stop this player, then just remove it.
Also I think there is no reason having that delay at the end.
So your final script should be:

radio_stop:
  alias: Stop Radio
  sequence:
    - service: media_player.media_stop
      data_template:
        entity_id: >
         {% if is_state("input_select.radio_speakers", "Living Room Audio") %} media_player.salotto_audio
         {% elif is_state("input_select.radio_speakers", "Chromecast Salotto") %} media_player.salotto
         {% elif is_state("input_select.radio_speakers", "Chromecast Camera Letto") %} media_player.camera_da_letto
         {% elif is_state("input_select.radio_speakers", "Google Home") %} media_player.googlehome5670
         {% elif is_state("input_select.radio_speakers", "Google Home Mini") %} media_player.googlehome0461
         {% elif is_state("input_select.radio_speakers", "Echo Plus") %} media_player.echo_plus__di_maurizio
         {% elif is_state("input_select.radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa
         {% endif %}
    - service: input_boolean.turn_off
      entity_id: input_boolean.radio_play
    - service: switch.turn_off
      entity_id: switch.ampli_on
    - service: script.turn_on
      entity_id: script.set_onkyo_status

So in this way i will stop every speaker is playing regarding the last service?
The delay is for having a different switch in the frontend like this instead the default one for the scripts:

21

Let me explain what you have done here:
This template will read which media player is selected at input_select.radio_speakers and will stop that player.

    - service: media_player.media_stop
      data_template:

This will turn off the radio_play boolean

   - service: input_boolean.turn_off
      entity_id: input_boolean.radio_play

This will turn off the ampli_on switch

    - service: switch.turn_off
      entity_id: switch.ampli_on

This will turn on a the set_onkyo_status script

    - service: script.turn_on
      entity_id: script.set_onkyo_status

This will stop the media player salotto_audio.

    - service: media_player.media_stop
      entity_id: media_player.salotto_audio

and finally you are having a 0 second delay… There is no point for this…
But can you see what you did there? If the media_player.salotto_audio is playing and you select the Gruppo Casa and you run the script, then it will stop the Gruppo Casa AND the salotto_audio. That is why you have to remove it.

Yes, i understood this and removed the last service as it was useless. About the delay i think i already replied to you about why i use it…
Thanks…