Life360 Device Tracker Platform

Ah i did notice that in my Node Red outputs! Thanks

if you want to use this new branch for now you need to pull manually (well not use HACS) from here > GitHub - pnbruckner/ha-life360 at new-api

AFAIK Phil will do a beta via HACS soon but not yet ver 0.3.10 is from an old branch without these new changes over the last week or soā€¦

First, like @Gav_in states below, 0.3.10 is very old and not guaranteed to work, and probably wonā€™t at some point. If you want to try the newest stuff (which is still a WIP), then youā€™ll have to manually get the files onto your system from github. Be aware that it will be changing frequently for now.

Regarding the address attribute, it comes from Life360. My integration does not try to determine it based on GPS coordinates. (Neither does the Google Maps integration, for that matter. In that case, it comes from Google that way.) If you want to get an address from GPS coordinates, you could try my ā€œEntity Time Zoneā€ integration. In addition to determining Time Zone from GPS coordinates (where it originally got its name), it can determine various other data, such as address.

The only thing the Life360 integration does with the address from the server is to combine the pieces it provides. I.e., it provides two address fields (where sometimes only one has a value), and it sometimes alternates between two sets of values every other query. And sometimes it duplicates the value from the place field. The integration tries to put these (potentially) five pieces of data together into one string attribute.

I have a quick question regarding zones. I have never set up any zones (from memory) in HA, but all my life 360 places are there as zones. Is there a way to reimport the life 360 places into zones? I have a vague memory or running a script maybe once to do this?

So far, with the new implementation of the integration, I havenā€™t done anything with Places yet (other than showing Places a Member is reported to be in in the trackerā€™s place attribute. That comes ā€œfor freeā€ when querying for the Memberā€™s details.)

I.e., it does not query the server for the list of Places that exist in each Circle like it did before. I havenā€™t decided yet if Iā€™m going to add that back in. At minimum, if I do, then it could simply list them in the log as DEBUG statements (like it did before.) I could do more, though. A VERY long time ago, before it ever became a built-in integration, it did have a feature for automatically creating HA Zones from Life360 Places. That is still a potential, but not even on the current ā€œTo Doā€ list.

2 Likes

No problem Phil.

I noticed there were only 3 places missing anyway from mine, so I manually added them to the zones.yml file in HA by getting the gps coordinates for them.

Thanks!

UPDATE:

Iā€™ve added a few more commits:

  • Remove device_tracker entity if Member is no longer in any Circles visible from registered accounts. The entity will still be in the entity registry in case there was just a temporary change (e.g., someone was accidentally removed from a Life360 Circle and then added back.)
  • Save & restore device_tracker state. Since more than likely new data will be retrieved from the server shortly after a HA restart (or config reload, etc.), this isnā€™t as important as it is with some integrations. However, it can fill in some ā€œgapsā€ in certain circumstances.
  • Retry ā€œloginā€ errors (i.e., 403 errors) indefinitely when retrieving Circles (just like for 429 ā€œtoo many requestsā€ errors.) Iā€™ve already experienced where Circles can be retrieved after getting three ā€œloginā€ errors in a row. Since thereā€™s no way to know what the limit should be, donā€™t set one. Just warn if updating Circles & Members is taking more than an hour. Member details can still be retrieved while this is happening in the background.
  • Retry HTTP error 520. I noticed this yesterday. Seems to be a ā€œcatch allā€ error Cloudflare sends when it canā€™t relay the request to Life360 and get a response from it. When this happened, the next request (5 seconds later) worked just fine. So, retry it like other ā€œintermittentā€ errors.

Iā€™ve also done some prep work to add the online binary sensors back in, which Iā€™ll do shortly.

3 Likes

Sorry if this is a simple questionā€¦ I cloned the repo from git and created the link.

How do I get it to show up in my HA (docker setup)?

Thanks!

-Tim

I have all my custom integrations cloned into ~/repos. Then I have this (snippet) for my docker compose.yml:

version: '3'
services:
  homeassistant:
    container_name: homeassistant_test
    image: "ghcr.io/home-assistant/home-assistant:2024.4.3"
    volumes:
      - ./config:/config
      - /home/phil/repos/ha-life360/custom_components/life360:/config/custom_components/life360
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

Just made a new commit which adds the online binary sensor.

UPDATE: Sorry, itā€™s a bit buggy. Iā€™ll let you know when I think Iā€™ve fixed it. For now, use the commit before I added the binary sensors.

UPDATE: Ok, should be working now. Sorry for any inconvenience.

1 Like

Maybe Iā€™m pulling down the wrong repo?

git clone https://github.com/pnbruckner/ha-life360.git

But I did as you and created a folder called repos and cloned there.

Then in my existing homeassistant config folder under existing custom_components I created the link:

ln -s /mnt/data/homeassistant/repos/ha-life360/custom_components/life360 life360

My directory looks like this now:

root@intelnuc8a:/mnt/data/homeassistant/custom_components# ls -larth
total 24K
drwxr-xr-x 10 root root 4.0K Apr 18 22:12 hacs
drwxr-xr-x  3 root root 4.0K Apr 18 22:12 entity_controller
drwxr-xr-x  5 root root 4.0K Apr 18 22:12 alexa_media
drwxr-xr-x 10 root root 4.0K Apr 26 17:25 ..
lrwxrwxrwx  1 root root   66 Apr 26 17:26 life360 -> /mnt/data/homeassistant/repos/ha-life360/custom_components/life360
drwxr-xr-x  5 root root 4.0K Apr 26 17:26 .

cd to life360 and this is what I see:

root@intelnuc8a:/mnt/data/homeassistant/custom_components/life360# ls -larth
total 100K
drwxr-xr-x 2 root root 4.0K Apr 26 17:25 translations
-rw-r--r-- 1 root root 1.5K Apr 26 17:25 strings.json
-rw-r--r-- 1 root root  377 Apr 26 17:25 manifest.json
-rw-r--r-- 1 root root  15K Apr 26 17:25 device_tracker.py
-rw-r--r-- 1 root root  39K Apr 26 17:25 coordinator.py
-rw-r--r-- 1 root root 1.3K Apr 26 17:25 const.py
-rw-r--r-- 1 root root 7.4K Apr 26 17:25 config_flow.py
-rw-r--r-- 1 root root 2.4K Apr 26 17:25 binary_sensor.py
-rw-r--r-- 1 root root 5.3K Apr 26 17:25 __init__.py
drwxr-xr-x 3 root root 4.0K Apr 26 17:25 ..
drwxr-xr-x 3 root root 4.0K Apr 26 17:25 .

I restarted HA but still donā€™t see anything anywhere related to Life360 where I can configure it.

I even updated to the latest Life360 2024.4.4

-Tim

If you do

git branch

What do you get?

you need to switch to the new-api branch

  master
* new-api

Cheers

mb

I figured it out. Have to think in terms of the container and not the host.

Changed the link to:

ln -s ../repos/ha-life360/custom_components/life360 life360

I originally made the link the direct path based on the host machine. Needed to make it something that the container would be able to understand.

I did the docker exec -it home-assistant /bin/bash and went to the custom_components directory and before it could not open life360 but now it can.

And on the web, I was on the new-api branch when I got the code

This is what my directory looks like now:

intelnuc8a:/config/custom_components# ls -larth
total 20K
drwxr-xr-x   10 root     root        4.0K Apr 18 22:12 hacs
drwxr-xr-x    3 root     root        4.0K Apr 18 22:12 entity_controller
drwxr-xr-x    5 root     root        4.0K Apr 18 22:12 alexa_media
drwxr-xr-x   10 root     root        4.0K Apr 26 18:03 ..
lrwxrwxrwx    1 root     root          45 Apr 26 18:48 life360 -> ../repos/ha-life360/custom_components/life360
drwxr-xr-x    5 root     root        4.0K Apr 26 18:48 .

I restarted HA and went to integrations under settings and clicked the button to add and typed in ā€œLifeā€ and Life360 came up. It added and asked for credentials. It worked and after a while it populated entities for it as well.

Thank you all!

-Tim

1 Like

Yep. I chose to use the volumes option in the compose.yml file. Apparently, faking a symbolic link works, too.

It doesnā€™t work that way. You have to switch to the new-api branch:

git status
git switch new-api
git status

The first status Iā€™m sure will show the master branch, but the second should show the (correct) new-api branch.

Once youā€™ve switched to the correct branch, restart HA.

The master branch may work, maybe for a while, but eventually it wonā€™t, I can almost guarantee it.

1 Like

QQ, If I pull the latest code and the code is mounted in a docker volume (life Phill did above), do I have to restart HA or can I just reload the integration?

I am pretty sure I need a HA restart, but just checking.

AFAIK, you need to restart.

1 Like

Well, apparently, it was a good thing to retry error 403 while retrieving Circles indefinitely. Overnight I got 13 in a row for one of my accounts, which made it take over 3 hours to finally retrieve Circles & Members for both accounts!

Also, Iā€™ve been trying to add the ability to login by phone number instead of username & password. But, so far, Iā€™ve been unsuccessful. However, I found a way to workaround the problem (can you say, ā€œhackā€?) and Iā€™ve been able to use my ā€œnormalā€ Life360 account, which has a verified phone number, for a while now.

Basically, you go to www.life360.com, sign in, then in the browserā€™s developer tools, you retrieve the authorization code from the recorded network traffic. For now Iā€™ve just manually entered it into config/.storage/core.config_entries, but I will probably add a way to enter this code via the UI.

If anyone would like to give this a try, let me know.

2 Likes

Thank you Phil.

By the time I got to it, it had already stopped working. I corrected the clone to the right branch but it did not recover. I removed the add-on and waited until the next day and added it back and so far it is working good now.

1 Like

A little thing that happens sometimes. Speed never comes back to zero.

That is just the value that the server is reporting. Well, itā€™s the value the server reports x 2.25, and then possibly converted from mph to km/h. If itā€™s non-zero, then the server is reporting a non-zero value.