Can this piston use an array rather than duplication for every device


#1

1) Give a description of the problem
I want to create a global variable for the lighting level setpoint of each Hue lamp in the house. Every minute, a timer should slowly dim the light towards that setpoint, creating the effect of a fade but one that can be cancelled on demand, or tweaked even during it’s run.

2) What is the expected behaviour?
The attached piston is working for a single device. Other pistons can reference @setpointLandingFar and it will slowly fade to the levels.
I have almost 20 Hue lamps. Rather than creating thirty copies of this piston, can I not create some sort of loop or array or way of not having to duplicate this code over and over?
If I do need to create a piston per lamp, is there any way of making it simpler to modify, perhaps only having to define the device name once and it automatically applied to every device. Is there a way of using $device to make this more modular?

3) What is happening/not happening?
I can’t seem to work out a good way to make this scalable.

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full


#2

Before you scale anything, I would recommend re-thinking the logic a bit…

Setting a @global on line 22 will not be accessible on line 25…
(a @global is only written to at the end of execution)

On the next run, (30 seconds later) it will finally see the previous change.
(but will not see the most recent level)

This essentially means that every execution will be using old data…


Pro Tip:

I normally recommend using local variables for cases like this…
(with perhaps the final command to update the @global)