Input_text as input for media_content_id:

Hi

input_text.radiokanal has this state http://live-icy.gss.dr.dk/A/A05H.mp3

In the script below I want to use the value of input_text.radiokanal as source for streaming to chromecast. Any hints on what wrong?

p1:
alias: Play P1 on Chromecast Audio
sequence:

  • data:
    entity_id: media_player.hjemmegruppe
    volume_level: ‘0.75’
    service: media_player.volume_set
  • data_template:
    entity_id: media_player.hjemmegruppe
    media_content_id: ‘{{ input_text.radiokanal}}’
    media_content_type: audio/mp4
    service: media_player.play_media

I know it’s an old topic but did you find any solution? I’m banging my head against the wall to get this solved…

I ended up skipping the Input_text part. I’ve a dashboard with a button for each radio station. The script looks like this

p1:
  alias: Play P1 backup on Chromecast Audio
  sequence:
  - data:
      entity_id: media_player.Sorrentovej
      volume_level: '0.75'
    service: media_player.volume_set
  - data_template:
      entity_id: media_player.Sorrentovej
      media_content_id: http://live-icy.gss.dr.dk/A/A03H.mp3
      media_content_type: audio/mp4
    service: media_player.play_media

This template is incorrect:

media_content_id: '{{ input_text.radiokanal}}'

It interprets input_text.radiokanal as being the name of a variable which doesn’t exist so media_content_id is set to nothing.

It should be like this which uses the states() function to get the state value of the entity called input_text.radiokanal

media_content_id: "{{ states('input_text.radiokanal') }}"

Thanks for your reply! Eventually I’ve made an scene where I stored the settings as I wanted them to overcome this issue.

I tried that as well but for some reason the url stream wasn’t accepted.

That’s an entirely separate issue from the syntax error I described. I’ve seen it mentioned in the Adhan thread where users are unable to play the content of a URL. The issue is resolved (for some) by altering media_content_type or even changing the service from media_player to media_extractor (although others claim the two are equivalent).

If I could re-open this discussion I would like to randomly play .mp3 tracks from a local folder called Playlist.
Would I need to create an input_text or input_select with all of the track names and then maybe use a random counter or can the track filenames be read into the input_text from the folder? There are 50 tracks in the folder.
I am thinking of something like this:

address_of_pi/local/Playlist{{ states('input_text.random_list')[states('counter.random_list_position')|int] }}.mp3

You should probably post your question in a separate topic instead of directing it to me in this very old thread. My only contribution here was identifying a syntax error.

1 Like

What about just putting it all in a script? Here’s a quick and dirty outline of what I’m thinking:

play_random_track:
  alias: Play a Random Music Track
  sequence:
    - service: media_player.play_media
      data:
        media_content_id: '{{"address_of_pi/local/Playlist/"+ random_track + ".mp3"}}' 
        media_content_type: mp3
      target:
        entity_id: media_player.my_player
  variables:
    random_track: |-
      {{ ['track_1', 'track_2', 'track_3', 'track_4', 'track_5']|random }}

EDIT

Just saw this: Random MP3 file … might be even better since you don’t have to worry about making the list yourself.

2 Likes