Expression to randomly run Global Reactions ?
-
Elcidreplied to toggledbits on May 27, 2021, 4:03 PM last edited by Elcid May 27, 2021, 12:06 PM
@toggledbits
Its a bit confusing, i read this
"[5,7,9], so this function is now obsolete and may be removed later)"
and tried [1..7], when that failed, I assumed the only way to spread was list(1..7)
May be add a note about 1..7 being the same as list(1..7). As I found it some what unclear. -
toggledbitsreplied to Elcid on May 27, 2021, 4:06 PM last edited by toggledbits May 27, 2021, 12:06 PM
@elcid , it says:
I think this is pretty clear. The range operator is documented separately.
May be add a note about 1..7 being the same as list(1..7).
But it's not. That's how we got started.
-
Elcidreplied to toggledbits on May 27, 2021, 4:21 PM last edited by Elcid May 27, 2021, 12:21 PM
@toggledbits said in Expression to randomly run Global Reactions ?:
May be add a note about 1..7 being the same as list(1..7).
But it's not. That's how we got started.
I mean 1..7 being what I assume list(1..7) would produce a single array. That's why I found it confusing, I think that I expected a array to have [ ] around them.
Maybe add "also see range operator". -
LibraSunreplied to Elcid on May 27, 2021, 5:05 PM last edited by LibraSun May 27, 2021, 3:05 PM
@elcid said in Expression to randomly run Global Reactions ?:
I mean 1..7 being what I assume list(1..7) would produce
Funny you should mention this, since all yesterday, I grappled with the question, "How can I find the minimum of an array in MSR?" (Answer: Not easily at all!) Turns out the
min()
function only works on a list with 2 elements, not arrays of arbitrary length. In other words,min(1,2,3)
yields1
without a hitch, whereasmin([1,2,3])
returnsnull
(for good reason: There's no guarantee the argument will always be a 1-dimensional numeric array!). Same formax()
.Which led me to the realization that there's no direct way in MSR to "convert" an array into a list. Seems your brain encountered the same type of mental collision while trying to work out your imported expression.
-
-
@cw-kid Just so you know, I have a "Color Cycler" rule that uses the [Entity Action] [Set Color RGB] action with this expression inside each field ("R", "G" and "B"):
${{ floor(random()*255) }}
which makes the associated light (a Hue bulb) adopt a perfectly random color. Just something you might consider trying.
-
Thanks I will try the "Color Cycler" in a brand new rule to test it out.
I haven't as yet looked at updating my current rule with the new expression to always guarantee a new random number that hasn't been repeated etc.
I will have a look over the weekend. Sure I will have questions.
Cheers
-
cw-kidreplied to Elcid on Jun 19, 2021, 3:39 PM last edited by cw-kid Jun 19, 2021, 11:41 AM
@elcid said in Expression to randomly run Global Reactions ?:
remove( 1..7, randomVal - 1)[floor(random()*6)]
I've just tried using this in my rule set, I added it as the expression for the rule. When I press the play button next to it, it seems to work and changes to different numbers between 1 to 7 etc.
However when I restart Reactor it says it cannot find the Global Expression named "randomVal".
So I then created it as a Global Expression, the error has now gone away, but I don't understand what this Global Expression is for?
Thanks
-
-
It looks to be working OK. Its changing the colours on the LED strip every 5 minutes currently. I'll leave it running for a while tonight.
Thanks.
-