Lights turn on for 5 minutes after door lock code entered after sunset and before sunrise

Hello, I'm trying to write a complex rule, but I'm struggling.

I would like to have my front door light come on after the front door lock has a code entered. I would like the light to stay on for 5 minutes and then turn off. I'm hoping to set this automation to happen after sunset and before sunrise.

Is this possible?

EDIT: OK I think I figured out The Front door lock any lock code and turning on the door light between sunset and sunrise. I'm still trying to figure out how to set a timer for the light to automatically turn off after 5 minutes.

I didn't test this but something like this should put you on the right track.

1 Like

Thanks JNS.

Mine Looks a little different, but hopefully it will work.

Check the "Cancel?" flag on your delayed action (the "off" action)--otherwise, your "Cancel Delayed Actions" action won't actually do anything. That's what makes this countdown effectively reset if the door is unlocked again; otherwise, it will keep that countdown going and schedule an "off" three minutes after every unlock, even if it's unlocked again during that timeframe (so it will turn off sooner than expected, possibly multiple times).

The rest looks good to me! Keeping the "Cancel Delayed Actions" action inside your IF is probably better; that way, you won't run into an edge case where, say, you unlocked the door once before sunrise, then sunrise hit, then you unlocked it again before the 3-minute countdown was up (with the "Cancel Delayed Actions" outside the IF, the light would never turn off in this case; here, it would but wouldn't start the 3 minutes over with the second unlock).

Thanks for the advice. I think I've updated it correctly..?

I don't see any changes except 2 vs. 3 minutes. What you need to do is edit the "off" action, and where you checked the box for "Delay," also check the box for "Cancel?". The delay time is still up to you and not the problem.

My bad.:slightly_smiling_face:

Thanks for the help. I'm still trying to get the hang of it.

You still need to have the 'Cancel delayed actions' in there. The way you wrote it nothing will ever be canceled. Marking something as (cancelable) just makes it able to be canceled. You need to issue the cancel delayed actions statement for it to be canceled.

That should work! To be complete, I'd add an END-IF as your very last action. Rule Machine will imply it for you, but it's still good practice. :slight_smile: (This will matter if you want things to happen afterwards that aren't part of the conditional or if you have nested conditionals and...just a good idea to close it out, even though it's not a problem here.)

Thanks for the assistance. :smiley:

2 Likes