Combine door & motion sensor to determine coming home/going away


I have a door sensor (zigbee) and a motion sensor (zigbee) in my hallway.
I have an automation configured so that when the door is opened, I check if there was no motion the past 2 minutes (from another topic here on the forum). If no motion detected, I assume someone is coming in and turn on the lights.

But the issue is that sometimes this doesn’t work and my guess is that both sensors trigger at the same time, which causes motion to be detected in the last 2 minutes and the actions are not executed.

I checked the logs and both sensors trigger at the same moment. Any idea how to solve this issue?

Of course I don’t want this automation to fire when someone is leaving (first motion is detected and then the door opens)

I would add both sensors as triggers and conditions that both sensors are active. It’s doubtful they triggered at the exact same time (probably at least some microseconds/seconds apart). Add both as triggers and conditions will make sure that the rule doesn’t execute the actions unless both are active and will re-run the run whenever the second sensor triggers.

Can you explain a bit on how to define them both as triggers & conditions? (I know how to create triggers & conditions) but I don’t understand what you are trying to say.

I misread your requirements and was talking about setting it up for the opposite way (heading out).

One though would be to check how long it’s been since the motion sensor was triggered, but I’m honestly not sure how to add that to the automation…maybe a template. You’d have to really nail that down though through some testing (e.g. figuring out that if you head straight for the door, there’s 5 seconds between motion going active and the contact opening, but coming in the door is a gap of 2 seconds).

Second thought would be to adjust the motion sensor so that there will always be a delay when walking in (even if it’s something like 1 second) before it goes active when entering the door.

The whole thing is that you’ve got a race condition (as you’ve figured out). The solution will be to make sure that there’s always a way to run the rule before the motion sensor is considered active (both proposals above would add this gap).

I relocated the motion sensor so there is a bigger gap between door sensor & motion sensor when coming in. This seems to do the trick. Thx for the advice!

1 Like