Device_tracker.see and data templates

Hi,

I got the following scenario: I get the Battery States (location and other states) of my Phone from Tasker, via http post stored in an entity sensor, every 10 mins. So far so good everything works here.

The sensor is called:

sensor.pixel_3_batt

I test the syntax in the template editor now:

{{ states('sensor.pixel_3_batt') }}

It gives me the correct state, of example 83.

now i want to give the battery data to a device tracker.

I test in the service editor:

Service: device_tracker.see

data_template:
  dev_id: pixel_3_tasker
  attributes:
    battery: "{{ states('sensor.pixel_3_batt') | int }}"

I tried that but i get the error

Error while calling Service device_tracker/see. must contain at least one of mac, dev_id.

device_tracker.pixel_3_tasker is a custom device tracker that is not created by a router or something else.

If I manually type in like battery: 14 everything works. I dont know if i misunderstood the whole function of device_tracker.see, or if there is a syntax problem.

these are the attributes from device_tracker.pixel_3_tasker

state:

not_home

attributes:

source_type: null

friendly_name: pixel 3 tasker

hidden: false

I have desperately tried many different options. But none of them worked. I hope someone can help me find a solution.

The device_tracker.see service requires a location to be provided according to the docs.

Where do you manually type this? In the data_template of the device_tracker.see service call?

okay i tried this:

data_template:
  dev_id: 'pixel_3_tasker'
  attributes:
    battery: "{{ states('sensor.pixel_3_batt') | int}}"
    gps: "[{{ state_attr('sensor.pixel_3_geocoded_location', 'location') }}]"

But it gives me the same error.

the location template works correct i tested it in the template editor.

[{{ state_attr('sensor.pixel_3_geocoded_location', 'location') }}]

gives out: [51.xxxxxxx,7.xxxxxxx]

service call:
device_tracker.see

dev_id: pixel_3_tasker
battery: 14

this updates device_tracker.pixel_3_tasker correctly

attributes:

source_type: gps
battery: 14
friendly_name: pixel 3 tasker
hidden: true

I think I found the error. Why do you put the battery under attributes? In the example where you entered it manually and it worked you also did not put it under attributes.Try this:

data_template:
  dev_id: 'pixel_3_tasker'
  battery: "{{ states('sensor.pixel_3_batt') }}"

I still get:

No matter how i change things up it won’t work

okay this is kind of the solution.

There seems to be a problem with the call service tool.

If i put an automation like this together

- alias: Pixel 3 Battery
  trigger:
    platform: state
    entity_id: sensor.pixel_3_batt
  
  action:
    service: device_tracker.see
    data_template:
      dev_id: pixel_3_tasker
      battery: "{{ states('sensor.pixel_3_batt') }}"

I get the battery attribute immediately updated in device_tracker.pixel_3_tasker as the sensor state changes.

Next Problem: I tried to add the gps attributes to device_tracker.pixel_3_tasker. I added an additional automation:

- alias: Pixel 3 Location
  trigger:
    platform: state
    entity_id: sensor.pixel_3_geocoded_location
  
  action:
    service: device_tracker.see
    data_template:
      dev_id: pixel_3_tasker
      gps: "[{{ state_attr('sensor.pixel_3_geocoded_location', 'location') }}]"

But these Values do not get added. The Automation fires but nothing gets added.

device_tracker.pixel_3_tasker looks like this now

source_type: gps
battery: 71
friendly_name: pixel 3 tasker

I had the same issue, turned out I couldn’t use Location as the attribute, had to do 2 statements, one for Longitude and one for Latitude with a comma inbetween