Motion sensors as triggers seem to behave differently than door sensors?

I have a couple of rules set up to turn on lights (controlled by two different plug-in switches) in an out-building. Here is the summary:

  1. If either of two doors in the main building are opened, turn on both switches in the outbuilding if it is between sunset and sunrise

  2. If either of two motion sensors in the outbuilding sense motion, turn on both switches (regardless of time of day). One motion sensor is in the same room as one of the switches, the other is in another room with the second switch.

I set up a third rule to turn the switches off after a delay with the trigger event being that either of the switches in the outbuilding turn on. Hence, either of the aforementioned rules could trigger the switches to be turned on. The motion sensors are from different manufacturers and both set up as Generic Z-Wave Motion Sensors on the hub.

The trigger for the third rule is as follows:

Shed Lights, Office Lamp(off, off) any turns on

I have a conditional action as follows:

IF (Office Motion Sensor, Shed Motion Sensor all motion inactive TRUE) Off: Shed Lights, Office Lamp (Command only switches that are on)
--> delayed: 0:10:00

Here is the conundrum: If the switches are triggered by opening either of the doors in the main building, the rule executes properly, with the outbuilding lights turning off after 10 minutes. If the switches are triggered by motion being sensed, then they stay on forever unless I turn them off manually. This occurs even if the device status of the motion sensors is inactive in the app or dashboard. In other words, I could have left the outbuilding yesterday, the motion sensors show inactive, but the lights stay on.

I've tried a lot of different settings in the rules, and for the life of me cannot get this to work as intended whenever the switches are triggered from motion versus contact (ie door) sensors.

For additional information, here are some use-case scenarios:

If it is dark and I leave the main building, I want the lights to be on in the outbuilding so they are already turned on when I get there.

If it is any time of day or night and I enter the outbuilding (without opening the main building doors with the sensors) I want the lights to go on as well because there is not much ambient light in either of the outbuilding rooms.

Hope this makes sense.

Any ideas? It is probably something simple, but at this point I figured I'd ask for some advice.

Post screenshots of your rules.

2 Likes

In addition to @aaiyar 's request for screenshots, it may also pay to

  • At least look at the Events for each of the devices involved, available from a button at the top of the Device Details page. For the lights / switches, it would may be interesting to look at the apps that are triggered as a result of their events, which is available on this page
  • Turn on logging for the rules you have setup and look at / post screenshots of these to help troubleshoot what is happening

At a glance, I am wondering if the "only command devices that are on" option may be a factor. Understanding the device events and looking at the rule logs may help determine this.

1 Like

That’s because the if statement is false unless the motion sensors have a rapid speed of going inactive. Look at it this way…if a sensor is active, the lights turn on, and your lights off rule runs. However, the motion sensor is still active since we are talking about milliseconds most likely in your logs.

To fix it you just need an else. Something like the following should work:

If motion sensors inactive; off light (delayed 10 minutes)
Else,
Wait for expression: motion sensors inactive with a duration of 10 minutes; light off
End-If

You need the else in the actions to capture what happens if a sensor is active when the light off rule runs.

Now that I have had some sleep and coffee, your rule could be even simpler:

Triggers:
any light turns on

Actions:
wait for expression (both motion sensors are inactive)
Turn off light (delayed 10 minutes)

Thank you JB10! That totally makes sense, I'll update the rule as you suggested. I figured it was something relatively simple, but did not have any idea of how to set it up.

1 Like

Just out of curiosity, can you also set it up with something like this:

wait for event (both motion sensors inactive and stay that way for 10 minutes)
Turn off lights

Do you think that would accomplish the same thing?

As long as I have your attention, what is the difference between waiting for an event versus an expression? If a motion sensor changes state from active to inactive, is that considered an event? If an expression is the same thing as a condition, then I suppose either one would work. One would think so.

I'll make some assumptions and guesses, then perhaps you can test them out... :slight_smile: If nothing else it can get you more experience using RM :slight_smile:

I would expect an expression to be evaluated at the time the action is reached, and if it is false at the time, RM waits for it to become true.

Correct.

No, at least I don't expect so, there is likely a subtle difference.

An expression of motion sensor is active, will check if the motion sensor is active, if it is at the time that expression is first evaluated, the expression will be true and the rule moves on. If you wait for an event to occur and motion is active at that time, the rule will need to wait for the sensor to read inactive and then active again. If you had in your mind the situation where the motion sensor is already inactive, then yes, the behaviour / outcome would likely be the same, but does not produce the same outcome in all situations.

I believe one of the reasons for the wait for expression is that it can introduce a kind of conditional trigger in a way. If you want 3 devices to each be in a certain state, there is no one event when that occurs, 2 of the devices may already be in the correct state and you are just waiting for the final one to transition, but that event only triggers the action if the other states are correct. E.g. the temperature difference between outside and inside is X and someone is home. Someone could already be home and the temperature changes, or the temperature may already be correct and someone comes home.

1 Like

@sburke781 did an excellent job of an in depth explanation. Unfortunately, using an event would not work for a simple reason. If only one of the motion sensor turned active, the inactive one would never send an event for the wait to become true. The other reason it will not work is your contact sensors as triggers would not cause the sensors to become active. Basically, you would have the inverse of your first post if you went with events instead of expression

The above is why you need to use expression. It would automatically be true if a contact sensor triggered the light and your rule would progress as normal to the light off delay command. If a sensor triggered the light, it would wait until the expression becomes true regardless if one or both sensors become active.

1 Like

Logic can be hard sometimes....

It can pay, at times, to step back and see if there is a simpler way to construct a rule so that if / when you need to come back to it, you can easily get your head back around it. Not to say that is or isn't the case here, just something to bear in mind. Also, don't quote me on this, I'm as likely as anyone to setup a complex automation :grin:

1 Like

We could have suggested Room Lighting. :wink:

2 Likes

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