Two events within a given timeframe as rule trigger

I did not find a rule example nor do I have the background or experience to write this kind of rule from scratch on my own, but I am sure there is someone out there with the right ideas.

I have a Contact (sensative strips) Sensor which provides Door Open/Close information on my Front Door. In addition, I have a Nuki Smart Lock on the same FrontDoor which provides information on the Lock State incl. “Unlatch”.
It is a natural thing, that some time after Unlatch, the Contact will send Open when the door slowly opens. When this occures within a couple of seconds I exactly know, that someone is coming from outside to inside entering the house and then I could handle this event to trigger a specific (arrival) rule.

On the other hand, if only a Contact Open is registered without Unlatch before, I know someone is opening the door from inside and can handle this kind of event differently.

But how do I define one event depending on two item status changes within a certain timeframe?

One could say I can only trigger on unlatch which should be sufficient to detect arrival, but it’s not to cover the case someone opening the door from inside because the system doesn’t know then that the following Contact Open is due to someone entering the house and would trigger the same rule as Contact Open from inside.

Any ideas are appreciated, maybe there is already a threat covering this kind of requirement?


You need a couple of rules. One that triggers by one event and one triggered by the other.

Set a global var with now in each rule.

Then when the Contact changes to OPEN check the car for the Unlatch event and if it is soon after you have your someone came home.

contactTime = now
if(unlatchTime.isAfter(now.minusSeconds(10)) {
    // Someone came home
else {
   // Someone leaving