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!