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