#Is there a way to list X number of source files in yaml and have HA randomly pick one from list?

5 messages · Page 1 of 1 (latest)

wheat lotus
#

I'm using the following code as part of an automation. Is there a way to list a bunch of different "source" files and have HA choose one randomly from the list to play every time my event is triggered?

metadata: {}
data:
source: pacmangoodbye.fseq
target:
entity_id: media_player.fppbasement
action: media_player.select_source

cyan hullBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

dry matrix
#

You can do it with a template fairly easily and the | random function.

wheat lotus
#

Thanks, do you have any examples of a tempate doing this? I have not worked with templates yet.

dry matrix
#

If they are in your /www directory, you could do something like

{% set files = [‘file1.mp3’, ‘file2.mp3’, ‘file3.mp3’] %}
{{ ‘http://<ha address>:8123/www/‘ ~ files | random }}