Composite GPS-based Device Tracker?

Is there a “standard way” to combine multiple GPS-based device trackers for a single device/person?

E.g., I’ve been relying on just Life360 which has been pretty good as far as responsiveness and battery usage. However, one of the devices this tracks tends to be kept in power saving mode. And no matter how many settings I change on that device to allow Life360 to run as much as it wants, it seems this device just doesn’t update consistently when it’s in this power saving mode.

We also use Google location sharing, so I went ahead and set that up in HA. But that seems to have the same issue on this device. But what I found interesting is, although both Life360 and Google location sharing both seem to “drop out” from time to time, they don’t seem to do it at the same time. Very often while one has decided to stop for a while, the other seems to update ok, and vice versa.

So I created an automation that updates a virtual, composite entity whenever one of these two real device_tracker entities updates, and this seems to work very well for this phone that is mostly in power saver mode. (I say “virtual”, because the device_tracker entity is created via the device_tracker.see service, even though there’s no corresponding entity created via config entries. Otherwise it’s just like any other device_tracker. There’s even an entry in known_devices.yaml for it.)

I’m thinking about creating a new, “composite” device_tracker platform to do what I’m currently doing via the automation. Just wondering if there’s already a typical way this is handled whereby I wouldn’t have to do that.

BTW, I’m looking for something that creates an actual device_tracker entity, with GPS coordinates, not just something that combines home/not_home status.

1 Like

I’m in hopefully for an answer for this too. I can’t get device_tracker.see to accept any GPS coordinates. It doesn’t matter what I enter for that field I get an error message that states:

Invalid service data for device_tracker.see: None for dictionary value @ data[‘gps’]. Got ‘51.509802, -0.086692’

Yes I’ve tried it with [ ] too… same error.

I ended up creating a custom “composite” device tracker platform. (See this topic.) You might find that interesting.

Regarding your question, can you post your automation or script that is trying to call device_tracker.see? I may be able to spot the problem. For reference, this is what I had done:

  - alias: Composite Tracker
    trigger:
      platform: state
      entity_id:
        - device_tracker.ONE
        - device_tracker.TWO
    action:
      - condition: template
        value_template: >
          {% set old = as_timestamp(state_attr('device_tracker.COMOSITE','last_seen')) %}
          {% set new = as_timestamp(trigger.to_state.attributes.last_seen) %}
          {{ old == none or new > old }}
      - service: device_tracker.see
        data_template:
          dev_id: COMPOSITE
          gps:
            - "{{ trigger.to_state.attributes.latitude }}"
            - "{{ trigger.to_state.attributes.longitude }}"
          gps_accuracy: "{{ trigger.to_state.attributes.gps_accuracy }}"
          battery: >
            {% if 'battery' in trigger.to_state.attributes %}
              {{ trigger.to_state.attributes.battery }}
            {% else %}
              {% set battery = state_attr('device_tracker.COMPOSITE','battery') %}
              {% if battery != none %}
                {{ battery }}
              {% else %}
                0
              {% endif %}
            {% endif %}
          attributes:
            last_seen: >
              {{ as_timestamp(trigger.to_state.attributes.last_seen)|timestamp_local }}
3 Likes

I think you can attach a MAC address to any device tracker device. I believe home assistant tries to marry them together into a single device. I read that somewhere, do not know if it’s true. I usually just build a template sensor that combines them “manually”.

Yes, I know you can combine one or more network based trackers with a GPS based tracker (although I never tried it because I don’t use any network based trackers.) But the way I read the code, you can’t really do that with multiple GPS based trackers. The problem is the code of the GPS based tracker platform(s) would have to report the MAC address for the tracker component code to match it to other devices with the same MAC address, but GPS based trackers (AFAIK) do not report MAC address - only network based trackers do. And just adding the MAC to the GPS based entries in known_devices.yaml is not good enough. But, I could be wrong; haven’t really tried it.

I agree that a template sensor that combines multiple GPS based trackers might work for some, or even most, things I would think. But I don’t think it would/could show up on the map. But, honestly, I never tried it.

Good ideas, and thanks for you feedback. But so far I still think a composite device tracker platform suits my needs better. Although, I should probably give it some more thought…

1 Like

I’m pretty sure they won’t show up on the map. I just use it as a reference in other automations, so it’s hidden for me.

The only other way that could work better would be a custom component. But who has time for that.

1 Like

I created something for the exact same use case using automations and JSON MQTT device tracker to combine Google, Life360, ping, and bluetooth. For Google and Life360, I just use the latest state change. For ping and bluetooth, I only use the home state with my home zone’s GPS coordinates. The accuracy of my presence data has been much better since implementing this solution.

device_tracker:
  - platform: mqtt_json
    devices:
      person1_presence: location/person1

automations:
  - alias: Person1 Presence Update from GPS
    trigger:
    - platform: state
      entity_id:
        - device_tracker.person1_google
        - device_tracker.person1_life360
    action:
      - service: mqtt.publish
        data_template:
          topic: "location/person1"
          retain: true
          payload: >-
            {
              "latitude": "{{ trigger.to_state.attributes.latitude }}",
              "longitude": "{{ trigger.to_state.attributes.longitude }}",
              "gps_accuracy": {{ trigger.to_state.attributes.gps_accuracy | int }}
            }

  - alias: Person1 Presence Update from Router or Bluetooth
    trigger:
    - platform: state
      entity_id:
        - device_tracker.person1_ping
        - device_tracker.person1_bt
      to: home
    action:
      - service: mqtt.publish
        data_template:
          topic: "location/person1"
          retain: true
          payload: >-
            {
              "latitude": "{{ states.zone.home.attributes.latitude }}",
              "longitude": "{{ states.zone.home.attributes.longitude }}",
              "gps_accuracy": 0
            }

I’m using Node RED but this was exactly what I was looking for - I needed to format my payload with the GPS tag using [ ] instead of { }… weird way to do it and it’s not well covered anywhere but this has it working perfectly.