How to create a location sensor, or device_tracker, from separate sensor values

I have (separate) sensors that return my car’s longitude, latitude and altitude. How can I define a sensor, or a device_tracker, entity based on these values that can be used wherever a device_tracker entity can be used? I had something like this a while ago which seemed to work but now HA says that the entity is no longer being provided by the template integration…

template:
   - sensor:
       - unique_id: car_location
         name: car_location
         state: not_home
         attributes:
           latitude: >-
             {{ states('sensor.car_location_latitude')|float(0) }}
           longitude: >-
             {{ states('sensor.car_location_longitude')|float(0) }}
           altitude: >-
             {{ states('sensor.car_location_altitude')|float(0) }}

Check configuration does not complain about anything and the values for the individual sensors are correct and are being updated.

Use the device tracker.see service (action).

1 Like

I don’t understand how I would do that though. Surely I would need an existing device_tracker for the car, and I do not have one. The documentation for ‘device_tracker’ that you pointed me at is not very clear as to how I would create a ‘dummy’ device tracker entity that I could then update using device_tracker.see. Do you have actual working code examples?

I don’t currently use it, but used it before.

When you call that action it will create the device tracker.

action: device_tracker.see
data:
  dev_id: "my_car"
  gps: 
    - "{{ states('sensor.car_location_latitude') }}"
    - "{{ states('sensor.car_location_longitude') }}"

You can typically use this in an automation:

trigger:
  - platform: state
    entity_id: 
      - sensor.car_location_latitude
      - sensor.car_location_longitude
action:
  - action: device_tracker.see
    data:
      dev_id: "my_car"
      gps: 
        - "{{ states('sensor.car_location_latitude') }}"
        - "{{ states('sensor.car_location_longitude') }}"
1 Like

Thanks you, that was very helpful. I have it working now, with an automation to update it whenever the car’s location changes.

1 Like

An item to consider is how to remove the jumpy updates. Meaning when the inputs both change, the automation will run twice and it’s likely that device.see will be using the new value for latitude and the old value for longitude (or vv depending on the order they get updated). On the second run it’ll update the other element and the position will be correct.

You should be able to see this behavior in the automation traces. If not, then all is good.

If so, then adding a short delay to the automation may allow enough time to elapse for the other sensor to update.

1 Like