Use Trigger Entity in Automation

Hi, could someone please advice me what I am doing wrong, I would like to open my lock when someone comes to home, but to prevent locking and unlocking when someone briefly exit the area I added there condition that the person which entered must be out of the zone for more than 5 mins.

This is my configuration:

alias: Zámek - odemceni
description: ""
trigger:
  - platform: zone
    entity_id: person.jakub_znamenacek, person.petra_dobesova
    zone: zone.home
    event: enter
    alias: Kdokoli přijde domu
condition:
  - condition: not
    conditions:
      - condition: device
        device_id: ac774d802e9175e95c72fcd8928258b5
        domain: lock
        entity_id: 750b08f8153246abb8d20a30393324d6
        type: is_unlocked
    alias: Zámek je zamčený
  - condition: state
    entity_id: trigger.entity_id
    state: not_home
    for:
      hours: 0
      minutes: 5
      seconds: 0
    alias: Ověř, že ten kdo se vrátil byl mimo domov více než 5 min
action:
  - service: lock.unlock
    data: {}
    target:
      entity_id: lock.zamek_chodba
  - service: notify.all_mobile_devices
    data:
      title: Automatické odemknutí zámku
      message: Došlo k automatickému odemčení zámku vchodových dveří po příchodu domů.
mode: single

And this is what I see in logs:

Basicaly it says that the person was not out for more than 5 mins. Any help will be appreciated.

You might need a second automation for when someone leaves/enters a zone, your primary trigger is when someone enters the Home zone with conditions that do everything else. Alternatively you could set your trigger to be whenever someone enters or leaves a zone so that the rest of the automation is executed. At the very least you can add an automation to test that entering and exiting the zone for 5 minutes is functional, I know I’ve had hit-and-miss results with realtime zones.

You could also add a condition that waits for 5 minutes to trigger re-entry with commands to execute on failure.

Your condition is set to not_home for 5 minutes,
so if this automatition is triggered, somebody has to be away for 5 minutes to execute actions.

You can make a trigger on the person not home for x minutes…

Trigger on zone entering
Tringger on status not_home for 5 minutes.

Using id’s for the action to take.

Just build a little example:

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - person.marc
    to: not_home
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: Not_home for 5 minutes
  - platform: zone
    entity_id: person.marc
    zone: zone.home
    event: enter
    id: Entering_Zone
condition: []
action:
  - if:
      - condition: trigger
        id:
          - Entering_Zone
    then:
      - type: turn_on
        device_id: 6986284481792364423449745f61a30a
        entity_id: 4b4d7ab2d2b1ad2d63efd3f89398e5ba
        domain: light
  - if:
      - condition: trigger
        id:
          - Not_home for 5 minutes
    then:
      - type: turn_off
        device_id: 6986284481792364423449745f61a30a
        entity_id: 4b4d7ab2d2b1ad2d63efd3f89398e5ba
        domain: light

What you propose will cause 5 min delay before the action is executed. I just want to prevent accidental triggeres when I am around my house and I enter and exit the home zone.

I think something like this should work:

alias: Zámek - odemceni
description: ""
trigger:
  - platform: zone
    entity_id: person.jakub_znamenacek, person.petra_dobesova
    zone: zone.home
    event: enter
    alias: Kdokoli přijde domu
condition:
  - condition: not
    conditions:
      - condition: device
        device_id: ac774d802e9175e95c72fcd8928258b5
        domain: lock
        entity_id: 750b08f8153246abb8d20a30393324d6
        type: is_unlocked
    alias: Zámek je zamčený
  - condition: state
    entity_id: "{{trigger.entity_id}}"
    state: not_home
    for:
      hours: 0
      minutes: 5
      seconds: 0
    alias: Ověř, že ten kdo se vrátil byl mimo domov více než 5 min
action:
  - service: lock.unlock
    data: {}
    target:
      entity_id: lock.zamek_chodba
  - service: notify.all_mobile_devices
    data:
      title: Automatické odemknutí zámku
      message: Došlo k automatickému odemčení zámku vchodových dveří po příchodu domů.
mode: single

but for some reason it does not accept the entity_id: "{{trigger.entity_id}}" it says Entity {{trigger.entity_id}} is neither a valid entity ID nor a valid UUID for dictionary value. They use the trigger.entity_id this way even on offitial HA documentation pages

What you do here is trigger when somebody enters the zone home, and the condition has to be not_home for 5 minutes .

So this would not work in any way.

My suggestion does not cause a 5 minute delay. It triggers on the state not_home set for 5 minutes…
so if you are not_home for 4 minutes, and enter the zone again, it will not trigger.

The screenshot about the trigger entity_id youve took, is in the action field.
The trigger is already a condition, so not useful to use it in your condition again.