Single Rule After Sunset Before Sunrise Light Automation

I am trying to have lights turn on 15 minutes after sunset and turn off 2 hours before sunrise in a single rule, but not sure if that’s possible.

I have the triggers which was easy:

but can’t figure out how to make the on and off work properly in a single rule. Worse case I can just split the on and off functions into their own rules, just wasn’t sure if I was missing something as I’m still trying to learn more about sharptools.

Since the triggers are after sunset and before sunrise, you can use a condition with a time value to determine which one it is.

For example, you could say:

IF time is before sunrise
THEN //must be your before sunrise trigger
ELSE //must be your sunset trigger

Or even an arbitrary time in the middle of the day to split the difference:

IF time is before 12:00 PM 
THEN //must be your before sunrise trigger
ELSE //must be your sunset trigger
1 Like

That makes sense, thank you!

1 Like

I’m also trying to learn SharpTools, (seems like a big group- LOL). I’m confused as to if/why this will work. I’m working on some similar Rules.

The IF states “current time is after Sunset”. Isn’t it going to be “true” that it is always going to be “after Sunset” UNTIL it is actually Sunrise?

120 minutes before Sunrise is still after Sunset.

Am I still thinking in WebCoRE logic???

I am still learning but I believe that “sunset” would be the sunset for that day in time, and then “sunrise” would be also for that day in time.

So if the rule is triggered at 11:59pm sunset would be that night’s sunset that occurred a few hours prior while sunrise would be the sunrise that occurred that morning.

Once you hit 12am “sunrise” changes to be the next sunrise that will be happening within the next 4-10 hours and “sunset” would be the sunset that would be happening later that night after sunrise.

Taking a look at the rule I made (Let’s say that sunset is always 8pm and sunrise is always 6am):

If we break down the rule I made we have two triggers.

  • 15 minutes after sunset
  • 120 minutes before sunrise

The first time the rule is triggered would be at 8:15pm. Sunset happened at 8:00pm so the rule is true as current time (8:15pm) is after 8pm.

The second time the rule is triggered would be at 4am. Sunset is suppose to happen at 8pm, so the rule is false as the current time (4am) is before 8pm.

1 Like

Can you verify this works? Maybe (no, I am, stuck in WebCoRE logic) “$Sunrise” vs. “Sunrise”. I only see 1 Sunrise in SharpTools…

I’ve got multiple half baked Rules right now… looking for what works.

Can you verify this works?

Yea I will in about an hour :slight_smile:

Okay so looks like what I said earlier is true. Here is how I tested if you want to do it yourself (my porch lights also turned on correctly when expected from my rule posted earlier in the thread).

I created this rule that is just triggered by pushing a button I then have two if blocks one for sunset and sunrise. Doing before or after is up to you, just make sure the logic makes sense to you.

For me I got the following results:
It is after sunset
It is after sunrise

So my first if block (current time is after sunset) returned true and my second if block (current time is before sunrise) returned false.

You can also see in the logs for the if block what time is used for sunset and sunrise
image
image

After midnight I’ll run it again to make sure the local sunset and sunrise values change as expected and that the if blocks return the flipped responses.

Edit: After rerunning after 12am the results were flipped:
It is before sunset
It is before sunrise

1 Like

Good to know! Thanks for reporting back.

1 Like