Unlock automation

I’m newish to HA and am trying to wrap my head around how I should write a pretty simple automation. The use case is that we have a smart lock on the backdoor. I want to write an automation where if a person goes from not home to home, and a motion sensor in the garage is triggered within, say, three minutes of that, the backdoor unlocks.

I’m not clear on the timer piece–I understand how to build an automation that triggers when someone comes home, but not how to incorporate the three minutes timer that starts on arrival. I could see making a new sensor that tracks how long someone has been home, and using that; is that the right way to handle?

Thanks for any help!

There are often several ways to do things in HA. Your way should work.

Another is to use a condition that checks whether the person is home (using a state condition) and a second clause (using a template condition) to check that the last_changed attribute changed not more than 3 min ago. You can inspect this value by looking at your entity in the developer tools. Note that you can’t access that special “attribute” via the state_attr function but rather using the fully qualified dot notation.

Another is to start a timer when the person arrives home and check that the timer is active in your automation. Just keep in kind that timers don’t survive restarts, but that’s probably not an issue in this case.

All of the above kind of assumes your trigger is the motion sensor and everything else are just checks and actions.

Yet another way is to trigger based on the arrival. Under your actions, you can then use a wait_for_trigger with a timeout. If it happens, unlock, otherwise (if it times out), do nothing.