# Help with Porch Lighting Rule Please

Can someone help me figure out whats wrong with this? The lights come on anytime door or motion fires, day or night.

From the rule I would suggest that whenever the door sensor is open it will turn on.
You have this.
Door sensor
OR
Motion
AND
Time is.

So how could i correct it to only come on between sunset and sunrise? Should the time restriction be in the trigger too?

Need parenthesis around the OR part.

1 Like

``````ACTIONS
(Door Sensor open
AND
Time is between x and y)
OR
(Motion active
AND
Time is between x and y)
THEN``````

I'll try it. Thanks

Or this.

``````Time is between x and y
AND
(Motion active
OR
Sensor open)
``````

Make sure you put in the parenthesis around motion and sensor.

1 Like

Not sure I know how to add the parenthesis??

In actions.
Conditional actions
Select
---> ( sub-expression

And similar again to close the bracket

Oh OK. Thanks again

No problem.
The parenthesis' enable you to make a series of equations that lets you make some quite complex rules if you want.

It doesn't hurt to add them, but you don't need parentheses. `AND` and `OR` are (like mulitplication and division) evaluated left-to-right with equal precedence. You can see this here, where `False OR False AND True` evaluate to `False` because it is equivalent to `(False OR False) AND True`, the only other grouping (in this order) that also achieves this result:

This means that you likely have another problem going on, so changing what you have might not help. In fact, you can see that your time condition evaluates to "F" (false) right now, or whenever that screenshot was taken, so if you open the door or create motion, you should find that nothing happens. If it does, are you sure you don't have any other rules/apps affecting the same devices? If you don't think so, I'd turn on logging for the rule so you can see what it thinks it's doing (or skipping).

Finally, you didn't ask for help with this part, but the rule itself seems unlikely to be what you want: you're turning the lights off 2 minutes after motion becomes active, not inactive, and similar for the contact sensor. Most people would start an "off" timer like you have after motion becomes inactive or the sensor becomes closed. Are you sure this is what you want?

Had not considered that. I will play around with it. Thanks to you as well

You can always nest the conditions instead of trying to make complex logic.

``````IF (door open OR motion detected) THEN {
IF (nighttime) THEN {
Do stuff
}
}
``````

However, in this case do you need to even check the door or motion sensors? They trigger the event so you should have to test for them. Your code is already running. Just check your time constraint and turn on your lights.

Hey guys , this seems to be working. I will change times to sunset sunrise later. However, I am getting this error (see second pic) Can anyone explain what it is?

Personally I would do it like this so that while there is motion or the sensor is open the light will stay on.
After your current THEN I would have this.

``````Dim: Front Porch, Carport: 100.
Cancel delayed Actions.
ELSE
Turn Off Front Porch, Carport. Delay 0:01:00 (Cancelable).
END-IF.``````

Personally, I would do this a bit differently. Since you have the door sensor and the motion in the trigger, you don't really need it again in the actions. One of those triggers must have happened for the rule to trigger. There's no need to repeat in the actions unless you care which particular thing did the triggering. So I'd do something like:

``````Trigger:
Door Sensor open OR
Motion A, B, C any active

Actions:
IF Time between Sunset -15 minutes and Sunrise +15 minutes THEN
Dim lights
Delay 0:02:00