Rule Machine - Randomizing Actions

Hello! I’d like to create a rule that will randomly play one of three phrases on my HomePod when I return home. Currently, I have the trigger set to fire when my phone connects to WiFi, and I have three different phrases configured under Actions. Is there a way to randomize which single phrase is spoken when my phone connects to the network?

Here is an example of a rule that plays random sleep sounds at night using my Alexa device.

1 Like

I know your question is about Rule Machine, but if you have ever considered using Webcore, there is a handy and simple function for random that will just choose one of the comma separated strings.

With Location - Set Variable
speakText = random("Hello World", "Good morning", "Hello", "Hi")

  • The random function is typed into an Expression box.

https://wiki.webcore.co/Functions#random

For groovy apps, I just set a String array and then use Collections.shuffle, then I take the first element after the shuffle:

def randSaying = ["Hello World", "Good Morning", "Hello", "Hi"]
Collections.shuffle randSaying
speakText = randSaying.first()

Thanks! These configurations are quite advanced for me, so I’ll need to take some time to learn and figure out what’s happening.