Sunrise/Sunset Logic Conundrum

So here's my situation. I have a rule (using Simple Automation Rules app) to turn on some outside deck lights in the morning (currently based on a specific time) and then are set to turn off a specified duration post sunrise. In the winter, this works great b/c the On Time is before the Off Time. Example: On = 6:15am, Off = 30 min after sunrise (sunrise in my northern latitude is, at the latest in the winter, 7:55am).

But now it's spring/summer and sunrise is at 5:12am which means my lights come on at 6:15 but b/c sunrise has passed, they don't turn off.

So how do I get this to work? I imagine it's something like: IF sunrise b/f 6:15, THEN don't turn on the lights, ELSE turn 'em on. Or something like that. But I can't figure out which rule app to use and how to properly configure it... :sob:

Y'all are way smarter than I am, please help!! :smiley:

Hubirat :rat:

Here's an option using Rule Machine with a couple of local time variables. Make sure you pick a trigger time that will before any sunrise time throughout the year.

Trigger:
When time is 4:00 AM

Actions:
Set SunrisePlus30 to sunrise time
Set SunrisePlus30 to SunrisePlus30 plus 30 minutes
IF (Variable OnTime <= SunrisePlus30) THEN
	Wait for event: When time is Variable: OnTime
	On: Light
	Wait for event: When time is Variable: SunrisePlus30
	Off: Light
END-IF

Local Variables:
OnTime  Type=Time
SunrisePlus30  Type=Time

Funny, I just ran into the same scenario and took me awhile to figure out what was happening. In my case tho, I use a virtual switch which comes on at sunset and off at sunrise. So all I had to do was see if the switch was still on before turning the light on.

I can read this and understand all of it, it's just translating by using the Rule Machine that's got me hung up. I NEVER :joy: would have figured this out on my own. And I'm not sure I have it right as when I created the variables it asked for a time and those times show in my rule. Would they be overwritten when the rule is run?


Is this correct? I may try the idea from @j715 as well. That seems like a super simple soln too. Tho I really need to get better at the Rule Machine.

Thanks a ton both of you!

Hubirat :rat:

I just created this using Basic Rules. It should do what you want.

1 Like

SunrisePlus30 will be overwritten every time the rule runs. OnTime should be set from the beginning to 6:15 AM. In the rule there is a Run Action button. Click on that button and you'll see SunrisePlus30 get updated.

You could use a wait for event in RM which would be a bit simpler I think

Trigger the rule at 4:00am as shown in the examples above. then your first action would be:
Wait for event Sunrise - 30 or 6:15am You can have multiple wait events so when sunrise is after 6:15 it would come on at 6:15 and auto adjust as sunrise changes.
No need to work with variables.

I thought about this but doesn't work is that when sunrise is at 7:55 in the dead of winter, the lights wouldn't come on until 6:55, which is well past the time I want them on.

@terminal3, that's a great idea!

Thanks!
Hubirat :rat: