I have an automation for my kids where they can ask Alexa where mommy or daddy is and, if our phones are in a designated zone within Home Assistant, Alexa will respond “daddy is at work” or “mommy is at grandma’s”. If we aren’t in a designated area, I have it set up to say “mommy (or daddy) is driving”. I would like to enhance this part by adding “they left X (zone) Y minutes ago”. I am assuming to do this I need to access the entity history for our phones. I know I can see the history in the dashboard and it tells how long our phones have been in a zone (or away). I would like to access this data, however, when I load the entity in the States screen, this info isn’t part of the attributes. So I am assuming I need to access another entity and use the phone as the argument for it. I am just not sure what that other entity is. Any help would be much appreciated.
Assume we have some “device_tracker.jane_phone” entity (same for “person”).
Here is how it’s state changes:
home → not_home → Work → not_home → Grandma’s → not_home → home
(and “home” & “not_home” will be shown in your UI as translated “Home” & “Away”).
If an entity is between “Work” & “Grandma’s” (and thus is “not_home” currently) - then it left “Work” at
states.device_tracker.jane_phone.last_changed
So, you need to use this attribute in your notifications/automations.
As for the “they left XXX zone”:
if your automation is state-trigger based - then you can use “trigger.from_state.state” variable to access a prev. value.
If you need this info as some sensor - then create a template sensor like (simplified code, needs improving):
template:
- trigger:
- platform: state
entity_id: device_tracker.jane_phone
not_from:
- unavailable
- unknown
sensor:
- name: prev_zone
state: >-
{{ trigger.from_state.state }}
Thank you for this.
I’ve been playing around with the code from this old post:
However, one of the most recent posts states they are getting blank notifications with just the person’s name. This is what I am experiencing as well. It would seem that HA isn’t able to verify the “home” and “not_home” text. I did try to change this to a variety of other items like “away” and “not_away” but those don’t work either and I am still getting blank notifications with just the name.