device_tracker.see is being taken away, the intention to be replaced by a new template device_tracker[1]. In most situations this is a great idea, but I’m having trouble recreating an automation I had that used see previously.
Use case: To track the location where a vehicle was parked.
Previous solution: Use a legacy device tracker to keep track of the location of a car - when the occupancy of the car clears[2], copy (using see) the location of the driver to the legacy tracker.
The problem: GPS location updates are sometimes slow, so when the occupancy clears, we would like to “wait” for the next location of the driver before copying[3]. This is easily done in an automation using a wait trigger.
The closest equivalent I have come up with using the new template device tracker is the following (yes, it’s a blueprint)![]()
blueprint:
name: Vehicle Occupancy Device Tracker
description: Creates a sensor that automatically updates if someone leaves a vehicle
domain: template
input:
occupancy_sensor:
name: Occupancy Sensor
selector:
entity:
filter:
- domain: binary_sensor
source_device_tracker:
name: Source Device Tracker
selector:
entity:
filter:
- domain: device_tracker
variables:
source: !input source_device_tracker
trigger:
- platform: state
entity_id: !input occupancy_sensor
from: "on"
to: "off"
device_tracker:
latitude: "{{ state_attr(source, 'latitude') }}"
longitude: "{{ state_attr(source,'longitude') }}"
location_accuracy: "{{ state_attr(source, 'gps_accuracy') }}"
The issue is that the last known location is used, which tends to be stale. I’ve tried thinking of how to use last_updated/changed/reported but there’s no way to track the “next update” after a point (I imagine that there are no waits in a template).
The only approaches I can think of now are:
- Filter updates to the template using a boolean helper, and control that boolean via an automation (which would require a boolean helper per person-vehicle combination)
- To do away with the vehicle device trackers altogether and just use the appropriate driver’s location (in an alert, say) but I quite like the idea of having a vehicle device tracker in general
TL;DR: how can we be more discerning about when a template sensor should update?
[1]Device tracker changes in 2027.5... what to do? - #78 by seanomat
[2] a bluetooth connection (or lack thereof) is used to determine occupancy
[3] yes, it could be that the new location is equally incorrect (as the person has walked away), but given a person is slower than a car this is seen to be the better approach (especially if a “single accurate location” is requested at the appropriate time too).