Life360 Device Tracker Platform

You are 100% correct and I have experienced this.

What I find happening is the state constantly changes between not_home and driving. I thought about it after I set it up and then verified it when I left work.

I’ll look at customising the platform and see how that goes.

It seems that putting

if not loc_name and attrs[ATTR_IN_TRANSIT]:
    loc_name = 'driving'

Breaks the platform.

Breaks it in what way?

I just tried adding that and although none of us are in transit right now, it’s working ok. I can update you when the in_transit status changes for one of us.

I added those lines in and upon restarting Hass, no locations are reported.

What line number did you add that in at?

152, after the statement that sets attrs, and right before the call to self._see().

            attrs = {
                ATTR_LAST_UPDATE:  dt_attr_from_utc(last_update),
                ATTR_AT_LOC_SINCE: dt_attr_from_ts(loc['since']),
                ATTR_IN_TRANSIT:   bool_attr_from_int(loc['inTransit']),
                ATTR_CHARGING:     bool_attr_from_int(loc['charge']),
                ATTR_WIFI_ON:      bool_attr_from_int(loc['wifiState']),
                ATTR_DRIVING:      bool_attr_from_int(loc['isDriving'])
            }
            if not loc_name and attrs[ATTR_IN_TRANSIT]:
                loc_name = 'Driving'
            self._see(dev_id=dev_id, location_name=loc_name, gps=(lat, lon),
                      gps_accuracy=round(float(loc['accuracy'])),
                      battery=round(float(loc['battery'])),
                      attributes=attrs)

Yep. That works.
I changed it from ‘Driving’ to ‘Moving’ to align with what life360 reports.

Works really well actually!
Thanks so much.

1 Like

Actually, this seems like a really nice feature. I just ran some errands and looked back at the history, and sure enough it showed me moving while I was gone, except for the few stops I made.

I think I’ll add another config option to enable this. (Some people may prefer the state only being ‘home’ or ‘not_home’. Which makes me think, maybe I should add another config option for showing Places as states, too.) Given that states are usually all lower case (I think) I’ll probably show inTransit as ‘moving’. I should probably also show isDriving as ‘driving’, and it should probably take precedence over ‘moving’. Maybe I’ll temporarily enable “Drive Detection” in Life360 to see if/how that shows up.

@pnbruckner Do you have plans to put this on github? It would be great to expose loc_name as an attribute to trigger actions based on life360 defined locations/places

The code is at the top with instructions (although not with these latest changes yet) so you can copy and paste it for now. But, yes, I hope to get it into github before long.

loc_name actually becomes the device_tracker state so you can trigger automations based on places.

I tried enabling “Drive Detection” via the Life360 app, and although the Life360 app now showed when I was driving as Driving (as opposed to Moving), the raw data from the server still had a value of ‘0’ for isDriving. Hmm, maybe this parameter is associated with their extra cost “Drive Protection” service (which I don’t have.)

New update: Changed attribute in_transit to moving to be more consistent with how Life360 reports this status. Added new configuration option show_as_state to control which attributes will affect device_tracker entity’s state. (To be equivalent to previous behavior you must add show_as_state: places to your configuration.)

Oops, should have tested a little longer! :blush: State was still being set to moving (or driving) even when device entered a HA zone. Now being in a zone takes precedence over moving or driving, but Life360 Places (i.e., places) still takes precedence over everything.

Thanks, great work!. Your custom component works perfectly for me. Hopefully, it will be merged in Home Assistant in the future.

1 Like

Hi @pnbruckner I have just updated both life360.py files and now the locations of my circle our freezing even if i reboot HA.

Any Help Sorry.

Can you expand on what you mean by that? Do you mean the device_tracker entities aren’t updating anymore? Or they aren’t showing up at all anymore?

Are you seeing any errors on the Info page or in the log? If you have debug enabled for the log, are you seeing any Checking members or Updating messages for custom_components.device_tracker.life360?

If you do this:
grep 'custom_components\.device_tracker\.life360' home-assistant.log

You should see messages like these:

2018-05-17 11:51:07 INFO (MainThread) [homeassistant.loader] Loaded device_tracker.life360 from custom_components.device_tracker.life360
2018-05-17 11:51:08 DEBUG (Thread-14) [custom_components.device_tracker.life360] Life360 communication successful!
2018-05-17 11:51:18 DEBUG (Thread-20) [custom_components.device_tracker.life360] Checking members.
2018-05-17 11:51:19 DEBUG (Thread-20) [custom_components.device_tracker.life360] Updating member_name.

The Checking and Updating messages should repeat.

Also, what version of HA are you on?

The position of the device_trackers our at the same as yesterday.

The only log i have is

INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.life360

I am on HA 0.69

Thanks

Ok. I’m on 0.67.1, and I know there were changes made since then regarding how custom components & platforms are loaded. I’ve seen others discuss how this caused problems. I wonder if this is part of the problem here. I was hoping to wait a while for that “dust to settle” before updating, but maybe I need to do that anyway. I’ll try to do that soon.

Did you happen to upgrade between the time this worked for you and now?

Can you share your corresponding configuration.yaml entries? You can private message me if you’d prefer.

Regarding the additional log messages, are you sure you have DEBUG messages enabled? Are you seeing any DEBUG messages in your log at all (from other components)? If you need help enabling DEBUG messages, let me know.

Kind of surprising that the entities aren’t updating, yet you’re apparently not seeing any errors either. Hmm.

Do the entities show up on the States page? And if so, what are the last_update and at_loc_since attributes showing?

I only get

device_tracker.cameron_	
source_type: gps
latitude: xxxx
longitude: xxxx
gps_accuracy: 65
battery: 81
friendly_name: Cameron

I use to get a lot more before you made the last change.

Ok, that is the information that the recorder saves and restores when HA stops and restarts (apparently because those are basic device_tracker attributes.) So it would appear the entities are showing up only because they are getting restored by the recorder. That seems consistent with your other observations.

So then you didn’t just upgrade HA?

Also, can you share what you have for the following in your configuration.yaml (feel free to leave out anything sensitive)?

device_tracker:
  - platform: life360

FWIW I’m on 0.69.1 and the latest version of this and everything’s working fine. If I had to guess, I’d say it’s probably a copy/paste error of the .py file(s). Copying the code in the embedded blocks is a bit cumbersome…