Back door notification if left open for longer than 45 seconds [SOLVED]

Here is what I want to do in words:

Back door opens. Rule waits 45 seconds. After 45 seconds it evaluates whether door is still open. If it is it sends a notification to me and my wife and then announces it to nearby Echos so somebody will close the door.

If the open notification was sent then when the door closes, let everybody know via notification and announcement on Echos that the door was successfully closed.

If the door opens and closes in that 45 seconds nothing at all should happen.

With the rule attached it seems to now always announce the door open and the door closed even though it worked for the first few times I tested it.

Open notification is a local variable.

What can I change to make this better?

I would do it in the notifications app if it's feasible and not rule machine.

You could use the notification app but this will not announce when the door is closed but can be set to keep notifying you until the door is closed.

If you wan to keep the current rule you don't need the variable or the second if statement.
The wait for condition and notification can be right after the first notification as you only wan these to run when you leave the door open.

1 Like

@at9 beat me to it while I was typing, but I think you'll also want to check the "Cancel?" flag on your "Delay" action as well as place a "Cancel Delayed Actions" action first thing in your actions. The end result would be much simpler, something like:

Trigger: Door opened

Cancel Delayed Actions
Delay 0:00:45 (cancelable)
Notify phones: "Back door is open!"
Wait for event: Door closed
Notify phones: "Back door is closed"

In case you are wondering, delays only get cancelled with explicit cancellation; in-progress "Waits" are effectively cancelled any time a trigger matches, so you don't need to worry about that here.

[EDIT: I did not think through this clearly, and as-written this will fail in the way he mentions in the next post. Hence the strike-through....]

The way you wrote this rule hints to me that maybe you've seen lots of people talk about the "new" suggestion for writing rules like the above and were trying to follow it. I might assume you were trying to "translate" a rule like this:

Trigger: Door changed


IF (Door open) THEN
  Delay 0:00:45 (cancelable)
  Notify "Back door open!"
  Set Private Boolean to True
  Cancel Delayed Actions
  IF (Private Boolean is true) THEN
    Notify "Back door closed!"
    Set Private Boolean to false

Here, you can use Private Boolean (or a local or global variable as it appears you were doing--but no need to if you don't care about its value anywhere else) to "track" whether the notification was sent. This isn't the "new" paradigm" you may have seen, but it's easier for me to wrap my head around still in most cases, as you can see with my above attempt. Trying to re-train myself... :slight_smile:

EDIT: I think the "old" way might still be the best way to write this rule, but this is what I came up with if you want to use an event-specific trigger with a "Wait":

Trigger: Door closed


Cancel Delayed Actions
IF (Private Boolean is False) THEN
  Notify: "Door closed!"
  Set Private Boolean True
Wait for events: Door opened
Delay 0:00:45 (cancelable)
Notify: "Door opened!"
Set Private Boolean False

Not much "simpler," but maybe a little? :grimacing: (Also, wait for someone to check my logic here. Haha.)


Is that first rule right?
Won't it always notify you that the door was opened after 45 seconds even if it is closed as you would need to open the door again to cancel the delayed actions?

This what I was suggesting

1 Like

You're right--oops! (The "re-training myself" thing is quite real. :slight_smile: )

Technically, however, a rule like the above doesn't really check that the door stayed open for 45 seconds, either--just that it happens to be open 45 seconds after any instance in which it was opened (e.g., even if it was opened, closed 30 seconds later, and opened 10 seconds after that...then you'd get a notification after 5 seconds). I think adding a "Cancel Delayed Actions" and making the delay "cancelable" would address that.

This is one place where I really like the "old" style better...haha.

(EDIT: I edited my post above to suggest something else with the "Wait"-style actions...not sure if it's actually better...)

1 Like

Good point this does I think.

I tend to agree


Logic? What is that word that you speak?

1 Like

Thanks for all the input! It makes things clearer. I'm not following any new or old way of writing things. I used to program Crestron Automation controllers 20 years ago, so am probably a little stuck in SIMPL-C workflow.

It works! Thank you so much for the guidance.

1 Like

The built in notification app is designed for this perfectly, no need to specify using rules, I use this for my doors. Check it out below. Notice the "stop repeat upon next event" means when the sensor closes

No, that will not send a notification when the state that initiated the first notification is no longer true. Specifically, for this case: it can be used to notify you--either once on a repeating basis--when the door is opened, but won't also notify you when it gets closed after that. This was a specific requirement by the OP and the reason a rule was suggested.

But your idea is certainly a good one: use the built-in apps whenever they meet your needs. :slight_smile:

Yes, I had the same requirement and I just created a second(separate) notification to tell me when the door is opened and closed

How do you restrict it so that the "closed" notification happens only if it was open long enough for the "stayed open" notification to happen? (A notification for both is certainly possible, but none of us above were above to think of a way to accommodate this aspect of the poster's requirement with the Notifications app.)

Like this, it works every time.

The "Delay 0:02:00" should match the amount of time you have for the notification time of the door being open "for how long (minutes)"

So you used a rule like we suggested above instead of the Notifcations app? :slight_smile: The issue the OP presented has already been solved, and again while I agree that using the built-in apps is a good place to start, they didn't meet this particular requirement, hence why we suggested what we did. Just curious if you found something we didn't.

Also, I would suggest re-writing your rule to follow one of the above suggestions. As written, your rule doesn't really check if the door stays open for 2 minutes, just whether it happens to be open (either still open or opened again) 2 minutes after any time it is opened. The above should cover that, too.

1 Like

I use the notification app for the door being open as I posted a week ago, and then an RM rule that I just posted for it being closed, I didnt know it was resolved though or I wouldn't have posted. Thanks

Also my original post is how to get it to repeat the notification until it closes

I do mine this way and it notifies every 5 mins till someone closes the door