Rule Machine trigger event if sun is set and time

Hi, Trying to understand how I can add a trigger event (or conditional action) so that if the time is 05:00 and the sun is set it will start my outdoor lights.

To clarify, I live far up north, so during the summers the sun never sets and hence I do not need to trigger the lights during the night (and in the winter I do not want to shut them during the dark days)


First, before you try Rule Machine, you might be able to do this with Simple Automation Rules, formerly Simple Lighting. See here for documentation on that app: Hubitat® Simple Lighting - Hubitat Documentation (my thinking is that you could probably use "At a specific time" and restrict the entire app in "Restrictions" based on sunrise and sunset as desired).

That being said, what you want is definitely also possible with Rule Machine. As one example, this rule:

Triggers: Time is 05:00


IF (Time Between Sunset and Sunrise) THEN
  //Do things

That being said, given where you live, I'm actually not sure if this condition ("between sunset and sunrise") will work. In lower latitudes, these times get calculated daily just after midnight, I think, but in any case they are a specific time that will presumably be used with today's date in any calculation. I'm not sure what values you'd get here when the sun doesn't actually rise or set until a future day. You can test that, or perhaps someone else can chime in with what they may know. I'd certainly be interested in finding out.

A less elegant alternative that would definitely work is using a "Between two dates" condition or using a (virtual) switch being on or off as a condition, then manipulating the state of that virtual switch via some other app/rule. As an example of the latter, I have a few automated window blinds, and they act differently in "winter" vs "summer"--not really a scientific distinction in my case, just a switch I turn on or off depending on whether I'm finally in the part of the year where it gets way hotter/sunnier outside than I want it to be inside. :slight_smile: I adjust this manually since it varies year by year, but it seems like there should be an easy approach for you since this behavior is predictable in your case. I'm just not 100% sure what would actually work best among these options.

1 Like

How does the 5:00 play into what you are wanting, also is it am or pm?
I wonder if measuring the brightness would work. There would be no dependence on sunrise, sunset or time of day.
Check out this post:

Everyone needs at least one flood light.

Could do a simple automation to turn the lights on at 5PM, and set a restriction of between sunset and sunrise

1 Like

5am. The idea is to only light the lamps at 5am IF the sun is still set , meaning during wither this will always happen and during summer never happen.

I think the both of the answer given by dadarkgtprince and bertabcd1234 hopefully will work, Thanks!

Think I was to focused that it would be complicated, comming from other systems where this was not quite possble

ahh, then adjust my simple rule to turn on at 5AM, but leave it to run between sunset and sunrise and you should be good