home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.68k stars 30.8k forks source link

Life360 not affecting sensor correctly #81892

Closed bkr1969 closed 2 years ago

bkr1969 commented 2 years ago

The problem

Not sure how to even word this. I have a sensor that is based on the state of Life360. I get a notification from the app itself that my daughter is home, but even manually updating the sensor does not show her as home UNTIL I open the app and click on her icon. This works every time, but she is not updating as "Home" until then.

What version of Home Assistant Core has the issue?

2022.11.2

What was the last working version of Home Assistant Core?

2022.9.?

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Life360

Link to integration documentation on our website

https://www.home-assistant.io/integrations/life360

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Nope

Additional information

No response

home-assistant[bot] commented 2 years ago

Hey there @pnbruckner, mind taking a look at this issue as it has been labeled with an integration (life360) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `life360` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign life360` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


life360 documentation life360 source (message by IssueLinks)

pnbruckner commented 2 years ago

I have a sensor that is based on the state of Life360.

How is that sensor defined? Can you share the YAML code?

I get a notification from the app itself that my daughter is home

I assume you mean the Life360 app on your phone. Is that correct?

but even manually updating the sensor does not show her as home

Exactly what do you mean by this? Are you calling the homeassistant.update_entity service? If so, on what entity or entities? Or if something else, please elaborate.

UNTIL I open the app and click on her icon

Is this also referring to the Life360 app on your phone?

When you say not showing or updating as home, are you referring to the life360 device_tracker entity that represents your daughter's device? Have you looked at that entity on the STATES tab of the Developer Tools page? What does that show?

You can enable debug statements for life360 in HA by adding the following to your configuration:

logger:
  default: info
  logs:
    life360: debug
    homeassistant.components.life360: debug
    homeassistant.core: debug

After restarting HA there will be a lot of messages in home-assistant.log telling you exactly what the life360 integration is doing and seeing. Please look at them and let me know if that helps diagnose the problem. I'd be happy to interpret the log for you. You can send it to me via private message if you like (pnbruckner on the community forum, or pnbruckner@gmail.com.) If the file is very large you may need to use pastebin.com or something and send me a link.

bkr1969 commented 2 years ago

Sensor code (person.mia uses the Life360 device tracker):

  - platform: template
    sensors:
       m_where:
          friendly_name: Last Known Mia
          value_template: >
            {% if states('person.mia') == "unknown" %}
              {{states('sensor.m_where')}}
            {% elif states('person.mia') == "home" %}
              Home
            {% elif states('person.mia') == "not_home" %}
              Away
            {% else %}
              {{states('person.mia')}}
            {% endif %}

All references to "the app" are referring to the Life360 app.

Yes, I have set a homeassistant.update_entity to trigger if the front door is unlocked in the window of time when she would be arriving home from school.

The state of her device tracker (Life360) remains as "away" until I look at her in the Life360 app.

I will enable logging and see if I can obtain further helpful info.

Thanks!

bkr1969 commented 2 years ago

Core or Supervisor logs?

pnbruckner commented 2 years ago

Core: https://www.home-assistant.io/integrations/logger/

pnbruckner commented 2 years ago

Your sensor uses aperson entity. To help narrow things down, please only describe what the life360 related device_tracker entity is doing. Thanks!

bkr1969 commented 2 years ago

Yesterday it worked fine, today the same non-updating behavior. Logs pending...

bkr1969 commented 2 years ago
2022-11-11 15:26:38.461 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=device_tracker.mia_blythe, old_state=<state device_tracker.mia_blythe=home; source_type=gps, battery_level=54, latitude=xx.xxxxx, longitude=-xxx.xxxxx, gps_accuracy=15, address=Address, State, at_loc_since=2022-11-11T15:26:04-07:00, battery_charging=False, driving=False, last_seen=2022-11-11T15:26:26-07:00, place=Home, speed=0, wifi_on=True, attribution=Data provided by life360.com, entity_picture=https://www.life360.com/img/user_images/30ffe5f2-1e27-4ee7-8f46-e87f31731801/0ef193cf-882b-4e9f-9d77-5d6767d2339a.jpg?fd=2, friendly_name=Mia Blythe @ 2022-11-11T15:26:08.437747-07:00>, new_state=<state device_tracker.mia_blythe=home; source_type=gps, battery_level=54, latitude=xx.xxxx., longitude=-xxx.xxxxx, gps_accuracy=15, address=Our Home Address, at_loc_since=2022-11-11T15:26:04-07:00, battery_charging=False, driving=False, last_seen=2022-11-11T15:26:26-07:00, place=Home, speed=0, wifi_on=True, attribution=Data provided by life360.com, entity_picture=https://www.life360.com/img/user_images/30ffe5f2-1e27-4ee7-8f46-e87f31731801/0ef193cf-882b-4e9f-9d77-5d6767d2339a.jpg?fd=2, friendly_name=Mia Blythe @ 2022-11-11T15:26:08.437747-07:00>>

This is when Life 360 detected her home and my app sent me an alert. Home Assistant still listed her as away until I opened the app and looked at her at 15:32. Forget the sensors, the device_tracker for her on Life360 showed "away" even after the app had alerted me she was home.

pnbruckner commented 2 years ago

Well, your description doesn't jive with the line from the log you shared, which contains both:

old_state=<state device_tracker.mia_blythe=home

and

new_state=<state device_tracker.mia_blythe=home

Just before and after 2022-11-11 15:26:38.461 that device tracker entity was home, aka "Home".

Were there other lines from the log containing:

Event state_changed[L]: entity_id=device_tracker.mia_blythe

which showed different states? E.g., are there any of these state_changed events for this device tracker around 15:32?

I guess I'm not understanding when you show a log message that clearly shows the device tracker is home, that you say it showed away. Where are you looking and what are you seeing that tells you this?

In addition to the [homeassistant.core] Bus:Handling <Event state_changed messages, there should be ones that contain [homeassistant.components.life360] that give more detail that might be helpful.

It would be very helpful if you could filter out any log lines that contain either of these types of messages and send them to me so I can interpret them (e.g., use pastebin.com and then send me a link in a private message.) E.g.:

grep -iF -e life360 -e "new_state=<state device_tracker.mia_blythe" home-assistant.log > filtered_lines.txt
bkr1969 commented 2 years ago

I'm not 100% on the logs, but here is what doesn't make sense. The Life360 app sends me an alert when she arrives home, yet even 30 minutes later, when I look at the state attribute in HA for device_tracker.mia_blythe (this is the Life360 tracker) it still shows "away" instead of "home" until I open the app and look at her there, at which point HA instantly updates.

pnbruckner commented 2 years ago

The HA life360 integration uses your Life360 account (at least, I assume that is the account you used when you added the life360 integration to HA; if not, please say so) to periodically poll (every 10 seconds) the Life360 server. It uses the data it receives to determine the state of the corresponding life360 device_tracker entities. If the entity that corresponds to your daughter's device is not updating when you think it should, it's because the Life360 server is still sending old data for that device, or the HA life360 integration is not able to retrieve data from the Life360 server.

That is why I'm asking for log details. It's the only way to know for sure what's happening "behind the scenes" in HA. But, even without a lot of detail, there's really probably only two possibilities.

1) HA is not able to communication with the Life360 server, in which case all the life360 entities should change state to unavailable. Based on what you've said so far, this does not seem likely.

2) During the period from when your daughter's device has come home to the time the corresponding HA entity indicates that, the Life360 server is still sending old data for your daughter's device. This seems like the only possibility.

The questions then become, why is the Life360 server sending old data for your daughter's device, and why does it suddenly send new data when you open the app on your phone, even though the Life360 app on your phone has already sent a push notification that your daughter's phone has arrived in the Home Place?

The bottom line is, I can't answer those questions. That behavior is completely a function of Life360's software (i.e., their server and phone apps.)

However, I can offer one insight. I know in my situation, that in general the Life360 server does a pretty good job of providing up-to-date data for the various devices in my Circle. The time between updates can vary widely, though, and seems to be dependent on the phone's movement, the phone's cell service, and the phone's OS (e.g., Android vs iOS.) Phone settings can also have a big impact. (See Life360's FAQs.) E.g., when the phone is moving with decent cell service the updates come fairly frequently, and when it's not moving, or the coverage is shaky, the updates come much less frequently. (It's one of the reasons it's so good at minimizing battery usage.) BUT, having said that, if, e.g., my phone hasn't updated very recently, I open the app, it updates immediately. But, generally, at least in my experience, it updates my phone's location immediately, and opening the app on my phone has no impact on updating the other phones in my Circle.

So, in summary, unless we can discover that the HA integration is doing something wrong, and I'll need log details to make such a determination, it seems there's not much HA can do about your situation, which has much more to do with Life360's software and possibly settings on your phones. I would suggest reviewing Life360's FAQs for suggestions to improve responsiveness.

bkr1969 commented 2 years ago

That all makes sense. I do imagine that it’s on the Life360 side as she sometimes doesn’t update as away for 5-7 minutes either. She’s using an older iPhone so I’ve always been suspicious that that has a lot to do with it. The perplexing thing is why there is such a delay to HA vs the app. I appreciate your time but I don’t think this is worth delving into any deeper. I’ll keep looking at the logs myself but as far as I’m concerned, this issue can be closed. Thanks again for your time and insight.

pnbruckner commented 2 years ago

The perplexing thing is why there is such a delay to HA vs the app.

Agreed it is perplexing. I don't claim to understand how Life360's internals work, but the only thing I can come up with to explain this behavior (and this is just a guess, and I could be totally off the mark here) is maybe it's your Life360 account that is not updating until you open the app on your phone. Since HA is querying the Life360 server using your Life360 account (again, my assumption, tell me if I'm wrong), maybe HA is getting to see the Circle, and the status of the Members in that Circle, via your account, and maybe that "view" is stale until you open the app. So maybe the problem isn't with your daughter's phone (or entirely with your daughter's phone) and at least part of the problem is with your phone or its settings. And maybe there's some other mechanism Life360 uses to generate that push notification you get about your daughter's phone returning home. Anyway, just a guess. If I were you, I'd be checking Life360's FAQs to make sure all your phones are setup as best as they can be for responsive Life360 updates.

A couple of other thoughts, and then I'll close this out...

First, try to keep a watch on the last_seen attributes of all the life360 device_tracker entities. E.g., does only the entity that represents your daughter's phone get stale (i.e., last_seen getting old)? Or do they all get old and then all update when you open the app on your phone?

Lastly, please note that HA & Life360 have different definitions for "Home". It's possible they don't agree. You might want to make sure they use the same GPS coordinates and radius settings, or at least agree reasonably well. For more details, see:

https://www.home-assistant.io/integrations/life360/#home---home-assistant-vs-life360

bkr1969 commented 2 years ago

Here is why I think you are spot on. I work in an x-ray area with lots of lead shielding and electronics. I have WIFI but not good cellular. If it is my account causing the delay it could be due to this.

Thanks again for your help!

pnbruckner commented 2 years ago

I guess I should have said Internet connection, which is not necessarily limited to cell coverage. In any case, unless you can provide details that indicate the HA life360 integration is doing something wrong, or could work in a better way, there's not much I can do about this. I'll close this for now, but feel free to reopen it if/when necessary.

pnbruckner commented 1 year ago

@bkr1969 I said above:

if, e.g., my phone hasn't updated very recently, I open the app, it updates immediately. But, generally, at least in my experience, it updates my phone's location immediately, and opening the app on my phone has no impact on updating the other phones in my Circle.

Hmm, I guess I wasn't paying close enough attention. More recently I was doing some testing on something else, and noticed when I opened the Life360 app on my phone, ALL the HA device_tracker entities that correspond to Life360 devices immediately updated, not just mine.

So, my best guess at this point is that when you open the Life360 app on your phone, it makes a request (to, or via, the Life360 server???) for all the phones in your Circle to update themselves. I think this is the mechanism that is indirectly causing the HA entities to update, since they see new data from the Life360 server since all the phones in the Circle just got recently updated.

I still can't explain why you get a push notification from the Life360 app on your phone that your daughter's phone has arrived in the Life360 Home Place, even though your daughter's phone has not updated its location fully. Again, there must be some other mechanism Life360 uses to do that, maybe one that is more battery efficient than a full update. Who knows?

bkr1969 commented 1 year ago

So after the last update I haven’t had any issues with this. Not sure if it was the update or the fact that I edited my 360 “Home” circle to exactly match HA’s. Either way, works flawlessly now. Thanks!

pnbruckner commented 1 year ago

@bkr1969 I've started to work on a new feature based on some information someone shared with me a few years ago. Apparently, there is a way for HA to ask the Life360 server to update a member's location. I don't have a lot of detail, but it seems to work, for the most part. I have it running. If you have any interest in trying it, let me know.

BTW, the request is triggered by using the homeassistant.update_entity service, which I believe you said you tried before. In the current, released implementation, that will only cause the HA integration to immediately poll the server, but nothing else. I've added the new feature so now it will request an update for the member, wait a few seconds to give the server a chance to get new data, and then poll the server for the new data.

EDIT: I just realized this issue has been locked, so you probably can't respond here. So, I sent you an invite to a related community forum discussion.