Set media_content_id from local file

I have list of music files where I would like to play randomly. I don’t want to hardcode the filenames into the config file as it may be growing periodically. I have a shell_command config with the following, how do I supply to the media_content_id of media_player component?
shuffle_songs: 'cd /home/hass/.homeassistant/www/songs;ls *.mp3|shuf -n 1'

You can only supply 1 content id, being a url or a playlist. I think your shell command will need to (also) create an m3u file and send that to the media player.

I found out a way to play random songs from local every day. Below is the automation:

play_morning_songs:
sequence:
- data:
entity_id: media_player.googlehome9960
volume_level: ‘0.60’
service: media_player.volume_set
- service: shell_command.shuffle_songs
- service: media_player.play_media
data:
entity_id: media_player.googlehome9960
media_content_type: music
data_template:
media_content_id: ‘https://xx.yy.zz/local/songs/today.mp3

And the shell_command.yaml is

shuffle_songs: ‘cd /home/hass/.homeassistant/www/songs/;rm -f today.mp3;ln -s $(ls collection/*.mp3|shuf -n 1) today.mp3’

2 Likes

Thanks, exactly what I was looking for. Do I put the collection of mp3 to be shuffled in

/home/hass/.homeassistant/www/collection/

or

/home/hass/.homeassistant/www/songs/collection