Need help creating my first complex rule

Would this do what you want?

1 Like

I think I'm making progress towards what I want...

  1. Motion under the bed detected. Turn the lights on.
  2. Wait for event (motion in bathroom) with a timeout of 30 seconds
  3. IF (motion in bathroom) {
  4. Wait for event (motion in bedroom)
  5. Wait for event (no motion in bedroom)
  6. Turn off the lights -> delayed 30 seconds. }
  7. ELSE turn off the lights

I think that flow should do it. It may need some tweaks, but that's the gist of it.

This is what I ended up coming up with. I can't test it now because my son is sleeping. But maybe I'll get a chance tomorrow.

Hope it works for you. Not that I think it won't. Just some things need real life testing instead of armchair quarterbacking.

But my advice would be from here, to clone that rule and either keep the clone as a "clean" copy, or edit the clone and keep this as your clean known good copy. Pause the one so both rules aren't running. In fact, you can have multiple clones paused and waiting if you want to.

1 Like

In addition to what neonturbo said, I would save your screenshot so if needed you can reenter without going through the creation process again.

2 Likes

To put it in another way, the trigger is "omg something just happened". You might be hiding in the forest listening for the approach of either a tiger or a bear (OR). If you're only worried if they both come at once, that would be an (AND). But that would probably never happen - you might as well relax and go to sleep if you're not worried about a bear coming without a tiger or vice versa. That's why triggers are always OR.

Now for the condition. You may only need to listen for the tiger or the bear if you haven't got your trusty and armed safari guide with you. So that would go into the conditionals "(only) IF safari guide absent". You wouldn't use your safari guides absence as the trigger, because then you'd be getting alerts every minute even when there was no danger. The safari guide's status would therefore be in Conditions.

So this mostly works. It worked great if motion is detected in the bedroom but then no motion is detected in the bathroom.

However, when motion is detected in the bathroom, and then when motion is detected again in the bedroom, it starts the rule a second time, and seems to stop the currently running instance. Is there a way to prevent the rule from running again if it's already running? In this case, the functionality I want is actually still achieved, but it would still be good info to know.

Tested it out tonight when I woke him up to go potty before I went to bed. The rule definitely is trigger every time motion in the bedroom is detected. It does seem like only a single instance of the rule can be running though, otherwise I should have had a lot more log entries and more than a single line starting "End of rule."

So how can I make a rule not trigger if it's already running?

I'm might be wrong but I don't think it's possible. Which is why I said to split it into two rules. You could probably do it in a custom app but writing apps is over my head. A node-red flow is another option.

I was thinking the same as @at9. Motion Lighting App does most of the heavy lifting. I would use a Delay Off for 1 minute in the Lights-Off section, though.

1 Like

Wouldn't that require constant motion being detected in the bathroom or else the lights turn back off?

Within the 1 minute delay-off window, at least, yes.

With 0 delay it only depends on the reset on the sensors you have so not necessarily constant motion.

True but the 1 delay gives you a full minute to re-trigger the bathroom motion sensor to keep the lights on

Is there a way to do this in RM? I'd think there has to be.

Right now I can "wait for no motion" with a timeout of 30 seconds, but as soon as no motion is detected, it will stop waiting and move on. Is there way to say "wait until no motion has been detected for 30 seconds" and then move on to the next step in the rule?

EDIT: Also... I'm messing around with creating a motion zone but I'm a little confused by some of the wording. I think I want a "triggered activation" where the trigger is the under bed motion detector.

This zone will activate when any motion sensor becomes active within the Activation Window.
The Activation Window is enabled by the Trigger Devices(s).
The Activity Timeout is started after all motion sensors become inactive.
This zone will deactivate when the Activity Timeout expires, and no further motion was detected.

The default "activation window" is 15 seconds. I don't really understand what the activation window even is. I suspect that the motion zone app will make a virtual motion detector and then only report motion as true if the under bed sensor detects motion and then the bathroom detects motion within 15 seconds. If so, that's not what I want.

The "motion aggregation" zone type seems to fit best, but it's triggered by motion of any of the grouped sensors. I want motion aggregation, but the trigger to only be 1 of the motion sensors.

You could toggle the rule's private boolean upon motion in the bathroom. Initially i have it true until motion in the bathroom sets it false. Returning to bedroom resets to true.

1 Like

Do you need to always end the rule?

@joshuadrush Not sure I understand your question in regards to that quote.

@lewis.heidrick Sorry. I replied to something you put above. Do you need to put END-IF at the end of the rule if you simply have IF, Then, Else?

It's good practice but not required. It assumes an endif if it's missing.

So I think using the private boolean might work, but I've run into a slight problem. When I modified the rule to use the the PB, it seemed to initialize to True. I went to wake up my toddler to use the potty and when I came back and checked the rule, the PB is now False and I can't figure out how to get it back to True. I think I've fixed the logic in the rule and it should always reset to True when it completes. This is what I've got now.

Quick question... is using this special "private boolean" different than using a global boolean? I don't quite understand how the private boolean can be "private" when I can apparently change it from other rules. So it seems to be a global unnamed boolean for that specific rule. Is that correct?