Play a random song from predefined list with LMS?

I’m trying to play a song randomly and the following works

  - variables:
      path: file:///MultiMedia/Music
      songs: "{{path}}/Pop/Peter_Gabriel/New_Blood/cd2/12_-_The_Nest_That_Sailed_The_Sky_(Instrumental).mp3"
  - action: media_player.play_media
    target:
      entity_id:
        - media_player.squeezelite_x
    data:
      media:
        media_content_id: "{{ songs }}"
        media_content_type: music
        metadata: {}

This works too:

  - variables:
      path: file:////MultiMedia/Music
      songs: "{{path}}/Pop/Coldplay/Everyday\ Life/01. Sunrise.mp3"

If I do this and any other way that I know of, it fails

  - variables:
      path: file:///mnt/zpool/MultiMedia/Music
      songs: >-
        - "{{path}}/Pop/Peter_Gabriel/New_Blood/cd2/12_-_The_Nest_That_Sailed_The_Sky_(Instrumental).mp3"
        - "{{path}}/Pop/Coldplay/Everyday\ Life/01. Sunrise.mp3"

What’s wrong, been trying for hours…

I haven’t used LMS in a while, so I don’t remember exactly what it accepts, but I’m pretty sure that multiline quote is going to produce a weird literal string instead of the list you probably want.

If you aren’t sure, the first thing I would check is that the following works (not all integrations will queue multiple tracks from the media_player.play_media action):

  - variables:
      songs: 
        - "file:///mnt/zpool/MultiMedia/Music/Pop/Peter_Gabriel/New_Blood/cd2/12_-_The_Nest_That_Sailed_The_Sky_(Instrumental).mp3"
        - "file:///mnt/zpool/MultiMedia/Music/Pop/Coldplay/Everyday\ Life/01. Sunrise.mp3"
  - action: media_player.play_media
    target:
      entity_id:
        - media_player.squeezelite_x
    data:
      media:
        media_content_id: "{{ songs | shuffle }}"
        media_content_type: music
        metadata: {}

But if you are actually only trying to have it play just one of the songs randomly, you would do something like:

  - variables:
      path: file:///mnt/zpool/MultiMedia/Music
      songs: 
        - "/Pop/Peter_Gabriel/New_Blood/cd2/12_-_The_Nest_That_Sailed_The_Sky_(Instrumental).mp3"
        - "/Pop/Coldplay/Everyday\ Life/01. Sunrise.mp3"
  - action: media_player.play_media
    target:
      entity_id:
        - media_player.squeezelite_x
    data:
      media:
        media_content_id: "{{ path }}{{ songs|random }}"
        media_content_type: music
        metadata: {}

Hi, thanks for helping!

I found my error… :blush:
It was the action, not the list :man_facepalming:

media_content_id: "{{ songs | random }}"
media_content_type: music

Funny, after I posted that I found the reason I see your edit with the same! :+1: