Trigger on Presence, only if away for x minutes?

Hi all,

New ST convert here, and i'm loving the new platform!

I'm working on migrating all my automations over. I'm curious how i can set up a presence trigger for arrival, but have it run only if the device has been away for more than 5 minutes.

I started working down the route of using a Global Variable, and setting it to "now()" when i leave, but i'm stuck figuring out how to do the comparison of that variable to "now()" again when i arrive back. I've thought about making another rule to update another variable every minute and comparing against that, but that's not ideal since it 1) adds something that has to fire every minute on the hub, and 2) won't be directly in sync with when i leave.

What's the best way to compare against the last state change like this? I'll need this ability for another rule soon too, wherein i need to detect if a door is closed within 20 seconds of it being opened.

Any pointers will be much appreciated.

I would do this instead based on Mode. If you set up your Arriving home automation to only run when you are Away mode, then you don't have to worry about the timeout.

However, if you truly want to do the time comparison, you can compute the difference of the two times by capturing one variable at each of the events. You want to set the value of the variable to be Time in Seconds.

I stuffed them both into the same rule to demonstrate:

You can see that the difference between the two is 20.

Thanks, this gives me something to think about with the open/close scenario i have to tackle next.

For the away timer, i ended up going with a virtual presence sensor that gets set to departed 5 minutes after the phone leaves, and everything else triggers off the virtual sensor.