How to implement device tracker

I’m writing a custom component device tracker for devices connected to my router. But looking at the device tracker code it looks like the DeviceTracker object is considered legacy now core/homeassistant/components/device_tracker at 72801867d6f53c16846b8053b0ac367a6b5b51f3 · home-assistant/core · GitHubinit.py.

Also the documentation at Device Tracker - Home Assistant says that known_devices.yaml is being phased out. I tried looking in the documentation but didn’t find anything clearly stating what I should do. What is the proper way to implement a device tracker now? Should it just be a normal component that adds each entity as a binary_sensor entity with connectivity device class?

hi ,
does this help

Not really, as that is about managing already added entities/devices from a device tracker. I’m asking about how to write code to implement a device tracker.

I can’t tell you how to but I can say it is important to use not_home and home as integrations that use location will look for those states. I use a stand alone program and use an automation to turn a numeric sensor into a device tracker using the service device_tracker.see

- alias: Andrew Occupancy On
  trigger:
    - platform: numeric_state
      entity_id: sensor.andrew_occupancy_confidence
      above: 10
  action:
    - service: device_tracker.see
      data:
        dev_id: andrew
        location_name: home
        source_type: bluetooth

- alias: Andrew Occupancy Off
  trigger:
    - platform: numeric_state
      entity_id: sensor.andrew_occupancy_confidence
      below: 10
  action:
    - service: device_tracker.see
      data:
        dev_id: andrew
        location_name: not_home
        source_type: bluetooth


I have an custom integration using device tracker and i didn’t know that device tracker is deprecated.

So after looking around the code some more it seems that the new way you are supposed to implement device tracker is to get data using a DataUpdateCoordinator or some other means, then add entities using the new TrackerEntity and ScannerEntity in core/config_entry.py at 9307cbf861e199adccf33fb83f797e71032680a6 · home-assistant/core · GitHub.

An example I’ve been following is the asuswrt component core/device_tracker.py at 9307cbf861e199adccf33fb83f797e71032680a6 · home-assistant/core · GitHub

You are right, Data update coordinator is new way of updating data but it is not about deprecated device tracker, right?

As far as I can tell the device tracker platform itself is not deprecated, the deprecated part is all the stuff in the legacy file such as DeviceScanner, service.see, etc.

Typically in older device tracker implementations I have seen that they use the DeviceScanner to handle getting data without a coordinator. So my understanding is that DeviceScanner is deprecated because of the new coordinator pattern. And as a result you also need to manage the adding the device_tracker entities yourself instead of having DeviceScanner handle that for you.

1 Like