How to pick a random number between 1-50 and enter it as a parameter

Hi all,

I'm looking for some creativity on how to accomplish something. I need to basically create a rule that when a button is pressed, picks a random number between 1-50 and enters it as a parameter in a custom action. Is this even possible?

My use case is that I'm using an ESP32 with WLED flashed on it as a LED controller for a WS2811 individually addressable LED Strip. I'm using a custom driver that integrates WLED with Hubitat. WLED contains roughly 50 pre-programmed 'effects'. Setting the parameter of the device to any number between 1-50 will select a different effect.

The LED strip is in my daughter's room and I'd like to program a Pico remote button to randomly select an effect by randomly choosing a number.

Any ideas?

This thread may help get you started:


Thanks! I think I'm close but now just need to get the variable into the parameter of the device but I'm getting an error.



but I'm getting this error;

Oops, never mind, forgot the % at the end of the variable name!

It seems to be working! But i'm still getting an error:

The error doesn't seem to bother anything and the LED controller is picking a random effect now with the push of a button. My daughter is going to be so excited! Thanks @672southmain! I'm also a little more familiar with variables now which have been a black box to me mostly!

Sorry to make you struggle without giving an answer you could simply copy, but it’s the only way I knew to get you to think and learn.

Sadly, the Hubitat documentation is cr*p, in my opinion.

Here’s a screenshot of the two lines of a rule you need to insert to get the number (1 to 50, inclusive) you want. I added a logging statement so you could try it a few times, but the way to test, really, is to just create the two line Rule that sets Effect, and hit the “Run Actions” button and watch the resulting value of Effect.

No worries, I totally get it! Where do I find the "add 1 to variable" in the list of actions? I can't find it anywhere!

Nevermind, spoke to soon.. found it!

1 Like

Edit: see you found it.

Sorry! Thank you though! I think everything is working great now! Minus that pesky error grovvy error.

One more for good measure

That’s being generated by the driver. I don’t have that device, so I can’t know what the driver wants. I’d look at the code, but I don’t have the driver. If it’s a community driver, open it up, look at line 488, and at the definition of the setEffect routine and what types it expects for arguments.

Does it generate the error if you call it with integers 1 to 50 ?

Oh that makes sense then. Here's a screenshot from that area of the driver code:

If I manually set an effect through the driver, I get the same error in the Log. Perhaps it's expecting and FX Speed, FX Intensity and Color Pallette as well; although it works fine without them as it seems to be using defualt ones built into the effect.


Sorry, I just realized the line numbers from the device driver didn't show up in the screenshot. This is line 488: def paletteName = state.palettes.getAt(pal.intValue())

This is probably more something for the guy who wrote the driver but I appreciate you looking into it for me anyways!

Looking at the log, it seems to indicate that the effect is some sort of enum (Halloween, Theater Rainbow, etc.) or list. I can understand why it barfed on 53, if your docs indicate it wants 1 .. 50, but I don’t understand the other errors.

Is there an enum or list or map earlier in the driver that is used as the type for fx?

I don't see anything. If you're interested, here's the code on GitHub but don't feel obligated at all to spend time on it:

Glancing at the driver, the error is always when it tries to get the Color Palette name. Try putting a valid palette in as a parameter.