Duplicate switch entity ids - how to rectify?

say whaaaaaat? I have a .storage/core.entity_registry as you mentioned… as I’ve been using HA since well before 0.77.x. But… if you didn’t migrate up and just started at 0.77.x… you’ll have a totally different file name? Do you know why? That seems silly. I didn’t create core.entity_registry to begin with, HA did it for me. So… why not create the same file name no matter what? And if, at some version, core.entity_registry was the file name, and then it got changed to known_devices.yaml, why wouldn’t HA migrate the file over?

It’s the other way round. Was saved in known devices and since 0.77 is saved in .storage/core.entity_registry (not sure if known devices is still maintained)
Not sure what happened but if you have duplicate devices that’s where they’ll be saved. Remove the unwanted block(s) after backup and restart ha it should solve your problem

I used to have a file called “entity_registry.yaml”. Some upgrade (probably 0.77) moved it to “.storage/core.entity_registry”.

The file format also changed from YAML to JSON.

Thank you for your responses. We are running HA 0.75.3 in a docker container on Debian Linux 9.5. I will look inside the Docker container directories for these files. I am new to Docker and HA. Looks like I need to update the Docker instance to the latest HA release.

Any idea why the duplication may have occurred in the first place and are there any best practices for preventing it happening in future?

That’s weird. I still have a known_devices file after the update (currently 0.77.3).

Is the known_devices.yaml still a valid option in configuration.yaml for the latest release?

I don’t have the extra WiFi entries in configuration.yaml and I expect that is why I don’t see the known_devices.yaml file.

known_devices.yaml is for the device tracker platform. It’s different than the old entity_registry.yaml and is still a file in use in 0.77.x.

1 Like

I upgraded the HASS docker instance to .77.3 and like this thread (Entity_registry.yaml is gone as of version 0.77.1, as well as the GUI entity registry editor) suggests, the core.entity_registry file is now in the .storage directory under the HA configuration directory.

However, when I view this core.entity_registry file, it only contains two devices, both Wemo. Therefore, I am still no wiser as to:

  • how the duplication occurred in the first place; and
  • how to fix it.

Reading the forums it is clear that my problem is not unique and there are many frustrated HA users out there.

Any thoughts?

Ahhhh!

More than likely your switches are coming from MQTT discovery.

In the mqtt section of your config, you probably have discovery on. You likely have a retained MQTT message configuring two switches with the same name (or you have one switch defined in MQTT discovery and one switch defined directly in your config).

Using an MQTT tool of your choice, explore that parent topic. If you see any config entries that should not exist (or that are now defined directly in your HA config) you can delete them by publishing a null message to that same topic.

Alternately, you can delete ALL retained messages with the following commands (assuming you’re using mosquitto):

sudo service mosquitto stop
sudo rm /var/lib/mosquitto/mosquitto.db
sudo service mosquitto start
1 Like

Thank you @swiftlyfalling, I will take a look and let you know the results.

@swiftlyfalling, thank you again for your suggestion, which worked like a charm to remove the two rogue duplicate switch entries. While I have a software background, I am new to MQTT, HA and Tasmota. I will learn how to explore the MQTT database. While I used the ‘sledgehammer’ approach of deleting the mosquitto.db, I took a copy to review later.

Which tool do you use to explore the db?

MQTT.fx is a decent Java based client that should run just about anywhere.

On the command line, mosquitto_sub works well.

MQTTBox is a Chrome browser extension that isn’t the best, but gets the job done.

I hate to bring up an old topic but I am having the same issue and I am not sure how to remove the duplicate entries I have in my new HASSIO build.

I was able to resolve my issue by removing the MQTT broker and reinstalling it, that deleted all the auto discovered items.

I have the same problem. All my Tasmota switches are duplicated. That does not happens for other devices. I Tried uninstalling/reinstalling MQTT and deleting core.restore_state, but they are always duplicated.

And now, my friend also has same duplication problem with tasmotized switches
They don’t appear in HA MQTT autodiscovered devices under Integrations->MQTT

Ok i found out the problem. I had a startup automation that was doing “Setoption19 1” to all tasmota devices.
I changed in “0”, rebooted, commented out that part, deleted the core.restore_state, rebooted, and now all “_2” are gone.

Did that, and nothing happened. I still have the same _2 duplicates. core.restore_state got generated again identical, near my bak one. I use Hassio on a Pi3. Cannot access the file mosquitto.db.

i have duplicate entries for my raspberry pi in known devices.yaml and when i go take a look, each one of them has different mac address. i am running ha on docker. supervised manual install on linux host. any thoughts ?

It seems that in .storage\core.config_entries there are duplicated entries. I don’t know where are from coming. But have the same problem.
For the first step I’ve checked all integrations config to disable discovery because all my entities I added in yaml by hand and after I deleted all entites which was duplicated as 1_2, 1_3 … from .storage\core.config_entries and as the result it helped.