Notification leaving any zone when been there for X minutes

Hi guys,

I want to receive a notification when a device_tracker was for X minutes in any zone (but home and opvang) and leaves it.

Notification should contain something like this:

Hi Leon, person Y is leaving zone Z and is probably coming home.

(person Y was thus at least for X minutes in zone Z).

I’ve got this now, but testing is hard and is this the right way?

alias: Location | Person Y verlaat zone Z
description: ''
trigger:
  - platform: state
    entity_id:
      - device_tracker.other_phone
    to: not_home
condition:
  - condition: not
    conditions:
      - condition: zone
        entity_id: person.Y
        zone: zone.home
      - condition: zone
        entity_id: person.Y
        zone: zone.opvang
  - condition: not
    conditions:
      - condition: state
        entity_id: device_tracker.other_phone
        state: home
        for:
          hours: 0
          minutes: 5
          seconds: 0
      - condition: state
        entity_id: device_tracker.other_phone
        state: not_home
        for:
          hours: 0
          minutes: 5
          seconds: 0
action:
  - service: notify.mobile_app_phone
    data:
      message: X vertrekt van {{ trigger.from_state.state }}
      title: X onderweg
      data:
        group: home-assistant-notification
        priority: high
        ttl: 0
mode: single

When the trigger triggers the conditions have to be meet right away or the automation is “lost”.
Your conditions with minutes means it is probably impossible (haven’t looked very closely) but I would assume so.

The conditions with minutes has to become the trigger some how.

Fixed my own solution!

2 automations and 1 helper, for those who wants it:

Helper:
input_boolean.personXisonLocationFor5Minutes

Automation to set boolean:

alias: >-
  Set boolean when X is in a zone (not home) for 5 minutes
description: ''
trigger:
  - platform: state
    entity_id:
      - person.X
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: person.X
        state: home
      - condition: state
        entity_id: person.X
        state: not_home
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.personXisonLocationFor5Minutes
mode: single

Automation to send a message when person X leaves the zone (and thus been there for 5 minutes)

alias: Location | Person X leaves zone
description: ''
trigger:
  - platform: state
    entity_id:
      - person.X
    to: not_home
condition:
  - condition: state
    entity_id: input_boolean.personXisonLocationFor5Minutes
    state: 'on'
action:
  - service: notify.Y
    data:
      message: X leaves zone {{ trigger.from_state.state }}
      title: X is on underway!
      data:
        group: home-assistant-notification
        priority: high
        ttl: 0
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.personXisonLocationFor5Minutes
mode: single