Device tracker from script?

This is the automation I have, once run, you will see a discovered device in known_devices.yaml and you can use it as any other device_tracker

- alias: Car Tracker
  trigger:
    - platform: state
      entity_id: sensor.car_latitude, sensor.car_longitude
  action:
    - service: device_tracker.see
      data_template:
        dev_id: car
        host_name: Car
        gps:
          - "{{ states('sensor.car_latitude') }}"
          - "{{ states('sensor.car_longitude') }}"
1 Like

Has this service changed in the last two years? I canā€™t get a new sensor created with this automation:

alias: Device Tracker Update Person1
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.location_person1
condition: []
action:
  - service: device_tracker.see
    data:
      dev_id: person1
      gps: "service: device_tracker.see
data:
  dev_id: person1
  gps: "{{ states.sensor.location_person1.state }}"
mode: single

No, mine still works. what is the state of

ā€œ{{ state_attr(ā€˜sensor.person1_iphone_geocoded_locationā€™,ā€˜Locationā€™) }}ā€

Ooopsā€¦ that was an attempt to try something else because the first attempt didnā€™t work. Edited above. The state of that sensor is the GPS coordinates from my mobile device. Iā€™ve had a real uphill battle over the last few days. My mobile device_trackers have ceased to work, and Iā€™m trying to implement a work-around.

Just trying to call the device_tracker.see service doesnā€™t work for me:

ā€œFailed to call service device_tracker.see. Unknown error.ā€ My patience with this packed up and left days ago. All of my mobile device_trackers failed simultaneously, and Iā€™ve been trying to figure out a way to get my automations back up & running since.

EDIT: Just tried for ā€œfunā€ using sample data:

service: device_tracker.see
data:
  dev_id: THIS_BS
  gps: [51.509802, -0.086692]

Error

Have a look at mine above itā€™s a bit different to that

Yes, it is. Iā€™m using a single entity for both latitude and longitude, which should work.

Iā€™ve also split latitude and longitude into separate entities and done it similar to yours. This:

service: device_tracker.see
data:
  mac: FF:FF:FF:FF:FF:FF
  dev_id: person1
  host_name: Person1
  location_name: home
  gps:
    - "{{ states('sensor.location_person1') }}"
    - "{{ states('sensor.longitude_person1') }}"

ā€¦doesnā€™t work either, even now that I have device_tracker.person1 created.

Have you tried with data_template

Ohh, I see. Yes, Iā€™ve tried this:

- alias: Device Tracker Update Person1
  trigger:
    - platform: state
      entity_id: sensor.location_person1
  action:
    - service: device_tracker.see
      data_template:
        dev_id: person1
        host_name: Person1
        gps:
          - "{{ states.sensor.location_person1.state }}"
mode: single

ā€¦but it doesnā€™t do anything.

This updates the device_tracker entity:

service: device_tracker.see
data:
  mac: FF:FF:FF:FF:FF:FF
  dev_id: person1
  host_name: Person1
  location_name: home
  gps:
    - 30
    - -20

This does not:

service: device_tracker.see
data:
  mac: FF:FF:FF:FF:FF:FF
  dev_id: person1
  host_name: Person1
  location_name: home
  gps:
    - "{{ states.sensor.location_person1.state }}"

EDIT: Iā€™ve abandoned this pursuit because I got my native mobile device_tracker entities working. I may come back to this in the future, though.