Lock Automation Help

So i feel like this should be an easy fix, but i just cant rap my brain around it.

What im trying to do, is set up an automation that will unlock my door as soon as Unifi detects that im on the wifi, aka Home. But I only want it to unlock if iv been away from “home” for 10 mins or longer

Original working code

- id: '1526693475723'
  alias: Lock - Unlock when i get home 8p-3a
  trigger:
  - entity_id: device_tracker.preston_phone
    platform: state
    to: home
  condition:
  - after: '20:00:00'
    before: 03:00:00
    condition: time
  action:
  - data:
      entity_id: lock.front_door_2
    service: lock.unlock

So I know there should be a from/to somwheres in there, but I cant figure out where

for:
  minutes: 10
from: away
platform: state
to: home

Probably something like this:

condition:
  condition: template
  value_template: >
    {{ (as_timestamp(now()) - as_timestamp(trigger.from_state.last_changed)) > 10 * 60 }}

And to format the whole automation more nicely:

- id: '1526693475723'
  alias: Lock - Unlock when i get home 8p-3a
  trigger:
  - platform: state  
    entity_id: device_tracker.preston_phone
    to: home
  condition:
  - condition: template
    value_template: >
      {{ (as_timestamp(now()) - as_timestamp(trigger.from_state.last_changed)) > 10 * 60 }}
  - condition: time
    after: '20:00:00'
    before: '03:00:00'
  action:
  - service: lock.unlock
    entity_id: lock.front_door_2

Thanks guys, will give it a try!