How do I get location details of my car from latitude longitude attributes?

Hi,

I am a beginner to templates and creating new sensors, so I need some help.

My Goal : I have integrated Mercedes Me and now have an entity which has latitude and longitude as Attributes. On the logbook it displays Home, Work, other but I want it to specify the address of “other”, just like how I can track my Phone by address.

What I tried to do unsuccessfully : Created a template sensor but pulling out the Latitude and Logitude. Then used an automation using “device_tracker.see”. I did this based on this thread - Cannot figure out device_tracker.see service [Solved]

carlat:

    friendly_name: "Car Latitude"

    unit_of_measurement: ''

    value_template: "{{ state_attr('device_tracker.w1kcg2db8paXXXXX_device_tracker', 'latitude') }}"

    unique_id: carlatitude

  carlong:

    friendly_name: "Car Longitude"

    unit_of_measurement: ''

    value_template: "{{ state_attr('device_tracker.w1kcg2db8paXXXXXX_device_tracker', 'longitude') }}"

    unique_id: carlongitude
- id: '1123234243000024'

  alias: Device Tracker

  description: ''

  trigger:

  - platform: state

    entity_id: sensor.carlat, sensor.carlong

  action:

  - service: device_tracker.see

    data_template:

      gps:

        - "{{ states('sensor.carlat') }}"

        - "{{ states('sensor.carlong') }}"

  mode: single

What am I doing wrong??

What is going wrong? Is it just that you’re not getting an address? I’m guessing that on your phone you’re using the companion app, and that does send an address. It’s not a function of all device trackers.

Regardless, your “see” service call doesn’t look right, as it has no dev_id. I’m not sure what you’re wanting to do by copying the lat/long from “w1kcg2db8pa” into other entities, and then use them in a “see” call for another entity.

There is a HACS Places integration that can take a device tracker with gps and give you the address. You should be able to configure it with your “w1kcg2db8pa” (the car?) entity directly.

Your automation is missing a required configuration variable, and you are trying to make device_tracker.see do something it’s not really able to do. The first part is a pretty simple fix:

- id: '1123234243000024'
  alias: Device Tracker
  description: ''
  trigger:
  - platform: state
    entity_id: 
      - sensor.carlat
      - sensor.carlong
  action:
  - service: device_tracker.see
    data:
      dev_id: YOUR_DEVICES_OBJECT_ID
      gps: 
        - "{{ states('sensor.carlat') | float(0) }}"
        - "{{ states('sensor.carlong') | float(0) }}"
  mode: single

But that will not get you a street address. As mentioned by Michael, you will need to use Places or a different Reverse Geocode Location service like Google Geocode

Did you get a device_tracker at least? This is what I do:

service: device_tracker.see
data:
  mac: FF:FF:FF:FF:FF:F7
  host_name: [your device name here]
  source_type: gps
  dev_id: [your dev_id here]
  gps:
    - "{{ states('sensor.[your device]_lat') | float | round(7) }}"
    - "{{ states('sensor.[your device]_lon') | float | round(7) }}"
  gps_accuracy: 20
  battery: "{{ states('sensor.[device battery, if any]') | round(0) }}"

I am not 100% sure but I guess the MAC address, even if fake, was important.

For Host Name and Dev_id - Can I give any unique name or do I need to create them some place?

Just the name you want it to have as device_tracker.XXXXXX

The Host name is optional… if you don’t know what it is, don’t use that configuration variable.

The dev_id is required. As Andy already stated and the documents show, the dev_id is the object id of the device tracker entity you are trying to set. You can create a device tracker entity using known_devices.yaml. The device_tracker.see service will not create a new entity.

Be aware, if you use the device_tracker.see service on an device tracker that was created by another integration, it will only keep the value you set until it is updated by its own integration.

Hi there! It looks like you’re on the right track with your template sensors for Car Latitude and Car Longitude. However, for the issue with specifying the address for “other,” you may want to consider integrating a geocoding service in your automation. You can connect this with Shehu Rental Cars by extending the automation to include a service call to obtain the address using the latitude and longitude values. This will enhance the logbook entries and provide more detailed location information for “other” destinations. Keep exploring and feel free to reach out for more assistance!