How to remove device_tracker from database?

Hi guys,

I was playing around with the device_tracker with owntracker and suddenly it created some “personas” in my home assistant, which for the life of me can’t find out how to remove.

56

I’ve tried even deleting manually from the sqlite database with no success.

Any pointers?

P.S.: I’m quite a new home assistant user (newbie) so excuse my possibly dumb question. :slight_smile:

Hi,

Check the known_devices.yaml file. In that file you have all devices that you can track in HA.

Just remove that devices, or put track: false in their config.

9 Likes

Many many thanks! That’s exactly what I needed!

1 Like

known_devices.yaml has been depreciated. Is there any other way?

actually, it is still used, it is just beeing “phased out”, I was able to get rid of a couple of old devices only by editing it

which version are you using? Im on 0.113.3 and i cant find the file at all.

after debugging via the source code, it turns out that the only way to remove a rogue tracker was by editing the core.device_registry and core.config_entries files in the …/.homeassistant/.storage folder.
I located my old device there n deleted its whole JSON entry.
Do it at own risk and keep a backup please of your whole storage folder cause im not sure on the side effects this may have caused.

If someone know a valid way to remove a device tracker (i.e. via the hass UI) please share it.

Sharing a script I have for purging device_tracker entities from the .storage/core.entity_registry file.

USE AT YOUR OWN RISK–THIS IS NOT A UI TOOL AND IS FOR ADVANCED USERS WHO KNOW WHAT THEY ARE DOING

You can download the script from the Gist below, edit the first two lines for the path to your config and entity_id regex pattern you want to remove. By default it removes ALL device_tracker entities and let’s them regenerate when you restart Home Assistant.

  1. Download to somewhere with a) python3 and b) access to a copy of the core.entity_registry file. Suggest you run it on a copy first!
  2. Run with ./device_tracker_purge.py or python3 device_tracker_purge.py
  3. Check that the right number of entries were deleted.
  4. Copy file back to your config directory (overwrite the existing)
  5. Restart Home Assistant

In theory, this can be used to purge any specific entity_id pattern, not just device_trackers, but you should be using the UI whenever possible!

I pulled my hair out trying to get rid of own track device_tracker entities and devices. What I did:
Remove Own Track integration
Remove Mosquito integration
Purge MariaDB database with keepdays:0
remove Mosquito addon
ssh into host
find homeassistant docker id

docker stop #id

go to config/.storage and find the relevant entries inside the storage files. I found them in core.device_registry and core.restore_state
take a backup of these files
delete the entries you want gone while keeping the syntax.
save the changes
reboot the host machine
reinstall Mosquito addon if you want

I’ve stumbled upon a rather easy way of purging known devices… at least for the nmap integration, that now uses Config Flow instead of known_devices.yaml. Perhaps this would also work for other device_tracker integrations?

I needed to update my nmap configuration’s list of IPs to exclude. After doing so, it seemed to have wiped and re-created the device registry. I had lots of “stale” device entities I could easily remove.

How about removing the entities the device tracker picked up?
Some device around here seems to change his mac and I have several thousands or ble_ devices in my HA. I cannot figure out how to remove the entities :neutral_face:
I deleted the extranous entries from known_devices file and restarted, but the entities are still there :neutral_face:

1 Like

I change my phone this week and the only way I found to remove the old device_tracker was to search for the device name in all config files (core.entity_registry, core.device_state, …) and remove manually the records found.
After a restart It have disappear from entities

Here is something I figured out.
Even if you rename/remove old device trackers, they may still have entries in your Recorder.
So run the following service (at your own risk, in my case I didn’t care what “iPhone” data was deleted, I wanted it all cleaned up):

service: recorder.purge_entities
data:
  domains: device_tracker
  entity_globs: device_tracker*iphone*

I think this did the trick for me. You may not want to delete all of them at once with a wildcard - maybe specify the names for each one.

9 Likes

I found this and other threads and was partly able to solve my problems with numerous device_tracker entries. My main problem was I left “track_new_devices: true” for a year or two. With a Rpi4 with SSD it wasn’t a visible problem until there were some 75000 entries in known_devices.yaml…

The solution I made is a python program that purges all entries that relates the BLE trackers.

You can find the code at my Github project including instructions how to use it. The visible result for myself is that HA generally is much more responsive, and Developer Tools|States doesn’t time out anymore.

This worked for me. I had 15,087 devices that were named like this:

device_tracker.1a_2b_3c_4d_5e_6f

the entity_globs pattern I used looked like this:

device_tracker.**_**_**_**_**_**

Now my Developer Tools >> States page loads normally. The 15k records had that page loading in about 10 seconds.

Cheers.

9 Likes

Hi,
I had the same problem, I left track_new_devices: true for a little to long, and after I realized I was unable to even scroll through the whole list.

This solution solved it, but as target is now required in service call I wanted to share example syntax that worked for me. Maybe someone will have the same issue.

service: recorder.purge_entities
data:
  entity_globs: device_tracker.**_**_**_**_**_**
  domains: device_tracker
target:
  entity_id: null

After this restart of HA is required.

8 Likes

I’m wondering if anything different is needed for this now?

I’m on 2024.03 with this issue, and not having any luck with the above suggestions. I’ve cleared all the BLE entries from known_devices (which I can see remains trimmed down), and run the recorder.purge_entities service above, (tried both in gui and yaml mode), with restarts (tried both HA and full reboot) after each. Still all there though!

2 Likes

@SadGamerGeek : it is the same with me. Tried all the different ways mentioned above but was not successful.

Hope there is a chance to delete all those entities in order i got the feeling it slows down my system. Thank you a lot in advance.

Same here. Non of the solutions above work. Using wildcards will throw error saying entity not found. Adding target doesn’t work either. I understand the only option is to remove registry entries. That seems rather silly to me not being able to use the UI to multi select and remove entries.

Came across this thread after ending up with over 200,000 device_tracker entities in my HA instance. These are the steps that worked for me go get rid of them:

  1. Make a backup just in case
  2. Go to Developer Tools > Actions
  3. Choose “Recorder: Purge entities”
  4. Set Domains to remove: device_tracker
  5. Set Entity globs: device_tracker.**_**_**_**_**_**
  6. Perform Action
1 Like