Turning on lights if contact is opened between sunset and sunrise

I'm trying to set it up so if the front door is opened between sunset and sunrise the front porch lights come on. I choose between Sunset and Sunrise and save it and it shows "Time between Sunset and Sunrise FALSE" which to me indicates if that would be a time outside of sunset to sunrise. When I click it, it says time of day between sunset and sunrise without the false. If I click NOT, it switches it to " NOT Time between Sunset and Sunrise TRUE" which is still outside of that time. Anyway, does it look like this will accomplish what I'm looking to do? Thanks for any help you can provide on this.

Here is what I did:

1 Like

You've set your trigger.
I would change OPEN to CHANGED
Your action is to turn the light on.
You have not put in any conditions or when to turn the light off.
Let's say you want it on for 10 minutes.

Time is between sunset and sunrise.
Door is open
Turn on lights.
Cancel delay.
Turn off light - delay 10 mins (cancellable)

The cancel is if the door opens again in the 10 min window before lights turn off


I setup something separately to turn off the front porch lights after 10 minutes any time they are turned on. We live in the woods so the bugs would be horrible in the summer if they were left on. I just did it as its own rule so if someone uses switches to turn them on, it would turn them off. I guess the part that confuses me is if it says "Time between Sunset and Sunrise FALSE". To me that's like saying it's anytime outside of that time frame.

The [FALSE] indicates the current status of that condition, so

Time between Sunset and Sunrise FALSE

means that the condition is (Time between Sunset and Sunrise), and currently, that expression evaluates to false.

You still need to use the conditions you have defined in the rule.
Just defining the conditions does nothing. You have to actually specify them in the actions for the rule.

Ahhhh, well that clears that part up! Thank you!.

If you change your triggers to "changed" like @bobbles suggested, it'll be more reliable and you could combine your off condition using if then statements and adding a delay with cancel. Just a thought. Two rules is just fine too.



Is this light ever turned on in any way outside of (Sunset to Sunrise)? If so, I believe the example given will have the side effect that if the door is closed and the time is NOT (sunset to sunrise), the light will turn off after a 5 minute delay. You might want to change the ELSE to an ELSE IF (Time between Sunset and Sunrise) so that it does nothing at all if you're outside that time window.

It is. There are switches for both and they can be turned on and off via Alexa so I added a separate rule to turn them off after 8 minutes in the event they are turned on any other way.

I see what you are saying now @bobbles . I added this. I didn't notice the dropdown contained the triggers at first.

That will do the trick.
I'm not being picky as this will work OK but personally I think it's is good practice to finish the statement you have shown with an END-IF.
Like I say it will not make any difference to this simple rule but as you get more complex rules and you may have multiple IF-THEN statements you will need to use END-IFs.
Just a comment for future reference really.
Have fun. :smile:

1 Like

Looks like you got it figured out above, but is there any reason you're using Rule Machine for this? Hubitat Simple Lighting could handle this (it could be all in one app but I'd probably make two and only put the sunset to sunrise restriction on the "on" app so it gets turned off even if you open it, say, seconds before sunrise), as could Motion Lighting (which despite the name also added support for contact sensors). Here is something like this in ML:

Learning RM is great, and I'm not trying to discourage you if you are--just thought I'd point out that there are easier, built-in options. Good luck either way!


Wow, didn't know that was a thing. WAY more straightforward than the rules engine.


And if you want it to turn off again on the close just click the slider turn off when closed :smile: it should then give you a optional delay.

Happy to have helped point you in the direction of built-in apps! There are lots of them (see: "App Documentation" in the Hubitat Docs), so I'd encourage you to check out what they're capable of.

Exactly! :smiley: Do note that Simple Lighting restrictions are a bit naive. If you open the door before sunrise+30 and close it after sunrise+30, it won't turn off because your "close" event is during the restricted time. You can work around this by creating two Simple Lighting instances: one for turning it on when opened (with the restriction), and another for turning it off when closed (probably without any restriction unless you see a problem with that, or you could use a tad wider allowed time or whatever). Motion Lighting should work with just one app as above since the option I selected only prevents the lights from turning on outside that time. That being said, Motion Lighting was really designed with motion in mind and I've never tried it with only a contact sensor, but it looks like it should work...

...and now you know why RM is so tempting, since you can specify your own custom logic everywhere. But I think you have two built-in options that will work just fine here with a lot less work (and they'll likely be a bit faster: RM is a large app and with lighting automations in particular sometimes speedier is better). Good luck!