Rule Machine 4 - Cancel Delayed Actions

I am trying to figure out why this RM4 rule is not working the way I want it. Basically, I want to alert if any door left unlocked for over 10 minutes, but only between the times of 10pm and Sunrise.

There are two problems I am running into:

  1. If the door is already unlocked at 10pm, then the change trigger doesn't cause the condition to alert since there is no change.

  2. The cancel delayed actions is not cancelling the alert to my phone if the door is locked again within 10 minutes.

Any help would be appreciated.

For #1, you need to add a trigger @10pm.

1 Like

Awesome thanks! Updated.

That seems like it should work just fine. My only issue now is that when it does get locked within my 10 minute threshold, I would like to to cancel the alert.

I think you would want to change the trigger event to a certain time like napalmcsr said above.

If your door locks don't change or unlock at 10 PM, the flow won't run. The way you have it now, it will look for the door lock to lock and unlock. Only if it is 10 PM and the lock is active right then, it will lock the door and send a message.

I also would advise putting delays in the door lock locking event. If these are Z-wave, it will probably tie up the Z-wave radio, or cause a lockup if you send that many events at once. There are may reports of this on this board. I would start with a 5 second delay between lock events and see what happens.

You shouldn’t need the unlocked trigger, but you still need a trigger at 10pm.
I would suggest turning on action logging to try to discover why it isn’t canceling delayed actions.

Maybe that has to do with the trigger being "lock changed"? It is going to try and run the flow every time the lock is used. It shouldn't send a message unless it is 10 PM though.

Consider a situation where you have more than one door unlocked at the same time, then partially fix the situation by locking only one of them. Your "Cancel Delayed Actions" action will run only if all of them are locked. This could cause a built-up of delayed notifications your trigger fires any time any are locked are unlocked (you don't need both "changed" and "unlocked" as triggers, by the way; the former assumes the latter, but you may need to add a specific time if you care about already being unlocked at 10) since they wouldn't be cancelled for a specific door if another causes it to not meet the conditions for your ELSE (effectively "all locked," the boolean opposite of "any unlocked").

I'm not sure how you're testing the rule, but the above is certainly possible. As suggested, logging may help narrow down the issue. If this is indeed what's going on, one way to solve it is by using three separate IFs, each with their own ELSE and cancel, one for each lock.

Thanks for the feedback. I will see if I can narrow this down with the logging.

When you say I need a trigger at 10pm, but not an unlock trigger. Can you clarify what type of trigger it should be?

You want "Certain Time". From there you can set whatever time or times you want.

Delete the unlock triggers completely in the top half. Those are only needed in the bottom section "Actions".

My similar version

So far so good. I kept the unlocked triggers in place as I want it to alert if I forget to lock a door even after 10pm, not just at 10pm.

Your rule actions run only when a trigger fires, so I would suggest a small change. As an example of where this matters: let's say it's after 10 PM and you unlock your front door (and all the rest are, let's say, locked). That event matches your trigger, so your rule actions will run. The IF block with "Front Door Unlocked" will evaluate to True, so you'll get a notification action scheduled, subject to cancellation, for 10 minutes from now. Then you lock your front door within those 10 minutes. Now nothing happens with your rule because that event (Front Door locked) does not match a trigger. You're undoubtedly expecting the ELSE to run, but it won't--it never even gets a chance to evaluate itself. Therefore, you'll get a notification 10 minutes after you unlock the door, even if you lock it after. The solution is to change the "unlocked" trigger to "changed" so your rule actions run whenever the lock changes to or from "locked" or "unlocked."

tl;dr: change the "unlocked" triggers to "changed" but read above if you want to see why :slight_smile:

Thank you. I was using changed as a trigger originally. My hope was only to have this run initially when the door was unlocked, not on every event. Could I also just add a trigger for 'Front Door Locked'? I assume I would then put that above the 'Cancel Delayed Actions'. Am I off base here?

Do you mean that you only want it to notify you the first time the lock is unlocked after 10 PM and then not again until the next day? That is do-able, but you'll need to add something to make that happen. Otherwise, if "not on every event" you just mean that you only want it to notify you on unlocks and not on locks, that's already what you're doing: a trigger event firing won't cause all of your actions to run. The actions section will run, but if you have IFs, as you do, only those parts that match the conditions on your IFs will execute at that time (that's why conditionals are so awesome).

Triggers (the first gray box above) are defined in an entirely separate input from actions (the second gray box above), so I'm not sure what you mean with adding a trigger directly above a specific action. You could certainly add a "Front door locked" trigger, but if you already have a "Front door *changed*" trigger (as I suggested), there's no sense in doing so because the latter includes the former. If you leave "Front door unlocked" and add "Front door locked" as an additional trigger, you could certainly do that too, but then it's logically equivalent to "Front door *changed*", so you might as well use that. (Or perhaps you're concerned that "changed" means any event on the device at all, like battery level reports. Never fear: if you choose the "Lock" capability as the trigger capability--you always have to choose some capability here--Rule Machine will only look for locked or unlocked events, or both if you choose "changed", not literally anything the device reports.)

I'm still not sure what you mean with adding a trigger to your actions or what the goal is, so feel free to explain a bit more what you want to accomplish if this isn't what you mean.

Seems like this would be a lot easier to accomplish using the Notifications app:

I agree, but the only thing that can't do is a check at 10 PM to see if anything is currently unlocked (that will just handle the rest of what this rule does: notifying you after 10 PM if/when something is unlocked).

That being said, you could certainly take a hybrid approach: use the Notifications app for this, then still keep your 10 PM trigger and just check the locks then in the rule. That would definitely keep the rule simpler (though I'm still not sure what the goal is with the last request).

1 Like

Thank you both. I will try the changed trigger per your suggestion. I think I see what you are saying. Right now the rule is working, but it is never cancelling since my trigger will only cause the IF statement to run, not the ELSE.