MEDIA PLAYER randomize media_content_id

I am trying to play a random song to alexa for Christmas.

alias: test random song
sequence:
  - service: media_player.play_media
    data_template:
      media_content_id: >-
        "{{ ['Jingle Bell Rock by Bobby Helms', 'All I want for Christmas is you
        by Mariah Carey', 'Last Christmas by Wham!',   'Its beggining to look a
        lot like Christmas by Michael Buble', 'Rockin Around the Christmas Tree
        by Brenda Lee'] | random}}"
      media_content_type: spotify
    target:
      entity_id: media_player.attic
mode: single

It is not working. However it does work with a single song.
When I run it it doesn’t give me any errors. However it doesn’t play a song either.
What I am doing wrong please?

Does it help te remove the double quotes “” as you are using >- already?

alias: test random song
sequence:
  - service: media_player.play_media
    data_template:
      media_content_id: >-
        {{ ['Jingle Bell Rock by Bobby Helms', 'All I want for Christmas is you
        by Mariah Carey', 'Last Christmas by Wham!',   'Its beggining to look a
        lot like Christmas by Michael Buble', 'Rockin Around the Christmas Tree
        by Brenda Lee'] | random}}
      media_content_type: spotify
    target:
      entity_id: media_player.attic
mode: single

thanks for the reply. Nope it doesn’t make any difference.

The following doesn’t work but it doesn’t give any errors either…

alias: test random song
sequence:
  - service: media_player.play_media
    data_template:
      media_content_type: spotify
      media_content_id: >-
        {{ ['Jingle Bell Rock by Bobby Helms', 'All I want for Christmas is
        you             by Mariah Carey', 'Last Christmas by Wham!',   'Its
        beggining to look a             lot like Christmas by Michael Buble',
        'Rockin Around the Christmas Tree             by Brenda Lee'] | random
        }}
    target:
      entity_id: media_player.attic
mode: single

I’ve managed to solve this problem.
It seems that media_content_type must be written with capital case.

media_content_type: SPOTIFY

I was writing it with small case and it didn’t work.
As soon as I wrote it with CAPITAL it did work!!

1 Like