MQTT device tracker lat/long attributes help

Hi!

I am trying to create a device tracker for my car.

Followed documentation and created these lines, but the sensor does not have lat/long attributes.

mqtt:
  device_tracker:
    - name: "GWM ORA App tracker 2"
      state_topic: "GWM/726148.....53d"
      source_type: gps
      json_attributes_topic: "GWM/726148.....53d/status"

MQTT topic from car looks like this:
image

Please help me out :slight_smile:

Try it without the state_topic.

Unfortunately did not help.

Found solution:

mqtt:
  device_tracker:
    - name: "GWM ORA App tracker"
      json_attributes_topic: "GWM/tracker"
      json_attributes_template: >
        {"latitude": {{ states('sensor.gwm_ora_app_latitude') | float }},"longitude": {{ states('sensor.gwm_ora_app_longitude') | float }} }
      payload_home: "home"
      payload_not_home: "not_home"

Um, where are these coming from?

Did you create two more mqtt sensors?

That is not how the json_attributes_template should be used.

And where did this topic come from?

It is not the one shown in your screen shot from earlier.

You are right, my post about solution was incomplete :slight_smile:

Created automation to publish to topic “GWM/tracker”

service: mqtt.publish
data:
  topic: GWM/tracker
  payload: |-
    {
      "latitude": {{ states('sensor.gwm_ora_app_latitude') | float }},
      "longitude": {{ states('sensor.gwm_ora_app_longitude') | float }},
    }

I can see now, that “{{ states('sensor.gwm_ora_app…}}” is repeated in both codes.
I am sure there is a “right” way, but it works (for now).

Since you’re not actually using anything you got from mqtt, and you are also not using any data that you published on mqtt, why did you not simply use the device_tracker.see service? It creates the device tracker if there isn’t one.

mqtt:
  device_tracker:
    - name: "GWM ORA App tracker 2"
      state_topic: "GWM/726148.....53d"
      source_type: gps
      json_attributes_topic: "GWM/726148.....53d/status"
      json_attributes_template: "{{ dict(latitude=value_json.Latitude, longitude=value_json.Longitude) }}"

No need for axuilary entities.

2 Likes

Thank you!

Because I am really stumbling in the dark here :smiley: