I have a piston that I can’t quite get working. The goal is to have the floor lamp in my office act as a night light triggered by a motion sensor if I get up in the middle of the night to use the bathroom.
My desire is that the piston turn on my office’s floor lamp bulb (Philips Hue) and set its level to 20% if time is between one hour of sunset and one hour past sunrise, but only if the lamp is off already. If it’s on, I’m probably in there working so I don’t want it changed. The restriction works fine and it doesn’t mess with the light if it’s on already, however, right now it comes on but never goes off and I don’t understand why.
Your way is cleaner but I my condition of not adjusting the light if it’s already on complicates it. The if statement will fail the next time through and not reset the timer. What’s the slick workaround of that?
Okay, I haven’t used variables in that way because I’m unsure of the rules of initialization. But your code implies that the variable is not destroyed or altered between piston runs. I’m sure your code works, I’ll give it a try.