Piston to randomly choose one variable to speak


#1

1) Give a description of the problem
I don’t know if it’s possible to even do this.

2) What is the expected behavior?
What I would like to do is based on a trigger, play one four sayings that I have stored as variables. Basically whenever the trigger happens, randomly choose one variable and play that back.

**4) Post a Green Snapshot of the piston


#2

Easy… just use the random() function in an expression like so:


#3

Man, that is awesome, thank you so much!


#4

I was playing with random() in my Echo Speaks pistons and it doesn’t work well for me. Alexa always says bravo in this expression…

"Its " + @WeatherCondition + " and " + @WeatherTemp + " degrees outside. " + "The garage door is " + [GarageDoor : contact ] + random(" alpha "," bravo ", " charlie ")


#5

I just tried the following and it popped up alpha once, then bravo… so it seemed random:
'My text is ' (text1) + random(" alpha "," bravo ", " charlie ")


#6

That’s weird, in a quick test piston I did it worked great. Should not be different that I was calling defined variables rather than just text.


#7

Thank you, I will do some more experimenting.


#8

Or if you really want no duplication… a little bit more work but I feel satisfied lol


#9

What did you set lastcolor to, or how did you define that?


#10


#11

Nice, thank you!


#12

This is very intriguing to me. At first I couldn’t get it to work, but now I think I got it. Does it look right to you if I wanted to use something like this to randomize speak? Your code just looks so much cleaner and less cluttered then mine. In my instance would the wait command be neccessary?


#13

Wait shouldn’t be necessary and at first glance the piston looks like it would work.