Using variable with media player

I would like to run a script, that would start playing some radio station on mopidy media player. The name of the radio station would be retrieved from a custom component - variable. So if I run this script, it works:
…scripts…

play_radio:
  sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.mopidy_dnevna
        media_content_id: http://live-a.radio.si:80/Europa05
        media_content_type: 'audio/mp4'  

But if I assign station name to some variable and then use the variable value in the script, it doesn’t work

variable:
  radio:
    value: "abc"

…scripts…

play_radio:
  sequence:
    - service: variable.set_variable
      data:
        variable: radio
        value: http://live-a.radio.si:80/Europa05
    - service: media_player.play_media
      data:
        entity_id: media_player.mopidy_dnevna
        media_content_id: { states('variable.radio') }
        media_content_type: 'audio/mp4'  

Could you please help me with the correct syntax?

try:

    - service: media_player.play_media
      data:
        entity_id: media_player.mopidy_dnevna
        media_content_id: "{{ states('variable.radio') }}"
        media_content_type: 'audio/mp4'

And use data_template instead of data.

1 Like

Crap! :smile:

I meant to include that too but forgot to change it.

Yeah it happens every 10th time to me aswell :smiley:

thanks for help, it’s working now