Want to use Life360 to track and use home/away status

Thanks. I didn’t have any luck installing Mosquitto on my Lubuntu 16.10 platform - it kept giving me this error:

Err:3 http://security.ubuntu.com/ubuntu yakkety-security/universe amd64 mosquitto amd64 1.4.8-1ubuntu0.16.10.1
  404  Not Found [IP: 91.189.88.149 80]

…but I managed to install MQTT.fx on a Windows box, and have managed to subscribe to the owntracks topics. It looks like they’re updating - I can see valid longitude and latitude values (as well as battery level etc) - but there’s still no sign of my owntracks device_tracker on my HA console, and no known_devices.yaml file being created/updated.
???

FYI I can see 3 topics being updated in my MQTT subscriptions:
life360/ian
owntracks/my name/my name
owntracks/my wife’s name/my wife’s name
(my wife is in my Life360 family circle).
But still no known_devices.yaml file being created
???

Hmmm…I’ve just noticed that this error is also appearing when I restart HA:

Path to configuration.yaml: /config
Error fetching description at http://192.168.1.249:50001/
13:12 ssdp.py (WARNING)
Error doing job: Task exception was never retrieved
13:12 /usr/src/app/homeassistant/core.py (ERROR)
Unable to load /config/known_devices.yaml: Config file not found: /config/known_devices.yaml
13:12 components/device_tracker/__init__.py (ERROR)
Press the button to load the full Home Assistant log.

Log Details (ERROR)
Sun Mar 11 2018 13:12:45 GMT+0000 (GMT Standard Time)

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 342, in stream_connected
    yield from self.client_connected(listener_name, StreamReaderAdapter(reader), StreamWriterAdapter(writer))
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 476, in client_connected
    yield from self.publish_retained_messages_for_subscription(subscription, client_session)
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 723, in publish_retained_messages_for_subscription
    handler.mqtt_publish(
AttributeError: 'NoneType' object has no attribute 'mqtt_publish'

[Edit: adding “client_id: 12345” to my sensor config makes the above error go away]

Just pondering on how this is all (not) hanging together…how is the sensor definition linked to my owntracks device tracker? Is it the code in life360.py that sends owntracks device tracker info to the life360 sensor?

Is it the code in life360.py that sends owntracks device tracker info to the life360 sensor?

The opposite way around, but yes. The workflow is essentially this:

  • Life360.py polls Life360 for status information on members of your circle
  • Life360.py dumps all that info into MQTT under the life360/ian topic
  • Life360.py also pulls the relevant fields for the Owntracks device tracker, and creates an MQTT topic that matches the format the OwnTracks device_tracker expects to see
  • The OwnTracks device_tracker component should pick up the owntracks/ian/ian topic, and populate known_devices.yaml

You’re running homeassistant in docker right? What user is the docker container running as? Given that HA seems to not be able to create, or populate known_devices.yaml perhaps it could be a permissions issue?

For the sake of testing, what if you do:

  • touch /home/homeassistant/.homeassistant/known_devices.yaml
  • chmod 777 /home/homeassistant/.homeassistant/known_devices.yaml

If it turns out to be permissions then we can revert the 777 and fix it properly.

Edit: You’ll probably need to restart HA after running the above 2 commands.

Hmmm…interesting. I wonder if the topic name could be a clue to my problem? My HA sensor has a defined mqtt_topic of life360/ian but the owntracks MQTT topics that are being updated are:

owntracks/ian lastname/ian lastname
owntracks/gill lastname/gill lastname

i.e. the owntracks MQTT topic names include both my first and last names - presumably picking my full name up from the Life360 web service? I have tried changing the mqtt_topic of my life360 sensor definition to life360/ian lastname and life360\ian lastname\ian lastname respectively, but neither change seemed to make any difference - i.e. neither made the owntracks device tracker visible in my HA console.
Does the mqtt_topic in my sensor definition need to correspond to anything in my Life360 account details?
I did think about permissions being the issue, but think I’ve ruled that out as a cause: as an experiment I added a device tracker using the ASUSWRT platform (my Asus router supports this), and as soon as I added that device tracker the known_devices.yaml file was created by HA and was populated with a list of all of the devices connected to my router. I also saw each device shown as a device at the top of my HA console. That presumably means that HA has whatever permissions that it needs to create and update known_devices.yaml.
[Edit: I tried the touch and chmod commands anyway - followed by a restart - and nothing changed]

Hi I got it working today. One issue I had was that I had put my first name and last name in the name box of life360. I split it cortectly I.e. name and last name separately and then I got the topic owntracks/juan_juan.
I then got device_tracker.juan_juan.

The sensor sample sensor just tells you if the "service " is running.

Hmmm…so you entered your last name in Life360 but got an owntracks topic which consisted only of your first name??
I just noticed this in my log - I’m not sure if that gives any clues to why my device_tracker isn’t being created:

2018-03-15 15:48:11 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 342, in stream_connected
    yield from self.client_connected(listener_name, StreamReaderAdapter(reader), StreamWriterAdapter(writer))
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 476, in client_connected
    yield from self.publish_retained_messages_for_subscription(subscription, client_session)
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 723, in publish_retained_messages_for_subscription
    handler.mqtt_publish(
AttributeError: 'NoneType' object has no attribute 'mqtt_publish'
2018-03-15 15:48:11 DEBUG (MainThread) [hbmqtt.broker.plugins.packet_logger_plugin]  -out-> SubackPacket(ts=2018-03-15 15:48:11.140669, fixed=MQTTFixedHeader(length=3, flags=0x0), variable=PacketIdVariableHeader(packet_id=4), payload=SubackPayload(return_codes=[1]))
2018-03-15 15:48:11 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: timestamp=1521128891.142239, level=ERROR, message=Error doing job: Task exception was never retrieved, exception=Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 342, in stream_connected
    yield from self.client_connected(listener_name, StreamReaderAdapter(reader), StreamWriterAdapter(writer))
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 476, in client_connected
    yield from self.publish_retained_messages_for_subscription(subscription, client_session)
  File "/usr/local/lib/python3.6/site-packages/hbmqtt/broker.py", line 723, in publish_retained_messages_for_subscription
    handler.mqtt_publish(
AttributeError: 'NoneType' object has no attribute 'mqtt_publish'
, source=/usr/src/app/homeassistant/core.py>

Ah sorry Juan I now see what you mean - I noticed that I had also entered both my first and last name in the Life360 “First Name” box on the website. I have now corrected it, and my HA MQTT topics are now:

life360/ian
owntracks/ian/ian
owntracks/gill/gill

But the device tracker is still not visible on the HA console (or in known_devices.yaml) :0(

The only thing I have left to suggest, is manually populate the known_devices.yaml with your settings in this case. Mine looks as below:

kyle_kyle:
  hide_if_away: false
  icon:
  mac: XX:XX:XX:XX:XX:XX
  name: Kyle
  picture:
  track: true
  vendor: Apple, Inc.

The device name (in my case kyle_kyle) should match your OwnTracks topic, excluding the owntracks portion. So for you it would be ian_ian and gill_gill respectively. You can see then if it starts providing the correct data. You can probably scrap the vendor line.

Also, I know it’s probably a stupid question, but I’m clutching at straws here, you do have the Owntracks platform configured for device trackers in your configuration.yaml right?

# OwnTracks
- platform: owntracks

I’m not sure what the HBMQTT errors are referring to in the case of your log I’m afraid, as I’m using Mosquitto as my MQTT broker. However it looks like it’s referring to publishing messages, not reading them.

If the pre-populating known_devices.yaml doesn’t work, the only suggestions I have left are:

  • Temporarily disable life360.py, and install the Owntracks app. Just so we can definitively rule out whether or not it’s a problem with the Life360 component, or a broader problem in your HA instance
  • Possibly open an issue on the life360.py GitHub repo, see if @skalavala has any ideas

Ok I tried manually adding entries in known_devices.yaml (with made-up MAC addresses for ian_ian and gill_gill), but they didn’t get updated.
I then tried setting up Owntracks on my Android phone, but couldn’t get past a java.io.EOFexception when trying to connect to my HA MQTT server. I had port forwarding set up for 1883, set up a username/pw for the MQTT service, etc, but couldn’t work out why it couldn’t access my MQTT server.
In the end I decided that trying to get that up and running was probably no less complicated than trying to resolve the original problem.
I did leave a message on Github for the life360.py developer, but the last response was 5 days ago so I guess he didn’t have any ideas.
I believe that I have the owntracks platform configured correctly for my device tracker - this is what it looks like:

device_tracker:
  - platform: owntracks

I assume that I don’t need any other parameters?

@itm1960, thats correct. So your owntracks/ian/ian topic should be reporting location, battery etc on the console.

Sorry, silly question but did you add this to your configturation.yaml file:

device_tracker:

  • platform: owntracks

Yes this is the code copied and pasted from configuration.yaml:

device_tracker:
  - platform: owntracks

I can see the owntracks/ian/ian topic correctly reporting location, battery, etc if I subscribe to the MQTT topics on my HA server using the MGTT.fx client. It’s just HA that is not picking up the MQTT data and reporting it.
There is also a life360/ian topic being published on the HA server - this contains much larger MQTT messages, but is also being kept updated.

Hmmm, well I’m officially stumped. I promise you that setting up device trackers in HASS is definitely not usually this hard these days.

When you forwarded port 1883 to your HASS instance for OwnTracks, did you also add 1883 to the docker container run options? Or I’m lieu of that, have you configured to container to use host mode networking?

If we can confirm that all that config was done correctly, it might be worth trying Mosquitto as your MQTT broker instead of the built-in broker. That’s the only difference in our setups that I can see at this point. There’s a docker image for Mosquitto - eclipse-mosquitto:latest - so it shouldn’t take too long to get set up.

@juan11perez, are you using the built in broker, or Mosquitto/CloudMQTT?

No I didn’t add anything for port 1883 to the docker run options, nor do I know anything about host mode networking (I’m a complete newcomer to Docker). This is the command that I used:

sudo docker run -d --name="home-assistant" -v ~/homeassistant:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant

Do I need to add an option?
I’ll investigate setting up Mosquitto…

That command is fine, this option --net=host is the one that sets the container networking options to host mode. For the purposes of what we’re discussing, it just means that you don’t have to manually specify ports that are passed through to the container.

Oh and in response to your earlier question, yes, your device_tracker config is correct.

I’m running Mosquitto

So I managed to get Mosquitto up and running (in a Docker container) and it seems to have solved the problem - many thanks for all of your input.
I have no idea why this wouldn’t work with the embedded HA MQTT broker, and would be curious to know if anyone else managed to get it working.

Hm, yeah, strange. I don’t think I’ve seen any issues around OwnTracks and the embedded broker mentioned before. In any case, glad you got it working.

Sorry, kind of late to this discussion, but I thought I’d mention this anyway in case you (or others) are interested. I created a custom device_tracker platform for Life360. It does not require any other service (such as MQTT or owntracks.) It basically goes right to the Life360 server. It does, however, use a low-level python integration to Life360 that is not officially published. But, other than that, it works pretty well (at least for me), and doesn’t require setting up all those other components. If you’re at all interested, check out:

And if you (or anyone) is interested in trying it out, let me know and I can provide more details. (Probably best to PM me in that case.)