Unexpected Behavior: Multiple sticky triggers in RM5.1

I'm trying to trigger a warning to occur if a door is left open for 4 minutes, and again if it is still open after 8 minutes. In RM4 I had two rules, one for each case duration, using the old-school pattern of triggering on the contact changed event, then in the OPEN case using delayed events for the warning, and in the CLOSED case cancelling delayed events. Both rules have EXACTLY the same structure except for the length of the delay.

These rules are much cleaner using Sticky Triggers: the four-minute version would look like:

Trigger Events:

  • Master Bedroom door open and stays that way for 0:04:00

Actions:

  • Notify My Phone: %device% left open since %time% (at %now%)
  • speak('Quick! Close the Master Bedroom door before the cat gets here!', 100, 'Marlene') on Master Bedroom Speaker

This works really well. If the door is left open, the warning happens, and if it is closed within 4 minutes, nothing happens (in the logs it shows the Sticky Trigger failing when the door closes, as expected).

Next, I thought I would combine both rules into one, since the only difference is the duration of the Sticky Trigger:

Trigger Events:

  • Master Bedroom door open and stays that way for 0:04:00
  • Master Bedroom door open and stays that way for 0:08:00

Actions:

  • Notify My Phone: %device% left open since %time% (at %now%)
  • speak('Quick! Close the Master Bedroom door before the cat gets here!', 100, 'Marlene') on Master Bedroom Speaker

Now, I start getting warnings at 8 minutes, even if the door is already closed at 8 minutes. Am I misunderstanding the semantics of two stick triggers? I assumed that the triggers would run independently, so if the door is open for 1 minute I get no warning; if it is open for 7 minutes, I get a warning at 4 minutes, and if it is open for 10 minutes, I get two warning, at 4 minutes and again at 8.)

[quote="jmason888, post:1, topic:91454, full:true"]
I'm trying to trigger a warning to occur if a door is left open for 4 minutes, and again if it is still open after 8 minutes. In RM4 I had two rules, one for each case duration, using the old-school pattern of triggering on the contact changed event, then in the OPEN case using delayed events for the warning, and in the CLOSED case cancelling delayed events. Both rules have EXACTLY the same structure except for the length of the delay.

These rules are much cleaner using Sticky Triggers: the four-minute version would look like:

Trigger Events:

  • Master Bedroom door open and stays that way for 0:04:00

Actions:

  • Notify My Phone: %device% left open since %time% (at %now%)
  • speak('Quick! Close the Master Bedroom door before the cat gets here!', 100, 'Marlene') on Master Bedroom Speaker

This works really well. If the door is left open, the warning happens, and if it is closed within 4 minutes, nothing happens (in the logs it shows the Sticky Trigger failing when the door closes, as expected).

Next, I thought I would combine both rules into one, since the only difference is the duration of the Sticky Trigger:

Trigger Events:

  • Master Bedroom door open and stays that way for 0:04:00
  • Master Bedroom door open and stays that way for 0:08:00

Actions:

  • Notify My Phone: %device% left open since %time% (at %now%)
  • speak('Quick! Close the Master Bedroom door before the cat gets here!', 100, 'Marlene') on Master Bedroom Speaker

Now, I start getting warnings at 8 minutes, even if the door is already closed at 8 minutes. Am I misunderstanding the semantics of two stick triggers? I assumed that the triggers would run independently, so if the door is open for 1 minute I get no warning; if it is open for 7 minutes, I get a warning at 4 minutes, and if it is open for 10 minutes, I get two warning, at 4 minutes and again at 8.)

(In connection with Feature Request: RM5.1 Time Since Event exceedds %some_variable%, if there is a way to add a variable to Time Since Event, this feature also has exactly the same setup.)

Here are some logs. In these logs, I am running both versions (one trigger and two triggers) for comparison. I am not running the version with a single 8 minute sticky trigger, as I would expect it to work like the 4-minute version.

  1. Rule 1 (app 1372) is the one with only one sticky trigger:
    • Master Bedroom door open and stays that way for 0:04:00
  2. Rule 2 (app 1594) is the one with two stick triggers:
    • Master Bedroom door open and stays that way for 0:04:00
    • Master Bedroom door open and stays that way for 0:08:00

Scenario 1: I close the door quickly (less than 4 minutes):

Rule 1

As expected, does not trigger.

Rule 2

Triggers at 8 minutes, even though the door is closed.


Scenario 2: I close the door after 4 minutes (but before 8 minutes):

Rule 1

As expected, triggers at 4 minutes.

Rule 2

Does not trigger at 4 minutes, even though the first sticky trigger should have fired.
Triggers at 8 minutes, even though the door is closed.


Scenario 3: I keep the door open longer than 8 minutes:

Rule 1

As expected, triggers at 4 minutes.

Rule 2

Does not trigger at 4 minutes, even though the first sticky trigger should have fired.
Does triggers at 8 minutes, as expected because of the second sticky trigger.


For now, I'm happy running two identical rules: one with a 4-minute sticky trigger and another with an 8-minute sticky trigger. This is already WAY cleaner than what I previously had using delayed events and canceling them. But I am curious what the expected semantics are for a rule with multiple sticky triggers (on the same device). If these could be combined into a single rule like Rule 2 above, that would be even nicer.

It seems to me that when you have 2 triggers, they are OR triggers (any one of the triggers can start the rule). So with your 2-trigger rule, when your first trigger fires at 4 minutes, the actions run and then the entire rule is done, finished. Thus I feel that it shouldn't be possible for the 8 minute trigger to ever fire, since it is the same sensor but for a longer "stay" time.

I tried this with a light staying on and as expected I could not get the 2nd trigger to execute. However you have indicated the opposite, that the 2nd trigger is indeed running, even when it shouldn't. That part is a mystery to me and I could not reproduce.

That's what's happening, but even weirder. The 8-minute trigger ALWAYS fires, even if the door has been closed (and thus it didn't "stay open" for 8 minutes), The 4-minute trigger NEVER fires, regardless of whether the door has been closed.

But there are plenty of cases where two triggers (OR triggers) start a rule and both fire. For example, if one trigger was for sunset, and one was for 10pm, the rule would fire twice: once at sunset and another at 10pm. So I don't think the "rule is done" logic applies either (since it's a trigger, not a wait-for).

I am pretty excited about the new rule machine sticky trigger capability and tried using it to warn me when doors have been left open for 5 minutes (was doing in "notifications" app but wanted to give this a go). However despite the rule being very simple, I have been notified incorrectly but unpredictably several times (such as this morning for 2 doors that were quickly opened and closed, not left open for 5 minutes). Once I can reliably reproduce the situation, I will post details for the devs. Essentially I think the new functionality still has some bugs to work out.

I believe your time-based "OR" triggers is a bit different scenario and it does make sense to me, in theory, that it could run at Sunset and then again at 10pm. I have a sense in my head of this but it is hard to describe. But I will try haha.

Sunset/10pm example:

  • Sunset arrives, actions run.
  • Rule is finished.
  • Now rule starts over and goes back to waiting for either:
    • Sunset
    • or 10pm
  • 10pm arrives: actions run.

Door example:

  • Door opens and stays open for 4 minutes, so action runs
  • Rule is finished.
  • Now rule starts over and goes back to waiting for either:
    • the door to go from closed to open, and stay open for 4 minutes
    • or to go from closed to open and stay open for 8 minutes
  • If door has remained open this whole time: nothing will fire anymore.
  • If door was closed and then again re-open and left open, in time, the 4-minute trigger fires.

The difference being, Sunset and 10pm are independent events, but door staying open for 4 minutes is a subset of door staying open for 8 minutes, and will always fire before ever reaching the 8-minute trigger.

This should never work as intended.

I think what you want is the initial trigger, and a Wait to catch the second case that it stays open longer.

Is that because both triggers are from the same subscription? So

  • Master Bedroom door open and stays that way for 0:04:00
  • Closet door open and stays that way for 0:08:00

might work (not that I'd want to do that; just figuring out what the intended semantics are).

The wait is an interesting idea; right now, I just have another rule for "Master Bedroom door open and stays that way for 0:08:00" that simply does a Run Actions on the first rule...