I read through a few related items like this, but didn’t see much in terms of a resolution and perhaps I’m just not clear on how a time type history_stats works. I have a Ubitquity doorbell that has a binary sensor for person detected:
I’m not sure what the 0.067 number represents, but it isn’t that many hours ago. I looked into the .last_changed value, but that seems to be only when I restarted HA:
{{ relative_time(states.sensor.doorbell_last_person.last_changed) }} ago
How should I be translating the state of a timehistory_stats item? Thanks!
I want to be able to mimic the integration’s view where it says “1 hour ago”, indicating the a person was last seen 1 hour ago.
When I tried to pull the .last_updated of the Unifi Protect integration’s binary_sensor, it seemed off (perhaps it was the time i restarted HA, so I thought “oh, the history_stats would work over restarts better.”
A timestamp would work, then I can display it differently in different spots. I changed how I was searching and found this post:
I think that is basically what I want, so I need to define a trigger to capture when the state on the binary_sensor goes from off to on, and populate another sensor with the timestamp?
template:
- trigger:
- platform: state
entity_id: binary_sensor.front_door_person_detected
to: 'on'
sensor:
name: Front Door Person Detected Timestamp
device_class: timestamp
state: "{{ now() }}"
Just FYI, this should be placed in your configuration.yaml file or a properly included file for template entities.