Comparing tracker accuracy

Not exactly massively important, this, but interesting for debugging/diagnostics.

At the moment I’m doing this to compare my Bluetooth tracker against Life360 and visa versa. I’d really like to be able to actually message myself (with Telegram) the time differential between how out of date either tracker is*. Any ideas how to go about this? Anyone already doing this?

*The only caveat and complicating factor is, to make it a fair test, I’d like the life360 timestamp to date from once I’ve actually opened my front door, not just when I enter the zone, as it’s not a fair comparison otherwise!

  - alias: 'Warn BT is not accurate'
    trigger: 
      platform: state
      entity_id: device_tracker.life360_boomer
      to : 'home'
      for:
        minutes: 1
    condition:
      condition: state
      entity_id: sensor.boomer_bt
      state : 'not_home'
    action: 
      - service: notify.telegram
        data:
          message: Bluetooth tracking not accurate

  - alias: 'Warn Life360 is not accurate'
    trigger: 
      platform: state
      entity_id: sensor.boomer_bt
      to : 'home'
      for:
        minutes: 3
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: device_tracker.life360_boomer
          state : 'not_home'
        - condition: numeric_state
          entity_id: sensor.iphone6s_battery_level_2
          above: 20         
    action: 
      - service: notify.telegram
        data:
          message: Life360 tracking not accurate

My first question would be, why worry about which is better/worse? Why not just get the best of both by combining them into a single tracker using my Composite Tracker? :wink:

Looking at what you’ve done so far, and what you seem to be asking for, I have a couple more questions. Why do the two automations use different “for” values in the trigger? Isn’t that unfair? You also say, “I’d like the life360 timestamp to date from once I’ve actually opened my front door.” And how can that be determined? Do you have a sensor on the door?

I don’t know about the BT tracker, but the life360 one has a last_seen attribute which indicates the last time the location was updated. You could use that at least when the BT changes to home to see how stale the information from life360 is.

FWIW, I use life360 and google_maps on my phone and my wife’s phone (combined using the composite tracker.) I was interested in seeing which service seems to be quicker at noticing when we arrive or leave home. I wrote this:

notify:
  - platform: file
    name: composite_wife
    filename: composite_wife.log
    timestamp: True
  - platform: file
    name: composite_me
    filename: composite_me.log
    timestamp: True

automation:
  - alias: Composite Updates Wife
    trigger:
      - platform: state
        entity_id: device_tracker.wife
        to: 'home'
      - platform: state
        entity_id: device_tracker.wife
        from: 'home'
    action:
      service: notify.composite_wife
      data_template:
        message: "{{ trigger.to_state.state }}: {{ trigger.to_state.attributes.last_entity_id }}"
  - alias: Composite Updates Me
    trigger:
      - platform: state
        entity_id: device_tracker.me
        to: 'home'
      - platform: state
        entity_id: device_tracker.me
        from: 'home'
    action:
      service: notify.composite_me
      data_template:
        message: "{{ trigger.to_state.state }}: {{ trigger.to_state.attributes.last_entity_id }}"

This creates two timestamped log files showing which service switched the composite tracker to and from home. They each look like this:

Home Assistant notifications (Log started: 2018-10-21T13:53:22.917542+00:00)
--------------------------------------------------------------------------------
2018-10-21T13:53:22.917678+00:00 not_home: device_tracker.life360_wife
2018-10-21T15:39:28.723848+00:00 home: device_tracker.life360_wife
2018-10-21T16:05:56.547730+00:00 not_home: device_tracker.google_maps_nnn
2018-10-21T23:31:14.096787+00:00 home: device_tracker.google_maps_nnn

Then I wrote a Python script (I use outside of HA) to analyze the logs:

import sys

count_home = {}
total_home = 0
count_not_home = {}
total_not_home = 0
with open(sys.argv[1], 'r') as f:
    for line in f.readlines():
        if 'google' in line:
            source = 'google'
        elif 'life360' in line:
            source = 'life360'
        elif 'ping' in line:
            source = 'ping'
        else:
            continue
        if 'not_home' in line:
            count_not_home[source] = count_not_home.get(source, 0) + 1
            total_not_home = total_not_home + 1
        else:
            count_home[source] = count_home.get(source, 0) + 1
            total_home = total_home + 1
print('home: total: {}'.format(total_home), end='')
for source in sorted(count_home, key=lambda x: count_home[x], reverse=True):
    print(', {}: {}%'.format(source, round(count_home[source]/total_home*100)), end='')
print('')
print('not_home: total: {}'.format(total_not_home), end='')
for source in sorted(count_not_home, key=lambda x: count_not_home[x], reverse=True):
    print(', {}: {}%'.format(source, round(count_not_home[source]/total_not_home*100)), end='')
print('')

Then using it on both of the logs I get:

pi@raspberrypi:/home/homeassistant/.homeassistant $ python3 composite.py composite_wife.log
home: total: 182, life360: 86%, google: 14%
not_home: total: 178, google: 50%, life360: 50%
pi@raspberrypi:/home/homeassistant/.homeassistant $ python3 composite.py composite_me.log
home: total: 179, life360: 77%, google: 17%, ping: 6%
not_home: total: 178, life360: 86%, google: 14%

The log files include data obtained continually since last October. As you can see, Life360 is generally better at more quickly updating when leaving or arriving home. Note that both services are running on both of our phones, at the same time.

One last comment about this data: You can see a small percentage of ping being the first indicating I was home. This is from when I ran that service for both of our phones as well as the others. It made such little difference I ended up scrapping the use of the ping device_tracker.

1 Like

Hi Phil

Thanks so much for your considered and useful reply, which I will be looking at at greater length tomorrow.

Because the bluetooth Monitor script used to be SUPER speedy and is now sluggish - I’m wondering why.

In theory the bluetooth scanner should more or less immediately pick me up as ‘home’ whereas with Life360 it seems to be more dependent on battery level and most importantly I also wanted to factor in some time for me to enter the GPS zone and then actually arrive at home. It’s an attempt at levelling the playing field.