Attributes latitude and longitude in a lovelace map

Hi, hope you can help me …

from a custom integration I’ve got a sensor containing numerous attributes. Two of these attributes are latitude and longitude:

Finally I would like to show the device location on a map in lovelace.
Since I did not find a way to directly use the attributes in a map card, I thought about creating a template sensor. But I did not find any proposals for this.

Is there anyone able to help me ?

Cheers, red

1 Like

You need to create a device tracker with device tracker template.
The device tracker is then what needs to be displayed on the map.

Assuming you have tried to add the sensor to the map already?

Not sure if this helps you or not, I have explored both device trackers and sensors with geo coding. The first picture below shows the resulting lovelace maps generated by each type of HA entity, the yaml code for each map is below. From my experience, if you add the attributes with the spelling shown below to a sensor, you can place it on a lovelace map as it shown below. You have different spelling, you might try changing those :

latitude: 54.0342230000
longitude: -107.1700410000
      - type: map
        entities:
          - entity: device_tracker.iphonexi
        hours_to_show: 48

      # - break

      - type: map
        entities:
          - entity: sensor.pulsepoint_sbco
          - entity: sensor.pulsepoint_sbci
          - entity: sensor.pulsepoint_mont
          - entity: sensor.pulsepoint_carp
          - entity: sensor.pulsepoint_vent
          - entity: sensor.pulsepoint_sber
          - entity: sensor.pulsepoint_sopa
          - entity: sensor.pulsepoint_pasa

          - entity: sensor.pulsepoint_redl
          - entity: sensor.pulsepoint_esco

Have a look here, using the device_tracker.see service you can create a device_tracker from 2 sensors

expanding what @dproffer said…

Make a template sensor with the 2 attributes and you should be good to go. Unfortunately you can’t copy and paste this because you’ve burred out the entity_id… which doesn’t make sense by the way. Knowing the entity_id isn’t going to give anyone information about your system that they can use to be malicious.

template:
- sensor:
  - name: imow blurry lawnmower
    state: "{{ state_attr('sensor.imow_blurry_battery_level', 'machine_state') }}"
    attributes:
      latitude: "{{ state_attr('sensor.imow_blurry_battery_level', 'coordinateLatitude')  }}"
      longitude: "{{ state_attr('sensor.imow_blurry_battery_level', 'coordinateLongitude') }}"

Then just put the sensor sensor.imow_blurry_lawnmower into a map card.

1 Like

Perhaps it was a swear word he blurred out to not make the images offensive :man_shrugging:

Hello guys,

first of all thanks for your quick and constructive feedback from all of you!
Finally I was looking for a simple solution. @petro, your solution really looks the best and it’s what I already tried before (more or less) … but seems that I had a syntax error somewhere.

Background: I put all my sensors into sensors.yaml, which looks like this:

- platform: template
  sensors:
    # dyson sensors
      ...
    # iMow sensors
      ...
    imow_device_tracker:
      state: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'machine_state') }}"
      attributes:
        latitude: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'coordinateLatitude') }}"
        longitude: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'coordinateLongitude') }}"

Other sensors from this yaml file work, something seems still to be wrong with the tracker sensor. Do you have any idea for me?

PS: Sorry I am no expert in yaml … sometimes I get a little confused when to use a dash and when not etc.

Cheers, red

yap, something like that :slight_smile:

That’s the old template format. If you copy/paste exactly what I wrote into configuration.yaml, then it’ll work. Do not paste it into the old format as the 2 formats do not work together.

template:
- sensor:
  - name: imow rmi422pc lawnmower
    state: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'machine_state') }}"
    attributes:
      latitude: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'coordinateLatitude')  }}"
      longitude: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'coordinateLongitude') }}"
1 Like

Hi @petro, thanks for your recommendation !!

what does “old” or “new template format” mean? Did I miss anything that there are different formats available? Do you have a reference for me where I can learn more about?

BTW: I just got it working with my separate sensors.yaml file which I have included in configuration.yaml. So I would like to keep the template sensors outsourced from my configuration.yaml. The result for my imow sensor looks like this and perfectly works :-).

- platform: template
  sensors:
    # dyson sensors
      ...
    # iMow sensors
      ...
    imow_device_tracker:
      friendly_name: "iMow position"
      value_template: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'machine_state') }}"
      attribute_templates:
        latitude: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'coordinateLatitude') }}"
        longitude: "{{ state_attr('sensor.imow_rmi422pc_battery_level', 'coordinateLongitude') }}"

Thanks so much and kind regards, red

It’s all covered in the template integration docs

2 Likes

Thanks for this thread.

1 Like