Cannot figure out device_tracker.see service [Solved]

Hi Andy,
Thanks to you, I am a little more further due to the fact that I had not set up mac, host name and gps accuracy.
I have called the device_tracker.see service by inserting the mac as well. I can now see the entity and mac but no plot on the map yet. Look forward to any suggestions.

Here is my configuration.yaml:
device_tracker:

  • platform: mqtt
    devices:
    civic_position_latitude: ‘civic/position/latitude’
    civic_position_longitude: ‘civic/position/longitude’
  • platform: mqtt
    devices:
    audi_position_latitude: ‘audi/position/latitude’
    audi_position_longitude: ‘audi/position/longitude’
  • platform: mqtt
    devices:
    crv_position_latitude: ‘crv/position/latitude’
    crv_position_longitude: ‘crv/position/longitude’
  • platform: mqtt
    devices:
    civic_position_latitude2: ‘civic/position/latitude2’
    civic_position_longitude2: ‘civic/position/longitude2’

Automations.yaml -

  • id: ‘1610996729565’
    alias: Update Civic position
    description: ‘’
    trigger:
    • platform: state
      entity_id: device_tracker.civic_position_latitude
    • platform: state
      entity_id: device_tracker.civic_position_longitude
      condition: []
      action:
    • service: device_tracker.see
      data:
      data:
      mac: FF:FF:EE:FF:EE:FE
      host_name: civic20152
      source_type: gps
      dev_id: civic20152
      gps:
      - ‘{{ states(’‘sensor.civic_position_latitude’’) }}’
      - ‘{{ states(’‘sensor.civic_position_longitude’’) }}’
      gps_accuracy: 20
      mode: single
  • id: ‘1611080901457’
    alias: Update Civic T2 Position
    description: ‘’
    trigger:
    • platform: state
      entity_id: device_tracker.civic_position_latitude2
    • platform: state
      entity_id: device_tracker.civic_position_longitude2
      condition: []
      action:
    • service: device_tracker.see
      data:
      data:
      mac: EE:EE:EE:FF:EE:21
      host_name: civic20153
      source_type: gps
      dev_id: civic20153
      gps:
      - ‘{{ states(’‘sensor.civic_position_latitude2’’) | float | round(7) }}’
      - ‘{{ states(’‘sensor.civic_position_longitude2’’) | float | round(7) }}’
      gps_accuracy: 20
      mode: single

Could be a syntax problem - can you repost your code with the preformatted text tag (</>)?
This is mine:

mac: 'FF:FF:FF:FF:FF:F7'
host_name: leaf2016
source_type: gps
dev_id: leaf2016
gps:
  - '{{ states(''sensor.leaf_position_lat'') | float | round(7) }}'
  - '{{ states(''sensor.leaf_position_lon'') | float | round(7) }}'
gps_accuracy: 20
battery: '{{ states(''sensor.leaf_soc'') | round(0) }}'

Update: I noticed that I didn’t used the device_tracker.leaf2016 on the map, I actually made a person named “leaf” and associated the leaf2016 device tracker to it.
I can see the person.leaf in the map.

1 Like
- id: '1610996729565'
  alias: Update Civic position
  description: ''
  trigger:
  - platform: state
    entity_id: device_tracker.civic_position_latitude
  - platform: state
    entity_id: device_tracker.civic_position_longitude
  condition: []
  action:
  - service: device_tracker.see
    data:
      data:
        mac: FF:FF:EE:FF:EE:FE
        host_name: civic20152
        source_type: gps
        dev_id: civic20152
        gps:
        - '{{ states(''sensor.civic_position_latitude'') }}'
        - '{{ states(''sensor.civic_position_longitude'') }}'
        gps_accuracy: 20
  mode: single
- id: '1611080901457'
  alias: Update Civic T2 Position
  description: ''
  trigger:
  - platform: state
    entity_id: device_tracker.civic_position_latitude2
  - platform: state
    entity_id: device_tracker.civic_position_longitude2
  condition: []
  action:
  - service: device_tracker.see
    data:
      mac: EE:EE:EE:FF:EE:21
      host_name: civic20153
      source_type: gps
      dev_id: civic20153
      gps:
      - '{{ states(''sensor.civic_position_latitude2'') | float | round(7) }}'
      - '{{ states(''sensor.civic_position_longitude2'') | float | round(7) }}'
      gps_accuracy: 20
  mode: single

Uhm, what I don’t understand in your code is the trigger. Why do you use DEVICE_TRACKER.civic_position_* ? Shouldn’t be SENSOR.civic_position_* ?
The positional attributes of the device_tracker are fictional (you actually update them manually with this very automation) so you need to trigger the update whenever the sensors on you car change value.

Hi Andy,

I have amended the code. However the automation is not being triggered since I made that change. Here is the current configuration and automation. This has been a real head scratcher…

device_tracker:
  - platform: mqtt
    devices:
      civic_position_latitude: 'civic/position/latitude'
      civic_position_longitude: 'civic/position/longitude'
  - platform: mqtt
    devices:
      civic_position_latitude2: 'civic/position/latitude2'
      civic_position_longitude2: 'civic/position/longitude2'

- id: '1610996729565'
  alias: Update Civic position
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.civic_position_latitude
  - platform: state
    entity_id: sensor.civic_position_longitude
  condition: []
  action:
  - service: device_tracker.see
    data:
      mac: FF:FF:EE:FF:EE:FE
      host_name: civic20152
      source_type: gps
      dev_id: civic20152
      gps:
      - '{{ states(''sensor.civic_position_latitude'') | float | round(7) }}'
      - '{{ states(''sensor.civic_position_longitude'') | float | round(7) }}'
      gps_accuracy: 20
      battery: 100
  mode: single
- id: '1611080901457'
  alias: Update Civic T2 Position
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.civic_position_latitude2
  - platform: state
    entity_id: sensor.civic_position_longitude2
  condition: []
  action:
  - service: device_tracker.see
    data:
      mac: EE:EE:EE:FF:EE:21
      host_name: civic20153
      source_type: gps
      dev_id: civic20153
      gps:
      - '{{ states(''sensor.civic_position_latitude2'') | float | round(7) }}'
      - '{{ states(''sensor.civic_position_longitude2'') | float | round(7) }}'
      gps_accuracy: 20
      battery: 100
  mode: single

You are missing automation: at the top of the automation.

I have now got this to work correctly. This is because I had not defined sensors correctly in configuration.yaml
Thank you for your assistance. I am including my set up for reference purposes:
Configuration.yaml:

sensor:
  - platform: mqtt
    state_topic: "civic/position/latitude"
    name: civic position lat
  - platform: mqtt
    state_topic: "civic/position/longitude"
    name: civic position longitude
  - platform: mqtt

automations.yaml

- id: '1611426245259'
  alias: NA4
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.civic_position_lat
  - platform: state
    entity_id: sensor.civic_position_longitude
  condition: []
  action:
  - service: device_tracker.see
    data:
      mac: AA:AA:AA:AA:AA:AA
      host_name: civic
      source_type: gps
      dev_id: civic
      gps:
      - '{{ states(''sensor.civic_position_lat'') }}'
      - '{{ states(''sensor.civic_position_longitude'') }}'
      gps_accuracy: 20
      battery: 100
  mode: single

/config/known.devices.yaml:

civic:
  name: civic
  mac: AA:AA:AA:AA:AA:AA
  icon:
  picture:
  track: true

hi
i have a similar problem
i receive the json data
{“sensor”:“gps”}{“time”:10580500}[{“longitude”:-9.546621},{“latitude”:50.34518}

and i try to show on a map card

this is my configuration.yaml

  - platform: mqtt
    name: "Garua GPS Time"
    state_topic: "datos_gps/sensor/garua/state"
    unit_of_measurement: "s"
    value_template: "{{ value_json.time }}"
  - platform: mqtt
    name: "Garua GPS Latitude"
    state_topic: "datos_gps/sensor/garua/state"
    unit_of_measurement: "°"
    value_template: "{{ value_json.latitude }}"
  - platform: mqtt
    name: "Garua GPS Longitude"
    state_topic: "datos_gps/sensor/garua/state"
    unit_of_measurement: "°"
    value_template: "{{ value_json.longitude }}"



this my automations.yaml file

- id: my_gpsdata
  alias: 'Update Leaf position'
  trigger:
  - platform: state
    entity_id:  sensor.garua_gps_latitude
  - platform: state
    entity_id: sensor.garua_gps_longitude
  condition: []
  action:
# Linea 184
  - service: device_tracker.see
    data:
      mac: AA:AA:AA:AA:AA:AA
      host_name: barco
      dev_id: barco
      source_type: gps
      gps:
      - '{{ states(''sensor.garua_gps_latitude'') }}'
      - '{{ states(''sensor.garua_gps_longitude'') }}'
  mode: single




i have an error when i try the code

Dont think that should be there ?

{“sensor”:“gps”}{“time”:10580500}[{“longitude”:-9.546621},{“latitude”:50.34518}

You have a [ in the middle there…
That suggests to me that is an array.
What does your sensors look like? Do they show lat and lon?
Remember to mask the real data

sorry this line is commented
i reedit the code

this is the entity in the states page

[sensor.garua_gps_latitude]     50.34518       unit_of_measurement: ° 
                                                                       friendly_name: Garua GPS Latitude

That makes no sense. Because the json you say you get is not valid.

This is valid:

{"sensor":"gps"},{"time":10580500},[{"longitude":-9.546621},{"latitude":50.34518}]

Notice there is commas between the values and a ending ]
And this is also valid:

{"sensor":"gps"},{"time":10580500},{"longitude":-9.546621},{"latitude":50.34518}

But in order to get lon and lat you would need to access item [2][“longitude”]

or if there should be [ ] also [2][0][“longitude”]

If the json looks like this:

{"sensor":"gps","time":10580500,"longitude":-9.546621,"latitude":50.34518}

Then it would make sense.

this is my new json

[{"sensor":"gps"},{"longitude":-7.65456},{"latitude":50.64512}]

but now my sensor can’t see the value data

imagen

this are my data parser from json, and i try to show in a map

There is no way to see the gps data received on the map
Does anybody have an idea?

Invalid config for [automation]: [action] is an invalid option for [automation]. Check: automation->trigger->0->action.

my configuration.yaml is not valid

automation:
  - trigger:
      platform: state
      entity_id: sensor.kia_position_lat, sensor.kia_position_long
      action:
        service: device_tracker.see
        data_template:
          dev_id: ship
          gps:
            - "{{ states('sensor.kia_position_lat') }}"
            - "{{ states('sensor.kia_position_long') }}"

You have indentation errors.
Action is not a part of trigger.

1 Like

Thank you
it’s running fine