Just wondering how to track the real “not at home” times using History Stats. I’m currently using state: 'not_home' but that doesn’t work if using zones—whenever I’m at work or in a friend’s zone, I’m still “not at home” but this time wouldn’t add to the sensor.
sensor:
# Not home hours today
- platform: history_stats
name: Unterwegs heute
entity_id: person.matthias
state: 'not_home'
type: time
start: '{{ now().replace(hour=0, minute=0, second=0) }}'
end: '{{ now() }}'
# Not home hours this week
- platform: history_stats
name: Unterwegs diese Woche
entity_id: person.matthias
state: 'not_home'
type: time
start: '{{ as_timestamp( now().replace(hour=0, minute=0, second=0) ) - now().weekday() * 86400 }}'
end: '{{ now() }}'
Now do I really have to add an extra template sensor for each person I want to track not being at home or is there an easier way to do this?
To make it clear, I wish to track {{ not is_state('person.matthias', 'home') }} (for me and some others), so even if my state would be “Work” or “Home Friend’s Place” it would count towards “not at home”.
Also to point out, if the zones are only being used for automation, simply set them as passive so that the state doesn’t change to the name of the zone when the device is in them…
The curiosity stays if you could template this into an history_stats sensor without one of the many people sensors (person, device trackers, home occupancy now, etc. etc.), but it seems we cannot, right?
No, sadly the docs say it is a string or a list -
however the fact that it accepts a list means you could in fact list all the states that are not home, eg all your zones.