Help with Porch Lighting Rule Please

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
image

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:

image

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?

image

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
    Fade lights
  END-IF

I'd also add in @bobbles suggestion to keep the lights on while there is any motion.

Hi @jabecker I'm not saying your way won't work as I've never tried it that way, but if you don't have the Door Sensor or Motion Sensor in the IF-THEN, then the lights will turn off even if the door is still open as your are only using the door open as a trigger.
Like I say, I'm not saying it won't work but it just doesn't feel right to me.

Lots of ways to skin a cat though!!!!! :+1::grinning:

Thanks for all the help and suggestions guys! How bout that ERROR? Anything to be concerned about

For the error, I don't know, but it maybe because you are not putting a delay against an actual device. Try putting the delay against the Dim: Light; 0. like I've done in the example above.

Ok Iā€™ll try that

Honestly, all of the ways discussed above seem a bit weird. Yes, the lights could still turn off if the door is open because nothing is checking for that before turning them off. They could still turn off if motion is active, too. This is not the way most people would set this up. Here is a more common setup:

Triggers: Motion sensor *changed* OR Contact sensor *changed*

Actions:

IF (Motion sensor active OR Contact sensor open) THEN
  Cancel Delayed Actions
  IF (Time is between x and y) On: Light Switch
ELSE
  Delay 0:01:00 (cancelable)
  Off: Light Switch
END-IF

This way, the lights won't turn off until motion is inactive and the contact sensor is closed. (It will also turn them off even if this automation didn't turn them on or it is now outside of the specified "on" time; most people want the latter, and there are ways to work around the former if you don't want that.) I can think of very few cases where you'd want motion to turn off based on when motion becomes active rather than inactive.

And if this all you're doing, I wouldn't use Rule Machine at all. Motion Lighting can handle this with none of the above effort. Your original rule did have a fade out, but I don't see that in the new version; you'd need RM or another app to handle something like that.

I've never thought of doing it the way you have described above. Makes perfect sense when it is all laid out.
I've always gone down the road as I've shown.
Nice one..

It's one of the first examples in the Rule 4.0 documentation, which I recommend reading so much that I should probably have a shortcut that types this sentence for me. :slight_smile:

I agree but I didnā€™t want to stray too far from the original question.

The biggest difference I had was I used a motion group for the sensors. That way I didnā€™t have to deal with them turning on and off independently as I moved around outside. I used the changed condition to trigger and then used On/off condition to trigger the lights. It worked well because my motion sensors have a 4 minute timeout. I didnā€™t need a delay.

The logic looked something like this:

IF (nighttime) THEN
   IF (motion detected) THEN
      Turn lights on full
   ELSE
      Dim nightlights
      Turn off other lights
   ENDIF
ELSE
   Turn off all lights
ENDIF

If there was any motion the lights would go on full then back to dim when motion stopped. I put the full off in the outer loop just in case the motion ran past the time constraint. That way the would turn off during the day without fail.

It worked well but that was only the start. Now I have a custom app that has overrides and special holiday scenes. For example, starting tonight the lights are yellow and orange for Thanksgiving but still come on full if anybody come onto the property. Then they dim back to the seasonal colors. At midnight they return to the regular nightlong settings. It has been a fun project and really took a bit to get me over the initial learning curve.