Timed before/after sunset/sunrise

jjones3318

New Member
Hi - I've been trying to figure this one out without success. 
 
The premise is simple - turn the garage lights on for 1 minute if it's dark out, or if the time is less than 59 minutes before sunset or after sunrise when going from the mud room to the garage.  The G2 timer is used to prevent the lights being turned on if the garage door was opened within three minutes of the mud room door going not ready, as the lights on the garage door opener are on at that time.  The sunset/sunrise conditions need to be added to this block, which I haven't done yet. 
 
The problem is, no matter the time of day or night, this code always turns the lights on.   I can't figure out why that's happening. 
 

Code:
19. WHEN Garage Door NOT READY
           AND IF DARK
                THEN Door Timer G2 ON FOR 3 MINUTES
20. WHEN Mud Room Door NOT READY
           AND IF Door Timer G2 OFF
           AND IF Garage Overhead Lights OFF
           AND IF DARK
           OR
           AND IF Door Timer G2 OFF
           AND IF Garage Overhead Lights OFF
           AND IF TIME IS LESS THAN 59 MINUTES BEFORE SUNSET 
           OR
           AND IF Door Timer G2 OFF
           AND IF Garage Overhead Lights OFF
           AND IF TIME IS LESS THAN 59 MINUTES AFTER SUNRISE 
                THEN SET LIGHTING LEVEL Garage Overhead Lights TO 50% FOR 1 MINUTE
 
Your times are overlapping

DARK = From Sunset to Sunrise

TIME IS LESS THAN 59 MINUTES BEFORE SUNSET = 0001 to 59 min prior to Sunset

TIME IS LESS THAN 59 MINUTES AFTER SUNRISE = 0001 to 59 min after Sunrise

You can use a timeclock to encompass the entire time band, or use an GREATER THAN statement


Code:
20. WHEN Mud Room Door NOT READY
           AND IF Door Timer G2 OFF
           AND IF Garage Overhead Lights OFF
           AND IF TIME IS GREATER THAN 59 MINUTES BEFORE SUNSET
           OR
           AND IF Door Timer G2 OFF
           AND IF Garage Overhead Lights OFF
           AND IF TIME IS LESS THAN 59 MINUTES AFTER SUNRISE
                 THEN SET LIGHTING LEVEL Garage Overhead Lights TO 50% FOR 1 MINUTE

Those times encompass Sunrise and Sunset so Dark is not needed
 
If sunset is 1900 (7pm)
59 minutes before would be 1801
A time less than 1801 would be 0001 (midnight) to 1800 (6pm).
 
I'm having a hard time grasping that.  To keep it simple let's say sunrise is 0700, and sunset is 1900.  Here's how I interpreted it:
 
Time less than 59 minutes before sunset would encompass 1801 - 1900
Time less than 59 minutes  after sunrise would encompass 0700 - 0759
And dark encompasses the time between sunrise and sunset. 
 
What you're saying is that the statement is evaluated such that XX minutes before sunset isn't a range (1801 to 1900), but rather a specific time of sunset minus 59 minutes (1801), and any time less than 1801 as referenced to 0001 makes the statement true?
 
jjones3318 said:
I'm having a hard time grasping that.  To keep it simple let's say sunrise is 0700, and sunset is 1900.  Here's how I interpreted it:
 
Time less than 59 minutes before sunset would encompass 1801 - 1900
Time less than 59 minutes  after sunrise would encompass 0700 - 0759
And dark encompasses the time between sunrise and sunset. 
 
What you're saying is that the statement is evaluated such that XX minutes before sunset isn't a range (1801 to 1900), but rather a specific time of sunset minus 59 minutes (1801), and any time less than 1801 as referenced to 0001 makes the statement true?
Yes.
It evaluates the current time versus the criteria.
If sunset is 1900, then 59 minutes prior is 1801. It's a fixed time for that day.

A time less than 1801 is ANY time from 0001 to 1800. Essentially from midnight until 1 hour prior to sunset.
The time between 1801 and 1900 is GREATER THAN 1801, not less than.

You are telling it offset the time from sunset or sunrise a certain amount and calculate what time that is, then evaluate the current time greater or less than that time. Not the region between the time calculated and sunset or sunrise.

If the current time is 1700, it compares 1700 to 1801, 1700 is less than 1801, so the condition is true.
If the current time is 1830, 1830 is not less than 1801, so the condition is false.
But after 1900, the Dark condition is true.

"Time less than 59 minutes before sunset would encompass 1801 - 1900"
No - it would encompass 0001 - 1801

"Time less than 59 minutes after sunrise would encompass 0700 - 0759"
No - it would encompass 0001 - 0759

"And dark encompasses the time between sunrise and sunset. "
No - DARK encompasses the time from Sunset to Sunrise, it would start at 1900 and go until 0700.

You code will turn on the lights any time from 0001-1801, and 1900-2400

If you used a timeclock, you could turn it on 59 minutes prior to sunset and turn it off 59 minutes after sunrise, and then just check to see if the time clock was enabled instead of using the less than or greater than conditions.

Think of the DARK and LIGHT conditions as built in reciprocal time clocks with Sunset and Sunrise as their boundaries.
 
I wrote the dark part backwards - I meant sunset to sunrise.   Okay, I got it.  I used a time clock instead.  Thanks for the help!
 
Back
Top