So the problem I have is I get multiple notifications when moving in or out of zones, presumably because of GPS inaccuracy on the border of the location radius. What I want to do, is add a condition that the notification only sends if that particular entity (the person) hasn’t already been notified in the last 3 minutes.
Working code is first, and then an attempt at what I’m trying to do comes after:
trigger:
- platform: state
entity_id:
- person.alec_down
- person.kelsey_down
- person.christopher_hansen
for:
hours: 0
minutes: 0
seconds: 30
condition:
- condition: template
value_template: '{{ trigger.from_state.state != trigger.to_state.state }}'
action:
- service: notify.notify
data_template:
message: '{{ trigger.to_state.attributes.friendly_name }} {% if trigger.to_state.state
== ''not_home'' %}has left {{ trigger.from_state.state }}{% endif %}{% if
trigger.from_state.state == ''not_home'' %}arrived at {{ trigger.to_state.state
}}{% endif %}.'
And so I basically want to add a second condition that’ll look something like this, but not sure how to dynamically insert the last_changed
on the entity.
- condition: template
value_template: "{{ as_timestamp(now()) - as_timestamp(states.{{ trigger.entity_id }}.last_changed) >= 180 }}"
Any ideas? Does this look right? Can I even use {{ }}
in a condition?