Randomize media_content_id?

I am trying to figure out how to get randomize an id for the following:

- service: media_player.play_media
  data:
    entity_id: media_player.bedroom_audio
    media_content_id: "http://192.168.1.7/audio/morningmusic1.mp3"
    media_content_type: "audio/mp3"

I’m guessing that i would change to this = media_content_id: !include random_music.yaml

but then what do i put in the random_music.yaml?
Lets say the different options are:
http://192.168.1.7/audio/morningmusic1.mp3
http://192.168.1.7/audio/morningmusic2.mp3
http://192.168.1.7/audio/morningmusic3.mp3

Thanks in advance!

Check out ih8gates posts here.

1 Like

I saw that one but it was more convoluted to understand.

Look for the line that begins with
media content Id:
and ends with RANDOM.

I can’t type it out on my phone for you right now but will later when near a keyboard if you still need it.

No luck? Try this.

- service: media_player.play_media
  data:
    entity_id: media_player.bedroom_audio
    media_content_type: audio/mp3
  data_template:
      media_content_id: >
       {{ ["http://192.168.1.7/audio/morningmusic1.mp3", "http://192.168.1.7/audio/morningmusic2.mp3", "http://192.168.1.7/audio/morningmusic3.mp3"] | random}}
3 Likes

Awesome! Thank you very much!