Could you point me to an example for how to track for how long a person
has been away from home? The counting should start when the person leaves home and get reset to zero when the person
comes back. Bonus point if there is an easy way to have a daily, and weakly summary that sums all these times away.
This should be the right sensor:
1 Like
Thanks. I have this code for tracking time away today and this week but I would like to have time away since the person left.
- platform: history_stats
name: Maui away from home today
entity_id: person.maui
state: "not_home"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
- platform: history_stats
name: Maui away from home this week
entity_id: person.maui
state: "not_home"
type: time
start: "{{ as_timestamp( now().replace(hour=0, minute=0, second=0) ) - now().weekday() * 86400 }}"
end: "{{ now() }}"
How do I get a time stamp for when the person left? How do I set the sensor to zero if that timestamp < now() (the person is home)?
Thanks!
Hello Ignacio, did you find a solution for this? I am looking for the same thing
1 Like
Looking for the same thing
My solution for my problem was this. Maybe it will be helpful:
- Create a helper for timestamp of when the person last left home:
input_datetime.person_name_last_left_home
- Create an automation to update the helper:
alias: Update person_name Last Left Home Timestamp
description: ""
mode: single
triggers:
- entity_id:
- person.person_name
from: home
to: not_home
trigger: state
conditions: []
actions:
- action: input_datetime.set_datetime
metadata: {}
data:
datetime: "{{ now() }}"
target:
entity_id: input_datetime.person_name_last_left_home
- I wanted to track how long something was running while I was not home. I use history stats helper to track the time a switch was turned on since the person left home until now:
There is a slight issue, that it continues to track even when I am at home, but I do not mind, because I only check this when I am not at home.