Issue with Rule Using Sunrise/Sunset

I've built my first rule with my new Hubitat Elevation and am having an issue. I want to turn on my front yard lights 30 minutes before sunset and turn them off 30 minutes after sunrise. They turn on successfully but don't turn off. Looking at the rule, it appears to evaluate as true even a few hours after sunrise. Thoughts on what's causing this issue and how to fix it?

Here's a screen shot:

Check your Location page on Hubitat, It will show Sunrise and Sunset times plus tell you "day" or "night."

In other words, your hub's time may be off.

Here's my location information, which I first updated when registering my hub. The sunrise time looks correct. The lights didn't turn off even more than an hour after the displayed sunrise time.

I can't speak as to why your rule isn't evaluating correctly, but I'd like to offer a suggestion. Have you tried using the built-in Simple Lighting App? You can set lights to turn on at sunset w/ offset and off at sunrise. Much simpler.

Although I understand the Simple Lighting App is a simpler solution in this case, I need the Time of Day condition with sunrise/sunset to work in Rule Machine. This type of condition will be a core foundation to other rules I plan to build when I move devices from ST to Hubitat. Without it working in Hubitat I cannot migrate from ST.

Even though the sunrise and sunset times for my location looked correct per my previous screen shot, I manually clicked the Update button on the Locations page. I then rebuilt the rule using the same sunset/sunrise times with offsets. It now shows the condition with the correct status as false during the day. I'll see if it turns the light on and off correctly tonight/tomorrow morning. Not sure what caused this to occur, perhaps an undocumented feature?:stuck_out_tongue_winking_eye:

Are you going to create a series of rules with different time periods? I ask as I use the Mode Manager to set modes (e.g. evening mode at sunset, day mode at sunrise, etc), and then I use the mode as a condition. This helps as I have several I do and don't want to fire when a particular mode is on.

I will likely use modes as I migrate more devices and build more rules for lighting, HVAC, etc. For now I wanted to do some basic testing of the platform with simple rules to see what is/isn't working. You'll see in my previous reply to @csteele that manually updating the location seems to have fixed the issue, even though the sunset/sunset times looked correct on the Locations page.

Just tuning in to this. I don't know why your original rule didn't work -- it should have. Ha! You found a fix for the unknown problem, that I have no clue about either. But, here's a thing you can always check if you encounter this sort of thing in the future:

Click the circled-i for the rule in question, and that will pull up the app details page. At the bottom of that page are the scheduled jobs for that rule. You should see the times you expect there. If you encounter again a situation where a rule like this doesn't work, grab a screenshot of the rule (just like above) and a screenshot of the scheduled jobs, and either post it here or PM me with it. We would very much like to get to the bottom of any issue like this.

3 Likes

I had a similar rule setup, and it was working, but recently it would not. I thought it was due to my other hub issue, but now that I've replaced that other hub, it still would not work. I ended up using restrictions instead and that does work

This rule no longer works

This works as expected

Hi @bravenel.

I think I'm running into a similar issue. I have a rule (actually a trigger - is that the problem?) that turns on a few lights prior to sunset, then turns a few more on after a delay. It didn't run last night, and when I looked at the info this morning per your suggestion, it indicated it was not scheduled to run.

After looking at things and saving, scheduled jobs looks like this:

Schedule:Once stands out to me.

I'll post more info tomorrow after things run, or perhaps create an even more simple version to run as a test, but until then, am I doing something obviously wrong?

PS: for fun, here's the existing rule. Also, I had re-built it when Rule Machine 2.5 came out, but I'm not certain that's when things started going awry or not.image

Thanks!

EDIT: PPS: Do I need to add a restriction specifying "Only on certain days of the week" and include every day? I think I assumed the default would be every day.

I think there is a bug related to sunrise/sunset and there's no announcement that it got corrected in the .119 release from 45 min ago.

The workaround is to not use sunrise/sunset in a Rule condition. What @SmartHomePrimer did was remove it from the Select Condition dialog and add it to the Restrictions dialog.

You can't really do the same since you have a trigger BUT you can rewrite it as a Rule: an always true Rule with a restriction.

For condition, pick something that's always true, for example, the Rules own Boolean. They are always preset to true.

Same actions as you have, then put your Sunset-11 into the Restrictions.

{ By the way, don't expose your SMS number in your pasted Rules. It's just so tempting to send you "The evening lights should be turning on" - like every 11 mins. :smiley: }

Thanks
And you're totally right about the SMS. I would deserve it. :slight_smile:
Editing now...

Do me a favor and look in Rule Machine (parent) and it shows what version your are using, like this:

03%20AM

What is the number on the right? There was a bug with sunrise/sunset offsets, that was fixed recently. This fix was in Build 1.1.1.118, and RM should show Version 2.5.2 or higher.

Here's what I've got:
image

(I also just did the update to 1.1.1.119 about 10 minutes ago, so I'm not sure if the rule machine was different prior to that.)

There is one more fix for sunrise/sunset offsets that has not been released. This one has to do with an offset prior to sunset today. That is, when you set up a rule right now with an offset before sunset, it won't be scheduled for today. It will work tomorrow. That bug is fixed but not released. Perhaps that's the one that got you.

Perhaps. I'll let things go for a few days (without monkeying with that specific rule) and see what happens.

Right now, the "Next Run Time" entry for the Scheduled Jobs looks correct. (I'm still concerned about the Schedule: Once entry.) I have a feeling it will actually run this evening correctly, then not run tomorrow. I'll check the Scheduled Jobs in the morning to see if it ends up empty.

The way it works for an offset prior to sunset is always going to be Schedule Once. Because Sunset changes every day, so it can't put in a schedule that repeats. Every day just after midnight there is a hub event called SunsetTime. RM grabs that event and calculates when the before sunset event has to run and schedules it to run once.

You can look in Location Events to see the SunsetTime event from this morning, and see for yourself if the offset from that equals the Run Once time.

For an offset after sunset, it simply gets the Sunset event that the hub fires every day, then schedules to run that many minutes in the future.

Thank you for the explanation about the "Once" entry.
I checked for tonight's Sunset time, and did the math to ensure that Next Run Time indeed looks correct (Thu Jul 26 19:44:59 PDT 2018). Thus, I expect it run this evening. I'll let you know what that line looks like in the morning.

Dang, 44:49 is supposed to be 45:00. That's a nit I've been chasing for a bit. :sunglasses:

1 Like