Managing color temp across lots of pistons


#1

1) Give a description of the problem
I have lots of pistons, which control a bunch of Hue and LIFX lights in various rooms. I would like for those lights to have a color temp at 7500k in the morning and 3000k in the afternoon.

It sounds easy, but I have had challenges with getting this to work reliably or in a desired manner, partially because setting the color temp causes the lights to turn on.

This means that I have to include the color temp logic in every piston I create which makes it complex to maintain and easy to make easy to make mistakes.

  1. Desired result
    One thought I had on how I would solve this was to create a function (separate piston) and pass the lights being switched on through the color function. This function/piston would then then take the device object as an input, check the time of day, and set the appropriate color temp of the light object passed. OR maybe I create a piston with a trigger which fires anytime time light X turns on which then executes the color/temp time stuff - but then I think I would need a piston for every individual light bulb, which again seems like a lot of code.

The problem is when I take an action, such as changing the color, I have to specify the exact device instead of an input variable. Otherwise if I had a piston which says IF Lights A, B, or C power on, the action will power on all the lights in the target section instead of just the one that powered on.

I can’t be the only one who has had this thought. Is there a way to do this without adding the color temp/time logic to every piston I create? Does anyone have examples of how they deal with this?

Thanks for your help!


#2

Create a global integer variable

($hour24 < 12 ? 7500 : 3000)


#3

Hi, Thanks for your response!

I don’t think I can use a global variable like that. I tried setting one and the expression won’t stick.

The wiki says: “When a piston runs, a snapshot is taken of the global variables to ensure that they do not change unexpectedly while the piston is executing. For this reason, global variables cannot be used to “pass back a result” from the Execute piston action to its caller.”


#4

I’m doing just about exactly this… I have a piston that runs every 5 minutes when location mode is Home, and assigns a global variable @colorTemp based on the time of day (e.g. midnight - 30 minutes past sunrise, 30 minutes before sunset to midnight, and times in between the two). My other pistons reference this global variable, and set the color temperature at run time…

So, if the light was previously 2500K, but the motion sensor piston turns the light on at noon, it’s going to turn on, then change the temp to 3000K. It’s not going to turn the light on if it’s off, because it’s running with the action that turns the light on.

I’m also in progress in making a piston that will look at all of my color / color temperature capable lights that are currently turned on, and update the color temperature if it’s not the correct value on the global var.


#5

Do you have a piston that you are working with or just looking for ideas?

Try something like this

Define
Device lights - add all devices to control
Integer colorTemp - ($hour24 < 12 ? 7500 : 3000)
End define

If any of {lights} changes to on
Then
Using {$currentEventDevice}
Set color temp to {colorTemp}
End if


#6

Could you also help with the setup to set the colour by way of a variable? I know too little to figure out what kind of variable should be used and what values should be set to set the colour to red e.g.


#7

Do you have more info?

You would use a string variable to set the color in that variable. You can use hex codes like #FF0000 for red or the actual name like Red.


#8

Trying this now. I’m using LIFX Group of Groups, which doesn’t immediately pass the on/off state to the app for the individual bulbs, so they don’t change until they get an update. (these 3 bulbs are all in the same group, but two of them use Kelvin and the other uses hex)

If I tell it to listen to the status of the group switch, it works, but… Alas, a delay in changing color.


#9

Okay, the trick to using this with LIFX Group of Groups is to create a GoG device for each set of bulbs, even if it’s just one bulb. Then sync them with LIFX Sync and tell it to listen to the on/off state of the group(s) (not the individual bulbs). It’s pretty fast this way (at least as long as LIFX isn’t having API issues, which could very well be happening cause of me right now…) :rofl: