Distance in Meters between 2 device trackers

Hello everyone,

I would like some help to get accurate distance between 2 device trackers. I would like to use this in an automation to automatically lock my car and send a notification when i move more than 10 meters away from it. I found a ninja template as follows:

{{ distance('device_tracker.me', 'device_tracker.car') }}

While the above works, it gives me a distance of 0.08 while i am more than 100 meters away. Any suggestions?

Thank you
M

Hi,

try this.

- sensor:
    - name: "Entfernung Person1-Person2"
      icon: mdi:map-marker-distance
      unit_of_measurement: "m"
      state: "{{ (distance ('person.person1', 'person.person2') * 1000) | float | round(2) }} "

As suggested above, distance is in km, not m. But also it is not likely you will reach the accuracy you want. Both the car position and yours are not always perfect. Also, updates are not immediate, so unless you are both stationary you would need to account for difference of either position in time too. You can find more about GPS accuracy, and reasons why it is not always maximum accuracy here:
GPS.gov: GPS Accuracy.

I noticed “distance” is always off from the one that google maps provides, e.g. over a length of 6km about 20-40m, I have little to compare as to which one comes closer to the truth

Guys I would like to thank you fir support.

The sensor that Moss provided above works and gives the correct value.

Edwin’s comment is also true. Leaving from the car doesn’t automatically lock it. When you are stationary the home assistant app updates the location and that’s when the automation triggers. You can be many kilometers away until it finally updates the location.

For now, I just set a notification to be received if the car is unlocked for testing purposes.

While it is not ideal, for now it will do.

Thank you all very much