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.
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.
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 ?
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?
For some reason it's getting an array of 0 instead of a number when you call the function. Technically it shouldn't have even worked. I added the segment index to the setEffect call, see if that fixes this for you.
Thanks! I'll try that new driver soon. For now, things are working great minus that error in the log. Nice to have this awesome LED controller integrated into Hubitat.