Code from home assistant cookbook, I don't see how it can work

There’s an automation to have media casted when you have two radio select inputs with one having a chromecast selected, and another with the media, but the part I have below is to stop the media being casted, which is where my confusion lies.

When the user selects None in the input select with the chromecasts listed, it should stop the media playing on whatever chromecast was selected, but the trigger in this code is when the user selects None, and at that point the code has no clue what was previously selected.

  1. am I correct or am I missing something?
  2. how would you actually accomplish this if i’m not incorrect


  - alias: Stop Streaming Radio
      - platform: state
        entity_id: input_select.radio_station
        to: "None"
      service: media_player.turn_off
        entity_id: >
            {% if is_state("input_select.radio_player", "Mansarda") %}
            {%-elif is_state("input_select.radio_player", "Doccia") %}
            {%-elif is_state("input_select.radio_player", "Bed") %}
            {%-elif is_state("input_select.radio_player", "Bath") %}
            {%-elif is_state("input_select.radio_player", "Salotto") %}
            {%-elif is_state("input_select.radio_player", "Salotto Video") %}
            {% else %}
            {% endif %}

The presumption is that the media player you selected is still the one in the box.

If that doesn’t work you’ll need to adjust the code for your use case.

The Media player you selected is no longer the value in that box because the value in the box is now None, which is the trigger. So it’s trying to turn off a media player with an entity id of just None

This code definitely doesn’t work, no matter the use case.

No, the code is triggered by changing the radio station input_select, not the media player input_select.

So you set the media player to livingroom and the radio station to Radio 1. You listen to the music. Then you change the radio station to ‘none’, it stops the music. It knows it’s the livingroom one because that’s still in the input_select for the media player.