Combine GPS sensors and show them on the map, with or without device tracker?

Hello all,

i am seeking help here, as i am not sure where exactly to start.

I want to add a device to the map and work with zones.
I am gettings the GPS information from a Car Dongle.

This is the sensors i am creating:

- platform: rest
  resource: "https://api-production.autoaid.de/cc/v0.1/status/vehicles/VIN5YXXXX"
  name: "GPS Position Lat -  Tesla X "
  scan_interval: 60
  force_update: true
  value_template: >
      {% for i in value_json.eventStatusList %}
          {% if i.eventType == 'POSITION' %}
           {{ i.eventData.lat }}
          {% endif %}
      {% endfor %}
  headers:
    Authorization: "XXXXXXX"
    content-language: "en_US"
- platform: rest
  resource: "https://api-production.autoaid.de/cc/v0.1/status/vehicles/VIN5YXXXX"
  name: "GPS Position Lon -  Tesla X "
  scan_interval: 60
  force_update: true
  value_template: >
      {% for i in value_json.eventStatusList %}
          {% if i.eventType == 'POSITION' %}
           {{ i.eventData.lon }}
          {% endif %}
      {% endfor %}
  headers:
    Authorization: "XXXXXXX"
    content-language: "en_US"

And here it starts, first i would ne need those two sensors into one sensor, i am not sure how to do that.

Now i need kind of a device tracker, but i do not have anything to track.
With the sensors i get the location every 60 second, how could i then let the position of the car been shown on the map

Also, i think there is a way to combine those two values into one sensor?

Can someone help here ?

Thanks in advance

You can use the device_tracker.see service to create a device_tracker entity from your two sensors. E.g.:

automation:
  - trigger:
      platform: state
      entity_id:
        - sensor.gps_position_lat_tesla_x
        - sensor.gps_position_lon_tesla_x
    action:
      - service: device_tracker.see
        data_template:
          dev_id: tesla_x
          gps:
            - {{ states('sensor.gps_position_lat_tesla_x') }}
            - {{ states('sensor.gps_position_lon_tesla_x') }}

Hi,

thanks for the answer If I try that, I getting the following error message, I am not sure what the issue is here, as I double checked the spelling etc.

Error Message:

Error loading /config/configuration.yaml: invalid key: “OrderedDict([(“states(‘sensor.gps_position_lat_tesla_x’)”, None)])”
in “/config/config/automation/device_test.yaml”, line 12, column 0

- alias: gps_status_x
  trigger:
    platform: state
    entity_id:
      - sensor.gps_position_lat_tesla_x
      - sensor.gps_position_lon_tesla_x
  action:
    - service: device_tracker.see
      data_template:
        dev_id: tesla_x
        gps:
          - {{ states('sensor.gps_position_lat_tesla_x') }}
          - {{ states('sensor.gps_position_lon_tesla_x') }}

Oops, my mistake. The templates need to be quoted. Try this instead:

- alias: gps_status_x
  trigger:
    platform: state
    entity_id:
      - sensor.gps_position_lat_tesla_x
      - sensor.gps_position_lon_tesla_x
  action:
    - service: device_tracker.see
      data_template:
        dev_id: tesla_x
        gps:
          - "{{ states('sensor.gps_position_lat_tesla_x') }}"
          - "{{ states('sensor.gps_position_lon_tesla_x') }}"
4 Likes

Hi,

again thanks for the answer.
This works now fine.

But what now ?
I do not see something on the Map.
Should there be another entity with is linked to the dev_id ?
How could I show the badges, and what entity is it, on the dashboard, car x is at zone x

That would be nice.
Right now I can see that the automation triggers, manually or automatically, but then i am not able to see anything else.
Or to work with…

Look on the Developers Tools -> States page. Do you see device_tracker.tesla_x listed? If so, do its latitude and longitude values look correct? Is it possible that the device is currently located within the Home zone (i.e., zone.home)? If it is, then it will not appear on the map. (This is standard behavior.) It will not appear until it is no longer in the Home zone.

1 Like

Ok, the automation did not run…

Log Details (ERROR)

Mon Nov 18 2019 19:28:41 GMT+0100 (Mitteleuropäische Normalzeit)

Error while executing automation automation.gps_status_x. Service not found for call_service at pos 1: Unable to find service device_tracker/see

But apart from that, the car should be right now in the home zone.
But I can change the car, which is not in the home zone

You probably need to add the following to your configuration:

device_tracker:
1 Like

Thats it.
Thanks!

I was not aware that I can enable it without giving info what to use for it

So, thanks a lot !

1 Like

I have to reopen this case kind of.
First it worked fine, now I added some more cars and now I get the following message and nothing is working anymore I do not know what to do here…

Log Details (ERROR)

Tue Nov 19 2019 09:47:30 GMT+0100 (Mitteleuropäische Normalzeit)

Error while executing automation automation.gps_status_881e_2. Invalid data for call_service at pos 1: invalid latitude for dictionary value @ data[‘gps’]

Fehler beim Aufrufen des Service device_tracker/see. expected dict for dictionary value @ data[‘service_data’]. Got ["{{ states(‘sensor.sube881e_gps_lat’) }}", “{{ states(‘sensor.sube881e_gps_lon’) }}”]

Please format error messages the same as you do for YAML code.

Also you should post the code you’re having trouble with. However, my guess is you used data: instead of data_template: in the service call.

1 Like

This looks very cool. I wonder if I can convince the significant other to increase our Home Assistant budget enough to get some new cars with built in GPS? :thinking:

1 Like

Hi,

sorry for formatting wrong:

im am using this automation:

- alias: gps_status_881e
  trigger:
    platform: state
    entity_id:
      - sensor.sube881e_gps_lat
      - sensor.sube881e_gps_lon
  action:
    - service: device_tracker.see
      data_template:
        dev_id: sube881e
        gps:
          - "{{ states('sensor.sube881e_gps_lat') }}"
          - "{{ states('sensor.sube881e_gps_lon') }}"

Like exactly as before.
The only thing is i put the automations in a folder. and linked it with the following command in the config file

automation: !include_dir_merge_list config/automation/

also device_tracker is enabled in the config.
It worked for a short time.

the file above is then called gps_881_zones.yaml

I also deleted the content of the known_devices file as there was a small hiccup with the names etc.
I rebooted the pi multiple time, but the known_devices file is not filled up again.

And what error are you getting now? (I’m guessing none, because I don’t think it’s even seeing/loading gps_881_zones.yaml.)

I should think:

automation: !include_dir_merge_list config/automation/

should be:

automation: !include_dir_merge_list automation/

I think it assumes config as the starting point.

1 Like

HI,

no this is working fine, I can see the automation and I can trigger them.

I can see the error message as stated above:

## Log Details (ERROR)

Tue Nov 19 2019 09:47:30 GMT+0100 (Mitteleuropäische Normalzeit)

Error while executing automation automation.gps_status_881e_2. Invalid data for call_service at pos 1: invalid latitude for dictionary value @ data[‘gps’]

Then the issue can only be that the state of sensor.sube881e_gps_lat is invalid. To be valid it must be a string representation of a number between -90 and 90, inclusive. Maybe this error is occurring at startup when sensor.sube881e_gps_lon gets created (which is triggering the automation) but before sensor.sube881e_gps_lat is created. That would cause "{{ states('sensor.sube881e_gps_lat') }}" to return 'unknown', which, of course, is not a valid number.

Maybe try this:

- alias: gps_status_881e
  trigger:
    platform: state
    entity_id:
      - sensor.sube881e_gps_lat
      - sensor.sube881e_gps_lon
  condition:
    condition: template
    value_template: >
      {{ states('sensor.sube881e_gps_lat') not in ('unknown', 'unavailable') and
         states('sensor.sube881e_gps_lon') not in ('unknown', 'unavailable') }}
  action:
    - service: device_tracker.see
      data_template:
        dev_id: sube881e
        gps:
          - "{{ states('sensor.sube881e_gps_lat') }}"
          - "{{ states('sensor.sube881e_gps_lon') }}"
1 Like

Hi,

sorry for my late answer.
And thanks for this brilliant piece of code.
But it is not working.

I get very good lat and long results.

Numbers like: lat 50.000000 and long 7.00000

So it is between the range of -90 and 90.

The Error message is still the exact same.
Maybe the Number is too long ? Not sure about this.
Also the very first try, which worked fine, does no longer work.
This is strange.

Does not one have an idea ?
I am really at the end of my little knowledge

Maybe try this instead:

- alias: gps_status_881e
  trigger:
    platform: state
    entity_id:
      - sensor.sube881e_gps_lat
      - sensor.sube881e_gps_lon
  condition:
    condition: template
    value_template: >
      {{ -90 <= states('sensor.sube881e_gps_lat')|float(200) <= 90 and
         -180 <= states('sensor.sube881e_gps_lon')|float(200) <= 180 }}
  action:
    - service: device_tracker.see
      data_template:
        dev_id: sube881e
        gps:
          - "{{ states('sensor.sube881e_gps_lat') }}"
          - "{{ states('sensor.sube881e_gps_lon') }}"
1 Like

Hi,

thanks, this does not work either.

I still get the exact same error

I do not know where the issue is from.
I will try to restart again, like all in one config file, like it was when it was working, maybe this will help me to start over and then work step by step.