Hello,
I’m trying to trigger an automation when a device tracker updates its state to a new state, but only if the new state has different GPS coordinates in comparison to the old state. I read a lot about events, old_state vs. new_state, event triggers but I couldn’t find the right hint.
Currently I’m stuck at this point:
- alias: "Get new parking position"
trigger:
- platform: event
event_type: state_changed
event_data:
entity_id: device_tracker.audi_car
condition:
- condition: template
# Only look at GPS Position Change
# this is not working
value_template: >
{{ trigger.event.data.old_state.attributes.latitude is not trigger.event.data.new_state.attributes.latitude
and trigger.event.data.old_state.attributes.longitude is not trigger.event.data.new_state.attributes.longitude }}
action:
#notify
My trigger is working fine - every 10 minutes the device tracker is updated. But the condition is not working. I want to compare the GPS position of the old_state to the GPS position of the new_state in order to determine if there is a difference and I need to push the notification to my phone.
I know that the current code in the condition is completely wrong, but that’s where I’m stuck - I have an idea how to proceed but not the know-how to do it
states.device_tracker.audi_car.attributes.latitude
states.device_tracker.audi_car.attributes.longitude
This is working fine to get the current GPS position of the car.
How do I get acces to the old_state vs. new_state event in the condition? Is there a better way to do this?