Using templates in device_tracker.see service call

Does anyone know if it’s possible to use templates to set the gps position of a manually created device tracker? And if yes what is the syntax?

I’ve seen examples of templates used for other service call data but not for the GPS data.

Here is the automation service call I’m trying to use:

    action:
      - service: device_tracker.see
        data_template:
          dev_id: tacoma_location
          location_name: not_home
          gps: "[{{ state_attr('device_tracker.my_mobile_app', 'latitude') }},{{ state_attr('device_tracker.my_mobile_app', 'longitude') }}]"

and this is the relevant line of the error (ignoring the gibberish):

voluptuous.error.MultipleInvalid: None for dictionary value @ data['gps']

the template looks like it is in the correct format when I put it into the template editor.

I even tried to cast the attributes to a “float” and still I get the same error.

A guess based on other templated arrays I have in my configuration…

    action:
      - service: device_tracker.see
        data_template:
          dev_id: tacoma_location
          location_name: not_home
          gps:
            - "{{ state_attr('device_tracker.my_mobile_app', 'latitude') }}"
            - "{{ state_attr('device_tracker.my_mobile_app', 'longitude') }}"
1 Like

Doh! That worked.

I totally missed that it was expecting an array.

But I guess I’m still not sure why the template I had above didn’t also create an array. I know that just typing it in as gps: [44.67765,-88.434554] works. So I assumed it was just a string. Maybe there is some magic conversion in the service call that converts that string into an array that doesn’t also work as a single line template?

THanks!

1 Like