First Rule that is complicated (For me)

OK, this is the first semi complicated rule that I am trying to create. What I am trying for is: Basement stairs are turned on then basement motion triggered and motion then un-triggered, wait for 60 seconds and basement stair turn off. I think what I have done makes sense but it does not seem to work. Any help would be great!

Have you considered using the Motion Lighting app?

If you prefer to stick with RM, you could consider a rule like this:

Trigger:
Basement Motion *changed*

Actions:
IF (Basement Stairs is on AND Basement Motion active) THEN
    Wait until (Basement Motion inactive)
    Off: Basement Stairs -> delayed 0:01:00 
END-IF

This assumes you don't want Basement Motion to trigger Basement Stairs to come on.

1 Like

@aaiyar I have not considered Motion Lighting. I will give it a try. I really want to get the hang of Rule Machine to create more complex rules in my automation. I will give you example a try and post back, thanks.

For Motion Lighting, I exclusively use Motion Lighting. It's easy to configure and works really well.

A simple motion lighting rule in RM would look like this:

Triggers:
Motion sensor *changed*

Actions:

    IF (Motion Sensor active) THEN
        Cancel Delayed Actions
        Turn Light on
    ELSE 
        Turn Light off -> delayed 0:01:00 minutes (Cancelable)
    END-IF
2 Likes

OK, I really need to study up on the IF, then, else, else if commands as I think this is what is really confusing me.

Think of a trigger as just something that starts the rule in motion. Since you want things to happen both when the motion is active and when it is inactive, set the trigger to be when the motion sensor "changes". That way it has the opportunity to evaluate the rules each time the state of the motion sensor changes from active to inactive or vice versa.

2 Likes

If you use RM, you may want to consider something along the lines of the following (which is an actual rule of mine, not customized to your situation).

  • This rule generally turns on my dining-room light when motion starts and turns it off 15 minutes after motion stops.
  • You want to trigger on *changed* if you want to cancel turning off the lights if motion is re-triggered before the light turns off.
  • The above rule accounts for the fact that "inactive" events from my motion sensors occasionally fail to reach my hub for some reason; the above rule turns off the light if motion has been continuously in the "active" state for an hour, as a normal human presence usually causes the motion sensor to flip back and forth between inactive/active during the course of occupancy of a space.
  • This rule also checks the state of the light before sending a Z-Wave command because I have a lot of Z-Wave devices and want to minimize unnecessary Z-Wave traffic.

Some parts of the rule may not apply to you, but I think the general strategy using "cancel delayed actions" may be something you will want to prevent the light from turning off if motion goes inactive and then gets triggered again.

1 Like

@hans.andersson thanks, I may give your rule a try. @aaiyar 's rule worked like a charm. I modified the delay time I am also going to look at a few other rule close to the few given and adding time restrictions and LUX levels in combination with a few doors and motion sensors.

1 Like

@aaiyar OK, so the rule is working and now I have a question, what is "cancelable" mean with regards to a rule such as this one?

It means that the action can be canceled. So the lights will not be turned off until repeated "motion sensor active" events end, i.e. until the room has been vacated.

1 Like

@aaiyar Just to make sure I am tracking here if "cancelable" is not selected than lights will turn off after scheduled time and if "cancelable" is selected it will basically reset the delay time to "X" each time movement is detected?

Yup. That is correct.

Thank you, just want to be sure that this rule is set the way I want it.

In your case, depending on what behavior you want, you may want to move "Cancel Delayed Actions" within the first "if" block and change the "else" block to an "else-if" block triggered only if the motion sensor is inactive (and if you do, you will also want to add a second "Cancel Delayed Actions" as the first action within the "else-if" block, right before a new delayed action is created).

Separately: Note that using an illuminance sensor in this way might lead to unexpected behavior if turning on the light affects the amount of light detected by the sensor (e.g., if the sensor is in the room to be lighted).

1 Like

@hans.andersson , by implementing you suggestion what will that do different from what I have now? Heck it wasn't until I started looking at the logs while trying to create a rule that the "proverbial" light came on!

The combination of multiple conditions in your rule could lead to what seems to me to be strange behavior, is all, but I could be totally wrong about what you're trying to accomplish.

I gather that if time is evening, illuminance is low, and motion starts, you want the light to turn on. The behavior that I would personally expect to follow would be for the light to stay on until motion has been inactive for a certain period of time, even if illuminance changes during that time or the "evening" time period expires (for example, if I'm up late for some reason). My proposed change makes that happen: The light will turn on only if all three conditions are met, and once the light is on, it will turn off only when motion is inactive for a certain amount of time.

As your rule is currently implemented, I would guess what happens (depending on where you have put your illuminance sensor) is that turning on the light causes the illuminance condition to become "false". This would mean that every time motion becomes either active or inactive, the timer would restart to turn off the light. This behavior doesn't make sense to me, though I don't think you will notice it in practice, as a 2:30:00 timer will probably not run to zero until/unless motion is actually inactive (the motion sensor being continuously active for 2 hours and 30 minutes would seem to be a rare corner case).

1 Like

Yeah, I am looking to keep it on and reset if there is any movement in the 2.5 hour window. I am trying to keep things simple while learning to use rules as such. Coming from Vera, BIG learning curve. I really did not think much about how to handle if a light is turned on and how the LUX setting would react / be handled.

@sky320

I agree with @hans.andersson. In most situations, the "Cancel Delayed Actions" belongs wthin the same IF block as the tested condition (i.e. motion is active in this case).

Consider this: Your triggering event is when the state of your motion detector is changed. That means that both "motion turns active" and "motion turns inactive" are triggering events.

Now, if you place "Cancel delayed actions" within the same IF condition block where there condition is "motion is active", then the delayed events are canceled only when motion is active.

By placing it outside of the block, delayed events will be canceled by both changes in the status of your motion detector (i.e. motion turns active AND motion turns inactive). In most situations, this is not desirable.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.