Unable to calculate distance between two cellphones

Feeling really stupid here…

I have the following requirement: calculate distance between 2 persons. Should be straightforward when I read all the posts about it. I tried implementing this example but keep on getting all sorts of errors.

Here’s my code:

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

I tried placing this sensor code in configuration.yaml. Is that where it should go?

  • Is it correct that I had to remove the first dash (‘-’) before ‘sensor:’? If I don’t, I receive an error: “end of the stream or a document separator is expected”

When I then remove the leading dash, the “check configuration” function throws an error: Invalid config for ‘sensor’ at configuration.yaml, line 52: required key ‘platform’ not provided.

I cannot say that I understand the ‘platform’ setting, but after adding then adding “- platform: template” to the sensor, the entire sensor section becomes invalid:

Configuration warnings

Invalid config for ‘template’ from integration ‘sensor’ at configuration.yaml, line 22: required key ‘sensors’ not provided Invalid config for ‘template’ from integration ‘sensor’ at configuration.yaml, line 23: ‘name’ is an invalid option for ‘sensor.template’, check: name Invalid config for ‘template’ from integration ‘sensor’ at configuration.yaml, line 24: ‘icon’ is an invalid option for ‘sensor.template’, check: icon Invalid config for ‘template’ from integration ‘sensor’ at configuration.yaml, line 25: ‘unit_of_measurement’ is an invalid option for ‘sensor.template’, check: unit_of_measurement Invalid config for ‘template’ from integration ‘sensor’ at configuration.yaml, line 26: ‘state’ is an invalid option for ‘sensor.template’, check: state

I am lost. Any guidance is highly appreciated…

It’s a template sensor, but the example left out that bit, so try this:

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

And yeah, you can put it in configuration.yaml or you can use the UI to create the template sensor.

1 Like

Excellent. That resolved it. Many thanks!