Iterate over list of dimmer devices setting unique dimmer level


#1

1) Give a description of the problem
I’ve created an array of dimmers and I’m iterating over each device (using a for each) applying the same set of actions with the exception of each dimmer having a unique dimmer level needing to be set.

I’m trying to avoid setting up a huge block of IF statements for each device and abstract it out where I could define these dimmer level values in the head of the piston.

If I were programming this, I’d create a key value pair where the device acts as the key and the dimmer level is the value, but I’m not sure something like that is possible in with webCoRE.

Any ideas? Thanks


#2

This should send you in the right direction:

List your devices in the ‘Dimmers’ variable
List you levels in the ‘Levels’ variable, comma separated in the same order as the devices.

array( 0, variableName) returns the first item in the comma separated list
array( 2, variableName) returns the third item in the comma separated list
array( $index, variableName) returns the ‘for each counter’ item in the comma separated list

In the example above:
RGB Bulb 1 = 10%
RGB Bulb 2 = 20%
Dimmer 1 = 30%


#3

Perfect! That worked exactly as I needed. Thanks for the help.