I am new to Home Assistant and using it to automate our new hackerspace. While I’ve worked around most issues through research, I am missing something about a current problem where two switches out of 9 at some point decided to duplicate their entity ids, which leads to an unwanted default switch group being displayed in the HASS UI.
These switches are Tasmota flashed Sonoff S26 devices, the majority of which work correctly. An example of the States listing is shown below.
These entries refer to exactly the same device. Clicking on the icon to the left of the entity ID brings up the same data display.
The difference in the entries for Power Switch Four is that one shows that an icon is associated with it and the other does not. The duplicated one with the 2 suffix shows it is hidden because of the work-around in customization.yaml which hides the unwanted device entity id.
I am not happy about using this work-around without understanding why the duplication happens, how to prevent it and how to fix it more permanently than randomly adding in extra customization.yaml entries when these issues pop-up.
In the journey to discover the cause and solution, I have tried many variations like commenting out discovery, cleaning a duplicate entity id’s entries from the States table, turned discovery off and attempting to use the Tasmota SetOption19 variations (HA discovery on/off).
So my questions are:
Why do these device duplicates occur only for specific devices; and
how can you remove them permanently and not simply hide them?
Thank you for your quick reply. I would love to use that approach but the system does not have a known_devices.yaml file in the configuration directory.
What was your first ever HA version? If it was anything prior to 0.77.x, check your hidden files…
After that I believe it’s stored in .storage/core.entity_registry.
Make sure you backup the file first !!!
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
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?
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
@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.
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