MQTT Device Tracker and Owntracks - Remove old device id from HA

Hi,
I installed MQTT Device Tracker and Owntracks.
The first time I tried it with a temporary device id. All was ok.
I changed the settings in owntracks with the real name but I still get the old and the new name in HA.
Any suggestions how to delete the old device id?
Thank you

1 Like

Try deleting the known_devices.yaml file in configuration directory. You can also open the file and delete the devices or match MAC addresses.

Does it show up in known_devices.yaml? If so, just remove it from there and you should be all set.

I have already done this. Reappear in know devices, either delete the file or delete the entries.
Thank you!

If it keeps showing up in HA you can go into the known_devices.yaml, find the entry with that id and set track to false, then it won’t show up in the front end

I found the solution. Some messages from old devices remained in the mosquitto broker. I manually delete them and now HA not discovering them.
Thank you.

Vassilis I am having the same problem, could you tell me how you removed the messages from old devices remaining in your broker? Thanks.

Hey guys, I’m having the same issue. I had Owntracks set up on my Android device but I had to reset it. Did not realize I’d have to deactivate Owntracks or something first, so now I have an extra device. Whenever I delete it from known_devices, it just shows up again after restarting HA…

You can remove retained messages by publishing a zero length retained
message to the topic you wish to clear. For example, you could do it
with mosquitto_pub as follows:

mosquitto_pub -t <topic> -r -n
1 Like

Thank you vassilis! I realized I did not have have the mosquitto_sub client installed…!
I also had to go to mosquitto.conf to cancel the persistent configuration.

This worked for me, and of course I restarted owntracks on my phone, as well as the server.

mosquitto_pub -t owntracks/“user”/“devicel” -r -n -u “username” -P “password”

That cleared everything. Thank you again for your support.

4 Likes

I’m having the same issue can someone help?
I’m a newbie to HASS MQTT and OwnTracks.

I basically set up Hassbian a few days ago with an MQTT broker. I set up OwnTracks yesterday with a default device ID. I changed that device ID a few times. Now my old device ID shows up in the HASS states page and also on my phone as “friends”. How do I get rid of this?

I tried running the following on my raspberry pi hosting my MQTT broker and HASS.

“mosquitto_pub -t owntracks/user/old device ID -r -n -h my_local_IP_of_my_RPi -p 1883”

But all I got in return was:

Connection Refused: not authorised.
Error: The connection was refused.

Please help?

I just tried this:

mosquitto_pub -t owntracks/<user>/<device> -r -n -h <mymqttbroker> -p <portnumber>

With the same result:

Connection Refused: not authorised.
Error: The connection was refused.

You probably need to include a username and password.

After some further investigation I tried this:

mosquitto_pub -u username -P password -h hostname -p port -t 'owntracks/user/device' -n

I see the null message successfully being delivered, If I restart the server the old messages unfortunately come back.
I’m using Cloudmqtt btw

I had the same problem and I finally just solved it. After reading this thread.

The trick was to remove “Friends” from OwnTrack app. I think every time you “share” your zone, it creates a friend with a device_ID you had at that time. As I was deleting those “friends” (myself from previous ids), I have seen all those weird ids sending a message to the MQTT broker.

I also did the mosquito_pub command and restarted MQTT server as well in addition to deleting “friends” from the OwnTracks app.

See if this works for you.

1 Like

Don’t know about the iOS version, but in the Android version of Owntracks, if you go in to the friends list, select the device you want to remove, slide up the card at the bottom to see the device info, click the 3-dots and then select ‘Clear’ it will clear the MQTT stream for that device.

Then delete the device from known_devices.yaml .

There is no need to send any manual commands from Mosquitto using this method.

6 Likes

I have a few old obsolete entries that I am unable to delete from home assistant v109.6. When I try from Configuration->Integration->Owntracks->Entities->Delete it give me the following error message

" Only 0 selected entities can be removed.

You can only remove 0 of the selected 1 entities. Entities can only be removed when the integration is no longer providing the entities. Sometimes you have to restart Home Assistant before you can remove the entities of a removed integration. Are you sure you want to remove the removable entities?"

I can certainly disable them on Home Assistant, but they are still there as disabled entries.

There is no known_devices.yaml in use anymore and I use the HTTP mode on Owntracks on iOS13 (not MQTT). Most of these devices are from older phones that I no longer use.

I did attempt the null message option via MQTT, however I was unsure what exactly is the ‘user’ and ‘device’ in the command. Is this Name and entityID as it appears on the Home assistant?

‘mosquitto_pub -u username -P password -h hostname -p port -t ‘owntracks/user/device’ -n’

On my owntrack app on iOS, there only one person and that is myself, ie the current device.

Appreciate your help

Go to /config/.storage/ and remove the old device and entity form core.device_registry and core.entity_registry

Worked for me.