RM 5 - Random Track for bathroom

Hi Folks, I am looking a bit of advice/steer.

I have my bathroom audio as a Hub Variable, this was so I could easily update it when I am bored and for seasonal holidays :slight_smile:
However, I now want to automate this process. Lets ignore seasonal holidays for now as we can easily deal with those in an IF Else statement and lets focus on lets say updating the variable every x minutes to a list of lets say 10 different URL's hosted on my network.

Granted I can create a rule to trigger lets say every 20 mins and perhaps do a time of day simple IF statement and just step down each of the 10 options, but this means more hassle when adding an 11th entry should it arise. Anyone any ideas on how to create a random list and then force it to randomly select from that list or am I over thinking this?

Thanks in advance.

Just off the top of my head: You can use variable math to get a random number into a variable, and that can be put into a string, thus constructing either a URL or a track name with that number. Music player Play Track could accept a string like that, or HTTP Get or Post.

I guess you better really like tracks 0 and 5. :stuck_out_tongue_winking_eye:

1 Like

Brilliant, I was getting hung up on the existing track names and not thinking logically. This makes total sense. Thank you!

You could use some indirection, by putting the actual track names in String variables whose name have those numbers in them.

@bravenel, What is the syntax to get Rule Machine to do what you suggest (use a variable reference within a variable reference)?

Variable '0' = 'filename1.mp3'
...
Variable '9' = 'filename.mp3'

Varaible 'RandomToPlay' = random # between 0 and 9

Resolved Filename = http://10.1.1.1/local/%????%

You don't use a variable within a variable, but rather create a constructed filename/url with a random element. For example make the last digit random 0 through 9, like this:

This results in urls like below:

1 Like

I understood your first response in the original thread, but filenames separated by only a single number removes all meaning of the filename.

Did I misunderstand your proposal to tuck the actual filenames into string variables that are named '0', '1', '2', etc.? How does one use the value of the random variable to reference the 'static' variable's content which includes the unique filename?

For posterity, this is how I got it to work...

To randomly select a descriptive Filename you can create a string variable that contains a list of the filenames separated by '-' (or whatever fits your scheme; however, I tried using ',' first and it did not recognize the separation). Then set a random number and use it with the 'set string - token' function to extract the descriptive filename from your list.

Since the filenames are tucked inside a delimited list, keep the names simple (no spaces or special characters, etc. ). And remember that the filenames are case sensitive.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.