Using device_tracker.see service to troubleshoot zone automations

In my opinion, the instructions are not clear on how to use the device_tracker.see service in Home Assistant. I hope that this explanation helps people out.

I will go thru how to create a device_tracker with the service, attach it to a person, and use it to manipulate the person’s zone manually and predictably for testing.

This is useful for troubleshooting zone related automations, scripts, templates, and blueprints such as my blueprint here.
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Start off by going into developer - services and opening up device_tracker.see service.
Open your Home Assistant instance and show your service developer tools.

In UI mode add a new Device ID and set it’s location to home. Click call service button bottom right. I called mine aaatest, but use whatever name you like.

Open a new window to developer - states and look at the entity you just made, device_tracker.aaatest .
Open your Home Assistant instance and show your state developer tools.

Now open up your People integration and select a person to use for testing. Alternatively you could create a new person for temporary use if desired.
Open your Home Assistant instance and show a list of your people.

Remember the track device(s) listed so that you can put them back un later, then remove any(all) existing tracking devices. Add the aaatest device tracker.

NOTE: It is possible to leave the Persons device trackers there and add a new one, but if that tracker you didn’t remove changes state, it will update the Person and might cause confusion. Therefore I recommend removing trackers that you do not control for testing so that only the tracker that you do control is changing the person’s state. The person’s state will update to match the location of the last tracker that reports in.

Now you have a person set to a manual device tracker. By changing the location in developer - services you can see it change in developer - states and the person you picked will move to the new location. Use this to test people moving from home, to not home, to any of the zones you have set-up in your HA instance.

When you are all done, restore the track devices that were in the person’s set-up before you changed them and delete the aaatest device tracker to bring your config back to normal.

2 Likes

I’m struggling with device_tracker.see

I got a dragino LoRa TrackerD GPS tracker, which I’m accessing through the things network. It’s working great, however HA doesn’t interpret the location information as a location. I’m wondering how I can track using this data. The plan is to leave the tracker in the car, and set automations based on distance away from home. 5 miles away turn on the heating, 500m away, turn on the lights, etc. We don’t always have our phones with us, so automating using a mobile isn’t really an option.

This is the output I’m getting for the entity at the moment:

trikr

What are the entity IDs that are providing the latitude and longitude?

Generally, the service call is going to look something like:

  - service: device_tracker.see
    data:
      dev_id: example
      gps: "{{ [ states('sensor.trkr_latitude')|float, states('sensor.trkr_longitude')|float ] }}"

Once you have the device tracker set up, you will likely want to also set up a Proximity sensor to help with your distance-based automations. Proximity also provides some other useful data points like whether the device is headed toward or away from the designated zone.

FWIW, there is also a non-device-tracker option, which is using the distance() function in a Template sensor. You would still need to ascertain the entity IDs that provide lat. and long.

Here is one of Drews old posts I found as well…
Is it possible to create a software device Tracker?.
and another
How to create a custom device or person tracker?.

hi Drew, Thanks for the explanation. The entity names are sensor.eui_<16-digit-eui-no>_ followed by the following

alarm_status
batv
latitude
location
lon
longitud (without the e)
md
transport

I’m struggling to understand how the device tracker updates. I went into developer tools, and called the service:

I associated it with the user called jag (yes we drive the most boring car in the world!)

Does this device tracker now update itself? Or do I have to do something else? I’m stuck at home for a few days, so no chance to test it!

Apologies for the noob questions.

You will have to add an automation that pushes the info to the device_tracker every time the device sends you an update.
The code you have for the action should be OK, the automation should trigger when the sensor state changes.

Just one thing to add to @Sir_Goodenough’s post… When you create your automation, you likely want to remove the location_name variable since not every set of coordinates will be home.

1 Like

Thanks to you both, and happy new year! (@Sir_Goodenough and @Didgeridrew) I’ve got it working pretty well now, apart from when the device loses GPS signal, and it sets both the latitude and the longitude values both to zero, which places the vehicle at ‘Null Island’ in the gulf of guinea! The side affect of this is that the vehicle moves between Home and Away, when it really is at home. I wanted to put a condition in the automation, so it wasn’t triggered when longitude was exactly zero, but I can’t figure out how to do that with a numeric state, as it only seems to accept either above or below a value. If the longitude is exactly zero, I can surmise that the GPS isn’t getting a signal. Any ideas?

here is my yaml

alias: trkr
description: “”
trigger:

  • platform: state
    entity_id:
    • sensor.eui_a84041fb11xxxxxx_location
      from: null
      to: null
      for:
      hours: 0
      minutes: 0
      seconds: 1
      condition:
      action:
  • service: device_tracker.see
    data:
    dev_id: jag
    gps: >-
    {{ [ states(‘sensor.eui_a84041fb11xxxxxx_latitude’)|float,
    states(‘sensor.eui_a84041fb11xxxxxx_longitud’)|float ] }}
    mode: single

Add a condition after your trigger to only allow the automation to proceed only when longitude is not 0.

condition:
  - condition: template
    value_template: "{{ states('sensor.eui_a84041fb11xxxxxx_longitud') | float(0) != 0 }}"

*Note: I left the sensor’s entity ID as posted above, without the e on longitude.

Woow just what I was looking for, thank you so much for the tutorial !!