Add a 10 minute delay to the end of the automation and put the automation into single mode.
Parallel mode means it will re-trigger over and over constantly when running.
EDIT: Ignore all this and see Drew’s answer below.
It is a tricky one. Home Assistant does not have any way of accessing the previous to last state change time Only the last state change time. So you would have to track this yourself. One way would be with four triggered template binary sensors. e.g.
# configuration.yaml
template:
- triggers:
- id: "on"
trigger: platform: state
entity_id: person.frederic
to: "not_home"
for:
minutes: 10
- id: "off"
trigger: platform: state
entity_id: person.frederic
to: "home"
for: 5 # seconds, prevents race condition with automation
binary_sensor:
- name: Frederic Away for 10 min
state: "{{ trigger_id | bool }}"
- triggers:
- id: "on"
trigger: platform: state
entity_id: person.jessica
to: "not_home"
for:
minutes: 10
- id: "off"
trigger: platform: state
entity_id: person.jessica
to: "home"
for: 5 # seconds, prevents race condition with automation
binary_sensor:
- name: Jessica Away for 10 min
state: "{{ trigger_id | bool }}"
- triggers:
- id: "on"
trigger: platform: state
entity_id: person.romeo
to: "not_home"
for:
minutes: 10
- id: "off"
trigger: platform: state
entity_id: person.romeo
to: "home"
for: 5 # seconds, prevents race condition with automation
binary_sensor:
- name: Romeo Away for 10 min
state: "{{ trigger_id | bool }}"
- triggers:
- id: "on"
trigger: platform: state
entity_id: person.alessia
to: "not_home"
for:
minutes: 10
- id: "off"
trigger: platform: state
entity_id: person.alessia
to: "home"
for: 5 # seconds, prevents race condition with automation
binary_sensor:
- name: Alessia Away for 10 min
state: "{{ trigger_id | bool }}"
You can then add just this one extra condition to your automation.
thank you very much
i implemented trigger.from_state.last_changed and hope it works and will report back. ////edit it works, thank you all
it is difficult to test but one of the most important automations i have.
(it warns you on all alexa speakers if someone enters the home radius.)
alias: Meldung Jemand kommt nach Hause
description: ""
triggers:
- entity_id:
- person.frederic
- person.jessica
- person.romeo
- person.alessia
to: home
from: not_home
trigger: state
conditions:
- condition: state
entity_id: input_boolean.meldungs_switch
state: "on"
- alias: The person was in its previous state ('not_home') for at least 2 minutes
condition: template
value_template: |
{{ now() - trigger.from_state.last_changed >= timedelta(minutes=2)}}
actions:
- action: notify.send_message
metadata: {}
data:
message: "{{ trigger.to_state.attributes.friendly_name }} kommt nach Hause."
target:
entity_id:
- notify.homeassistant_durchsagen
mode: parallel
max: 10
Note that if people’s states drift from home too often, you’ll not get any notifications. Downside of this version is that anyone drifting will prevent notifications for 10 minutes.
I’dd try to add multiple (types of) device trackers to each person to prevent ti. Also I believe the companion app has options to list your home wifi to help it determine home more accurately.