Error in Rule Machine for Delayed actions

Now I’m confused again. How can I use motion as a trigger when the trigger is “no events have occurred to a bunch of sensors”? The only motion triggers I see are changed, activate, and deactivate.

I don’t logically understand how there can be a trigger for the absence of events.

Sorry if I’m being dense. What am I missing?

your trigger needs to be "motion changed" for all your motion sensors.

then the condition (in the select actions to run section) needs to be motion inactive for ALL your motion sensors.

here is an example:

the trigger has to be changed so that the rule evaluates both with motion and without. with motion it cancels the delay, without motion it sets the mode after a delay.

Why do you think you need the trigger of 8pm? if all of the motion sensors are inactive it will turn off the light. There is no need to trigger the rule at a specific time. You want to avoid calling the same rule twice.

The trigger, as I said above, is that the sensor has changed. A motion sensor has two states, active or inactive. Changing from one to the other is the trigger you are looking for. That way, if one of the sensors go inactive, it triggers the rule. It also triggers if one of the sensors go active.

based on @mluck’s comments in the thread, I was assuming he wants to trigger it every evening regardless of whether there is motion or not.

if he restricts the rule to only a certain time window, then it will not fire unless a motion sensor is activated and then deactivated within that window.

the 20:00 trigger would act as a last ditch trigger to make sure the rule is triggered at some point, regardless of what any motion sensors have done. whether he needs that function or not is up to him. ymmv.

If you are restricting the rule until 8pm, you might want to trigger it at 8:01. I don't know how it would take the trigger and the restriction being removed at the same time.

Let me back up and better explain the use case. I use this rule to put the house to sleep each night (i.e., put house in Asleep mode). The logic that has worked for us in ST for years:

  • after 830pm when House is in Evening mode (FYI it’s always in evening mode after sunset if someone is home)
  • if none of the motion detectors in house activate for 25 mins in a row, put house into Asleep mode.

That’s it. Can you see why I struggle with a motion trigger? The condition is that there are no events for a period of time for a bunch of devices. How do I set a trigger in such a situation? And I think you gents have taught me that a trigger is required in RM4.

So, tonight I guess I’m going to try....

Trigger: its 830pm

Condition: all motions are inactivate
Action: set mode to Asleep (wait 25 mins then cancel)
Restriction: Mode is Evening

Whadya think? Thanks guys for all the help.

just do the trigger like i posted above, but omit the time trigger. then it will put the house into sleep mode when there is no motion for 25 min.

I’d also add the condtion that the house is already in evening mode.

Trigger: motion sensors changed
run actions:
if motion sensors inactive AND mode is evening
THEN
set mode to sleep after delay 25min
ENDIF

Ryan, this is the concept that I’m getting hung up on. The conditional for my use case is “bunch o’ devices do nothing”. So triggering with “bunch of devices change” (which I understand is your advice) seems like inconsistent logic. At least this is where I’m getting confused. You’re suggesting I trigger when the motion sensor does something (activate or disactivate). But what if the sensors remain dormant all evening? In such a situation, I still want the house to go to sleep if the sensors remain event-less for an extended period of time.

What am I missing?

Is this effectively the same as a restriction of Mode=Evening?

Is this actually correct? The trigger will fire if the sensors change to inactive, right? If they remain inactive, the sensors won't fire. That's what I'm worried about.

Or maybe I'm looking at it the wrong way? I find the concept of a "change" to a motion sensor to be incongruent with the search for a prolonged period of no-change. See where I'm getting caught up?

You're assuming that motion is a trigger. What you aren't hearing is that that is incorrect. Whenever the motion sensor changes (active to inactive or inactive to active) is an "event". You can have an event going active or and event of the sensor going inactive. There is a lack of events for 25 mins....but that isn't the trigger. You can't trigger off the lack of something. You have to trigger off an event. That's how hubitat works.

Exactly....that is a condition, not a trigger. The trigger in this case is a motion sensor going inactive. That's when the 25 min timer starts.

And FYI.....that's always what webcore does. Webcore just does it in the background without you having to do the legwork. The exact same function is happening here.

WRONG!!!! This is 100% wrong. Nothing triggers after the 25 min timeout because there are no events. Events are devices doing something or a particular time of day or the mode changing. You can't have a trigger that is the lack of something. That's not how HE works.

But ultimately, if you want it to work, do it the way we are saying. Even if you don't understand why, that is what you have to do.

I'll give it a go, just for grins.

Let's say you have a door. The door can be open, or it can be closed. There aren't any other states for the door -- i.e. no 1/2 way open, or ajar, or slammed shut. Just open and closed.

You want to have something happens when the door opens, and something else to happen when the door closes.

The door isn't actually doing anything. It's either open, or it's closed. Some external actor causes the door state to change: you opened it, someone else closed it, a hurricane blew it open, an explosion blew it shut. The stuff you want to have happen doesn't care how the state of the door changed, but only that it has. When the door opens, some stuff happens. Then the state of the door is static and nothing more happens until the state of the door changes again. You can wag the door back and forth all you want, but it's still open so nothing new happens. When you close the door, then the state changes and other stuff happens because that condition is triggered.

So you could write this as just one condition that the door state has changed, along with an if statement to see what the state of the door is.
TRIGGER: Door state changes (something acted on the door)
ACTION:
IF the door is closed, do some stuff
ELSE (if the door is open), do other stuff

Motion sensors also have two states: they can be active or inactive. Everything I said about the two door states also applies to the two motion sensor states. The motion sensor will be active when motion happens, and the motion sensor state will change to inactive when that motion ceases. Its state is static until something changes it. In the case of "inactive," that something is its internal programming that says, "Oh, hey... no motion for xx time so now I'm inactive." So even though we think of "inactive" as being "nothing is happening," there's actually something that does happen to cause that state change.

So, let's say you want some stuff to happen when the motion sensor is active, and other stuff to happen when the motion sensor is inactive. Borrowing from the door above:
TRIGGER: Motion sensor state changes
ACTION:
IF motion sensor is inactive, do some stuff
ELSE (motion sensor is active), do some other stuff

Maybe you want to delay that stuff, for some period of time like 25 minutes. The trigger will still be that the motion sensor state has changed.

TRIGGER: Motion sensor state changes
ACTION:
IF motion sensor is inactive, wait 25 minutes and then do some stuff
ELSE (motion sensor is active), cancel any wait that might be remaining from the last time the motion sensor state changed, then do some other stuff.

You can make the IF statement include as many other conditions that you need for your particular use case. But the trigger is still that the state changed.

Did this help?

Newer versions of Rule Machine make it possible for you to cram a bunch of stuff into one rule, but maybe your situation--and the triggers behind it--would be easier to understand with multiple rules. (Though if you're having trouble with triggers, webCoRE, if that's what you were using, creates these for you automatically--look at the lightning bolts in the left column of the IDE. ) As people used to say in the early days, rules are free. :slight_smile: (Rule 3.0 introducted the actions section as an ordered script, along with one level of conditionals in actions. Rule 2.5 actions ran in a set order depending on action type and didn't necessarily allow accomplishing as much with one set of actions.)

How about something like this:

  1. Create a virtual switch, something like "Virtual Switch - All Motion Inactive for 25." The idea behind this switch is that it will turn on any time all specified motion sensors stay inactive for 25 minutes.

  2. Create one rule that actually makes that virtual switch work. Any of the motion sensors changing would be the trigger. The actions in pseudo-RM-speak would be something like IF all the sensors are inactive THEN turn on virtual switch <-- delay 25 min (cancel) ELSE Cancel Delayed Actions and turn off virtual switch END-IF.

  3. Create a second rule that actually changes the mode:

    • One possibility here is using the virtual switch turning on as a trigger. Then your actions might be something like:
      IF Mode is Evening AND Time After 8:30 PM THEN Set Mode to Asleep END-IF.
    • However, this won't help you if stays inactive for 25 minutes and it's before 8:30 PM but then becomes 8:30 PM with no motion having happened since. So perhaps you want to add the time becoming 8:30 PM or the virtual switch turning on as a trigger. Then your actions would need to be something like IF virtual switch on AND time after (or equals) 8:30 PM THEN set mode to asleep END-IF.

Step 3 is, as usual, where things get complicated. I'm sure you can think of the nuances of your situation and modify the logic appropriately, but I think removing the bunch of motion sensors and their delay from this rule might help quite a bit with making what's happening clearer to understand and easier to actually do.

Or if you want more of a challenge: the virtual switch is essentially acting as a boolean variable here. If you want to get rid of that device and keep everything in RM, you could use the first rule to set the private boolean (one gratis variable you get with every rule and can use for any purpose, often restricting when something runs) on the second rule. You could probably even combine that all into the same rule, using the private boolean of the same rule to track motion inactivity with motion sensors obviously added back as triggers but only setting the private boolean in the actions, but then you get back into overly-complicated-rule territory. (Oh, and if you keep the virtual device, you can use it in other automations--might be helpful if you can think of any other use for this outside of this timeframe and mode-change.)

1 Like

This. Good advice. Tonight I've setup the app as per the below with two restrictions (Mode=Evening, Time After 800pm). Props to you guys for helping the noob. Crossing my fingers this works tonight.

Okay, now let me try to better articulate my question. I get the difference between a trigger and a condition. And I understand why the above rule makes sense (although, now that I look at it, I wonder if leaving off an END IF screwed it up--easy fix).

Anyway, I'm concerned about an edge case. Imagine a situation where the kids are out all night doing god knows what, and my wife and I were in the bedroom early (where there are no motion sensors btw--guy's gotta have some privacy). Or, if you're delicate, you can image that an alien came to our house at 7pm local time and shot us all with a freeze spray that last like twelve hours. Whatever the hypothetical, there is no motion-activation and no motion-deactivation all night from 8pm on. Given there are no events, I would think the above rule would not fire all night since the trigger is never satisfied. As @Ryan780 says so clearly "you can't have a trigger that is the lack of something. That's not how HE works".

By contrast, in my old rule in ST, the house would still go to sleep in such a scenario just by virtue of the fact that there was no activity for a specified duration (btw, I used a simple routine for this, not even webcore). In ST, any extended period of no motion, the house went to sleep, independent of when the last activation or deactivation occurred.

I grant you this edge case is highly unusual. But I'm asking anyway to make sure my logic is accurate (I have many more rules to write, after all).

If I've already exhausted you with the question, you won't hurt my feelings one bit by giving up on me at this stage. I've probably earned it. :grimacing:

If your whole family was hit with a freeze ray at 7:00, and stayed frozen until after 8:00, nothing would trigger because the state of the motion sensors would not have changed.

Instead of using restrictions for Mode = Evening, you could add these into conditions:
Mode changed
Certain Time 8:00 PM

Then change your IF to

IF motion sensors all inactive
AND Mode is Evening THEN

That would trigger if the motions sensor states change, or mode changes, or the time is 8:00 PM, so a freeze ray at 7:00 would not preclude changing the mode to Asleep, but Asleep would only happen if it were already Evening.

Not sure what's triggering your Mode = Evening. Do you need both that and the 8:00 PM restriction? If you want mode to change to Asleep no matter what time of day it is (which is maybe how it worked in ST? Not sure), then leave your IF statement the way you have it already.

ETA: The missing END-IF won't break your rule, since it would be the last statement. But it's always best practice to have all IFs matched to an END-IF.

Guys, it worked, thanks to your help! And more importantly to me, you taught me a few things about RM4. Much appreciation and gratitude.

1 Like

Gotcha thanks

Mode=Evening is triggered by sunset as long as someone is home. In ST, once we were in Evening mode and it was past like 830pm or 8pm, then I had an ST routine that would wait until there were X continuous minutes of no motion across most of the house, then it would switch to Mode=Asleep. It worked really well! And it didn’t depend on any motion event occurring, just the continuous absence of events on top of inactive states.

But i now get that RM4 requires a trigger, so the logic doesn’t translate directly. What are you suggesting I use for the trigger?

Mode=Evening is triggered by sunset as long as someone is home. In ST, once we were in Evening mode and it was past like 830pm or 8pm, then I had an ST routine that would wait until there were X continuous minutes of no motion across most of the house, then it would switch to Mode=Asleep. It worked really well! And it didn’t depend on any motion event occurring, just the continuous absence of events on top of inactive states.

But i now get that RM4 requires a trigger, so the logic doesn’t translate directly. What are you suggesting I use for the trigger?

Not sure where you live, but around these parts it's not sunset until after 9:00 in the summer. :grin:

You said it's working now. I'd love to see what you ended up with.

LOL fair point. The logic in ST was always Sunset (aka, Mode=Evening) OR 830pm. That way we were covered either way. But that's probably just detail.

Here ya go....it's worked every night since you guys guided me. Mega props!

2 Likes