How to send a random .mp3 from a folder to media player?

I have a working config to send random text statements to the TTS engine. I’d like to add the ability to upload a folder full of mp3s and send a random one to a media player based on a trigger. The best method would just grab a random file from the chosen folder so I could swap files without changing the config, however, if that’s hard, I’d be OK putting specific file names into a list. Anyone done this? What would the config for something like that look like?

Thanks!

I guess no one has a way to do this with yaml. Would it be easier to try this in Node Red or Appdaemon? I haven’t delved into that yet.

I want to do something similiar. Maybe some one can help?

I have a folder with some mp3 files in it. I just want to play a random song over one of my Google Home devices. Can do it trough YAML automation or Node Red.

Thanks!

Figured it out with Node Red. Key was giving the mp3 number file names like 1.mp3, 2.mp3, …

Then I generate a random number in Node Red and pass it to a play_media service call.

{"media_content_id":"http://192.168.178.30:8123/local/{{payload}}.mp3","media_content_type":"audio/mp3"}

Works perfect!

Easy to do in YAML as well.

- service: media_player.play_media
  data_template:
    entity_id: media_player.something
    media_content_type: audio/mp3
    media_content_id: "http://media_server/audio/{{range(1, 51)|random}}.mp3"

It assumes there are 50 tracks available, from 1.mp3 to 50.mp3.

4 Likes

Hi, what media player hardware is needed for this YAML? Would this work on Alexa? Thanks!