Is it possible to access device_tracker.my_device’s «for» state as we use it in automation’s trigger?
I’m trying to get delta between «before last_changed» and «last_changed» (trigger’s firing).
Using last_changed in notification, obviously always returns 0 seconds (cuz exactly this change has actually triggered the automation).
Something like this:
automation:
- alias: test
trigger:
platform: state
entity_id: input_boolean.test # Or device_tracker.xxx
action:
- service: persistent_notification.create
data:
# title: '{{ states.input_boolean.test.before_last_changed }}'
# title: '{{ states.input_boolean.test.changed[1] }}' # History?
title: '{{ states.input_boolean.test.for }}'
I’ve also tried this but that just returns what I’ve set in a trigger section:
automation:
- alias: test
trigger:
platform: state
entity_id: input_boolean.test
to: 'on'
for: '0:00:01'
action:
- service: persistent_notification.create
data_template:
message: '{{ trigger.for}}'
Thanks!