Difficulties in replicating device_tracker.see functionalities in new Template device tracker

Hi everyone, starting from June release, Template entities support the device tracker platform since device_tracker.see is deprecated. Sadly I am not able to replicate the flexibility/customizability of device_tracker.see.
E.g.:

  1. I was able to value device_tracker.see state with output of different sensors. E.g. my wife and I have a common car, so I was populating my device_tracker.see with the gps coordinates of the last person that used that car in order to save the parking position once Androdi Auto connection dropped off. Then I was able to visualize on phone dashboard the position of the car (so no matter who parked it).
    My automation was as follow (and I have the same automation for my wife Android Auto sensor that works on the same device_tracker.see):
alias: Car_Parking position
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.my_phone_android_auto
    from: "on"
    to: "off"
actions:
  - action: device_tracker.see
    metadata: {}
    data:
      dev_id: car_parking_location
      gps_accuracy: 10
      gps:
        - >-
          {{ state_attr('device_tracker.my_phone','latitude') | float(0)
          }}
        - >-
          {{ state_attr('device_tracker.my_phone','longitude') | float(0)
          }}
      source_type: gps
      attributes:
        friendly_name: Car parking location
        icon: mdi:car
        parking_time: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
mode: single
  1. I was able to value device_tracker.see "location_name" with a variable (as result of templating) in order to get the state home/not_home:
alias: Smartphone_Tracker Wi-Fi
triggers:
  - trigger: state
    entity_id:
      - sensor.my_smartphone_wi_fi_connection
    to: null
actions:
  - variables:
      tracker: "{{ trigger.from_state.object_id }}"
      zone: >
        {% set zone =
          [
            {'ssid': '', 'zone': 'not_home'},
            {'ssid': 'My Home', 'zone': 'home'}
          ]
        %} {{zone | selectattr('ssid', 'eq', trigger.to_state.state) |
        map(attribute='zone') | first | default('not_home')}}
  - action: device_tracker.see
    metadata: {}
    data:
      dev_id: "{{tracker}}"
      location_name: "{{zone}}"
mode: single

e.g. I tried the follow without success:

template:
  - device_tracker:
      - name: Smartphone_Tracker Wi-Fi
        unique_id: smartphone_tracker_wi_fi
        icon: mdi:cellphone-wireless
        in_zones: >
          {% if is_state('sensor.my_phone_wi_fi_connection', 'My House') %}
            home
          {% else %}
            not_home
          {% endif %}

Please format your configuration with proper indentation.

It seems like you have misunderstood how in_zones works. The values need to be the entity ID of the Zone.

To emulate what device_tracker.see did you will need to use a Trigger-based Template device tracker.

If you just use this, it will say Home or Away depending if the binary_sensor is on or off and the lat and lon will be in the device_tracker

You'll need to change the zone name to suit

template:
  - device_tracker:
      - name: Smartphone_Tracker Wi-Fi
        unique_id: smartphone_tracker_wi_fi
        icon: mdi:cellphone-wireless
        latitude: "{{ state_attr('device_tracker.my_phone','latitude') | float(0) }}"
        longitude: "{{ state_attr('device_tracker.my_phone','longitude') | float(0) }}"
        in_zones: >
          {% if states('binary_sensor.my_phone_android_auto') == 'on' %}
            ['zone.home']
          {% else %}
            ['']
          {% endif %}

First one is this

template:
- triggers:
   - trigger: state
     entity_id: binary_sensor.my_phone_android_auto
     from: "on"
     to: "off"
  device_tracker:
  - name: Car Parking Location
    default_entity_id: device_tracker.car_parking_location
    latitude: "{{ state_attr('device_tracker.my_phone','latitude') }}"
    longitude: "{{ state_attr('device_tracker.my_phone','longitude') }}"
    location_accuracy: 10

Second one needs extra finess, I'll come back later if someone else doesn't respond

Well, the logic I would implement is a little different: it is not basing on gps coordinate, but using the phone sensor when connected to a determined wifi network.
E.g. if the "sensor.my_smartphone_wi_fi_connection" indicates being connected to "My Home" ssid then the state of the device tracker should be "home", otherwise "not home"

Thank you for that, I saw it was in the documentation but probably I committed som errors.
So considering two binary sensors as trigger it should be:

template:
  - triggers:
      - trigger: state
        entity_id: binary_sensor.husband_phone_android_auto
        from: "on"
        to: "off"
        id: husband
      - trigger: state
        entity_id: binary_sensor.wife_phone_android_auto
        from: "on"
        to: "off"
        id: wife
    device_tracker:
      - name: Car Parking Location
        default_entity_id: device_tracker.car_parking_location
        latitude: >
          {% if trigger.id == 'husband' %}
            {{ state_attr('device_tracker.husband_phone','latitude') }}
          {% else %}
            {{ state_attr('device_tracker.wife_phone','latitude') }}
          {% endif %}
        longitude: >
          {% if trigger.id == 'husband' %}
            {{ state_attr('device_tracker.husband_phone','longitude') }}
          {% else %}
            {{ state_attr('device_tracker.wife_phone','longitude') }}
          {% endif %}
        location_accuracy: 10

sure, there's a number of ways to tackle that. But yes, that would work.

and I think I solved the second one:

template:
  - device_tracker:
      - name: Smartphone_Tracker Wi-Fi
        in_zones: >
          {% if states('sensor.my_smartphone_wi_fi_connection') == 'My Home' %}
            {{ ['zone.home'] }}
          {% else %}
            {{ [] }}
          {% endif %}

Regarding the android auto based location, do note that as template device trackers do not restore state, you'll loose the state if you restart HA while the car is parked.

So if you're wife parks the car somewhere, while you are home working on HA and perform a restart, the template device_tracker will become unknown

To work around this, you could create a template sensor to store the coordinates, as the template sensor will restore state, and then use the template sensor for the template device_tracker. However, you might see there will be no need for the device_tracker, as a template sensor with a longitude and latitude attribute works quite similar as a device tracker and also shows on the map just fine.

Right now I configured it as described above, but I'll probably get rid of the device tracker soon.
This is my config at the moment:

I used trigger variables instead of an jinja if statement.
I also added an action to force a location update in the mobile app.

  - triggers:
      - alias: "Martijn disconnected from Android Auto"
        trigger: state
        entity_id: binary_sensor.pixel_10_pro_android_auto
        from: "on"
        to: "off"
        variables:
          notify_action: notify.mobile_app_pixel_10_pro
          geocoded: sensor.pixel_10_pro_geocoded_location
          device_tracker: device_tracker.pixel_10_pro_3
      - alias: "Girlfriend disconnected from Android Auto"
        trigger: state
        entity_id: binary_sensor.girlfriend_carplay_connected
        from: "on"
        to: "off"
        variables:
          notify_action: notify.mobile_app_iphone_girlfriend
          geocoded: sensor.iphone_girlfriend_geocoded_location
          device_tracker: device_tracker.iphone_girlfriend
    actions:
      - action: "{{ notify_action }}"
        data:
          message: "request_location_update"
      - delay:
          seconds: 3
    sensor:
      - unique_id: 9c9da226-77f1-4366-9d0a-c778941fd61b
        name: Car Geocoded Location
        state: "{{ states(geocoded) }}"
        attributes:
          latitude: "{{ state_attr(device_tracker, 'latitude') }}"
          longitude: "{{ state_attr(device_tracker, 'longitude') }}"
          gps_accuracy: "{{ state_attr(device_tracker, 'gps_accuracy') }}"
  - device_tracker:
      - unique_id: 4c9495e8-e731-4597-ba01-6e5318789e55
        name: Car Location
        icon: mdi:car
        latitude: "{{ state_attr('sensor.car_geocoded_location', 'latitude') }}"
        longitude: "{{ state_attr('sensor.car_geocoded_location', 'longitude') }}"
        location_accuracy: "{{ state_attr('sensor.car_geocoded_location', 'gps_accuracy') }}"
        availability: "{{ 'sensor.car_geocoded_location' | has_value }}"

It sounds a pretty smart solution... thank you!

I’m having some issues adding a template device tracker through the UI.

Here’s my config:

…and I get this error in the logs:

Logger: homeassistant.components.template.validators
Source: components/template/validators.py:39
Integration: Template (documentation, issues)
First occurred: 11:46:43 AM (24 occurrences)
Last logged: 3:56:14 PM

Received invalid in_zones: zone.test_location for entity Test Location, expected a list of zone entity_ids
Received invalid device_tracker in_zones: zone.test_location for entity device_tracker.test_location, expected a list of zone entity_ids
Received invalid in_zones: ztest_location for entity Test Location, expected a list of zone entity_ids
Received invalid in_zones: test_location for entity Test Location, expected a list of zone entity_ids
Received invalid in_zones: for entity Test Location, expected a list of zone entity_ids

The entity zone.test_location is valid, and is quite large with the exact latitude and longitude expressed in the template config.

Any ideas what I’ve done incorrectly? I have another template device tracker for my home location, and it doesn’t throw any errors.

Your “Zones” template doesn’t return a list… like the error says.

{{ ['zone.test_location'] }}

Ahh, OK. I need an array. Thanks!

That’s a horrible decision to remove working functionality and replace it with less reliable behavior.

I was actually caught by this.

I thought that my new template device tracker wasn’t working at all because it seemed that every time I looked at it the state was always ‘unknown’. then after I wrote up a nice long post asking for help on what I was doing wrong because it “didn’t work” I just happened to click on the “your post is similar to…” link and found this info.

Looking back at the history I do see that it kind of works tho so there’s that.

Is this going to ever be changed to be restored on a restart like the other template sensors as you suggested using?

I still don’t think things are working correctly tho so I may still need to post up a request for help anyway. I’ll have to do some more troubleshooting since I now know that I’m at least part way there.

lastly is there a way to remove the old device tracker created by the device_tracker.see service? right now I have two device trackers with the same entity_id but with _2 appended to the new templated one. And I don’t see anywhere to be able to remove that old device tracker.

It has been fixed in one of the last releases. Template device trackers do restore state now!

Is that change only in the latest release?

I’m on 2026.8.3 and I believe I’m seeing that it still isn’t restoring after a restart.

If it isn’t restoring state, your template is replacing the value at startup. It was added in 2026.7 or 8, I can’t remember which version I added it in. 2026.9 added attribute templates to all entities so I think restore state was right before that

Here is the template. Maybe I can’t see the error:

  - triggers:
      - platform: state
        entity_id: sensor.my_mobile_app_bluetooth_connection
      - platform: state
        entity_id: person.me
        to: 'home'
    device_tracker:
      - name: Toyota Tundra
        unique_id: device_tracker_toyota_tundra
        latitude: >
          {% if trigger.entity_id == 'sensor.my_mobile_app_bluetooth_connection'
                and 'CC:57:63:68:4C:06 (TOYOTA Tundra)' in trigger.from_state.attributes.connected_paired_devices 
                and 'CC:57:63:68:4C:06 (TOYOTA Tundra)' not in trigger.to_state.attributes.connected_paired_devices %}
            {{ state_attr('device_tracker.my_mobile_app', 'latitude') }}
          {% elif trigger.entity_id == 'person.me'  %}
            {{  41.xxxxxx }}
          {% endif %}
        longitude: >
          {% if trigger.entity_id == 'sensor.my_mobile_app_bluetooth_connection'
                and 'CC:57:63:68:4C:06 (TOYOTA Tundra)' in trigger.from_state.attributes.connected_paired_devices 
                and 'CC:57:63:68:4C:06 (TOYOTA Tundra)' not in trigger.to_state.attributes.connected_paired_devices %}
            {{ state_attr('device_tracker.my_mobile_app', 'longitude') }}
          {% elif trigger.entity_id == 'person.me'  %}
            {{ -85.xxxxx }}
          {% endif %}

I only want it to update when I disconnect from the truck BT.

You might want to change the trigger to

      - platform: state
        entity_id: sensor.my_mobile_app_bluetooth_connection
        not_from: 
          - unavailable
          - unknown
        not_to:
          - unavailable
          - unknown

That will avoid it from triggering on a HA restart

And you can simplify your templates if you add a condition.

good point. I hadn’t checked that aspect.

But I just checked the trace and the BT connection sensor never shows as going “un…”. And I’ve restarted several times this morning already.

I went ahead and put it in JIC as it can’t hurt.

I don’t think I’ve never seen a way to check any “traces” from a trigger template sensor is there? If not that would be nice to actually see what might be happening.

as far as the condition I agree but I think (I think… :thinking:) the template works as is for now. I may revisit that later (but probably not… :smile:).