While Loops to Change Lights (not triggering)

time
light

#1

1) Give a description of the problem
I wrote a script that has some WHILE loops in it, but I don’t think I’m using them correctly. Ideally I’d like my lights to always come on in the evening, but then based on the while conditions, change colors for holidays. I looked at the Holiday Lights piston posted by another member here, but it looked a little too complex for my needs.

2) What is the expected behavior?
Every night, 15 mins to sunset, turn on a set of lights to a set color
~10 mins to sunset, change the colors based on dates (for holidays)

3) What is happening/not happening?
The WHILE loops don’t appear to be performing.

**4) OutsideLights|226x500

5) Attach any logs (From ST IDE and by turning logging level to Full)
~LOG COMING LATER~ although I think I just don’t understand how the while loops are supposed to trigger.


#2

Without seeing any code it makes it a bit difficult to determine what’s going on. You can post a snapshot using the Green camera button in the piston and that would be most helpful. However, I doubt a while loop is the right thing for this anyway.

I think a simple IF condition would be better.

But again, w/o code we have no idea what you’re doing.


#3

Sorry about that, I thought it was attached before, but I’ve uploaded a new screenshot of the code.

I really think my While Loops aren’t executing at all, but that could just be because of user error in interpreting the code.


#4

They aren’t…here’s why…

image

A piston can start by a Trigger or in the absence of all Triggers it will use conditions. But when you have both Triggers and conditions, only the Triggers will start the piston.

So…you can see from the screen grab I took here that Line 18 is a Trigger. The lightning bolt signifies that it is a line which will cause this piston to run. So at 15 minutes to sunset, the piston will fire off. Then it will run through and when it does it gets to Line 27 and determines that the Time of day check is not satisfied, so it quits there.

The piston does not run both at 15 minutes to sunset and then again at “after 10 minutes to sunset”. You’d need more Triggers to get that to happen.

Seeing what you’re doing though, I still don’t think you need While statements for that. I think IF’s would probably work better… Or maybe even separate Time statements for the various holidays. Just a thought.


#5

if you change the while statements from:

while time is after 10 minutes to sunset, but only ...

to something like:

while time is before 30 minutes to sunrise, but only ...

that should work fine so long as the dates match.

EDIT: looking at your while statement that should actually work fine as is if you change the after to before.


#6

Thanks for the help everybody. I ended up using a combination of the BEFORE while loops and setting up individual IF statements for each loop. I ran a test last night and it seems like everything is working for me now.