How to rename LocalTuya entities in Home Assistant after reinstalling everything (without losing your mind)
- January 14, 2026
This week I was doing some tests in Home Assistant and, because of a stupid mistake, I restarted it without validating the structure of the files I had changed. Home Assistant didn’t come back up. I tried restoring files, tried restoring backups, tried a few other desperate things… nothing worked. In the end, I had to reinstall everything from scratch.
And if you use LocalTuya and have ever had to reinstall Home Assistant, you know exactly what I’m talking about. Everything works again, but the names… my friend… the names turn into pure chaos.
Suddenly your whole house looks like this:
switch.local_71706185e868e755df28_1
switch.local_22230844e868e7828084_1
light.local_eb0siq_1
Before that, everything was nicely organized. Decent names, readable automations, a clean Lovelace dashboard.
After the reinstall, it feels like someone threw all the entity_ids into a blender.
The first reaction is: “ok, I’ll just rename them by hand.” The second reaction, after about 10 devices, is giving up on life.
That’s when I decided to do it the right way.
It’s not the simplest path, but it’s the one that actually works, and you only need to do it once.
The real problem (without too much theory)
In Home Assistant there are two different things that a lot of people mix up:
entity_idis the technical identifierfriendly_nameis just the nice label shown in the UI
Changing friendly_name is easy.
Changing entity_id is not.
What really controls entity_ids is the Entity Registry, that hidden file at .storage/core.entity_registry.
If you don’t touch that, Home Assistant will always prefer those ugly LocalTuya-generated names.
And yes: customize.yaml alone doesn’t solve this. It helps, but it doesn’t fix the root of the problem.
The approach that worked for me
The idea was simple:
- use
ui-lovelace.yamlas the source of truth - if an
entity_idexists in Lovelace, that’s the correct name - everything else needs to adapt to that
So I wrote a Python script that basically does three things:
- reads
ui-lovelace.yaml - opens
core.entity_registry - updates both
entity_idandnamefor all LocalTuya entities in one go
No UI clicking, no editing 80 screens, no pain.
First things first: stop Home Assistant and make a backup
Don’t skip this part. Seriously.
ha core stop
or if you’re running Docker:
docker stop homeassistant
Backup:
cp /config/.storage/core.entity_registry /config/.storage/core.entity_registry.backup
Now you’re safe to mess around.
The script that saves your sanity
This is the main script I use. It’s not pretty, it’s not generic, but it works. And it works really well.
import json
import yaml
import re
ENTITY_REGISTRY_PATH = ".storage/core.entity_registry"
LOVELACE_PATH = "ui-lovelace.yaml"
def load_desired_entity_ids():
with open(LOVELACE_PATH, "r") as f:
content = yaml.safe_load(f)
found = set()
text = json.dumps(content)
for match in re.findall(r"(switch|light)\.[a-zA-Z0-9_]+", text):
found.add(match)
return sorted(found)
def generate_friendly_name(entity_id):
name = entity_id.split(".", 1)[1]
name = name.replace("_", " ").title()
return name
with open(ENTITY_REGISTRY_PATH, "r") as f:
registry = json.load(f)
desired_entity_ids = load_desired_entity_ids()
print(f"Found {len(desired_entity_ids)} entity_ids in Lovelace")
for entity in registry["data"]["entities"]:
unique_id = entity.get("unique_id", "")
if not unique_id.startswith("local_"):
continue
for desired in desired_entity_ids:
domain = desired.split(".")[0]
if entity["entity_id"].startswith(domain):
print(f"Updating {entity['entity_id']} -> {desired}")
entity["entity_id"] = desired
entity["name"] = generate_friendly_name(desired)
desired_entity_ids.remove(desired)
break
with open(ENTITY_REGISTRY_PATH, "w") as f:
json.dump(registry, f, indent=2)
print("Entity Registry updated successfully")
What this script does, in plain English:
- it scans Lovelace and figures out which
entity_ids you actually use - it walks through the Entity Registry looking for LocalTuya entities
- when it finds one with the same domain (
switchorlight), it replaces theentity_id - it also sets a decent name at the same time
- then it saves everything back to the registry
Nothing magical. Just straight to the point.
####### “But how does it know which switch is which?”
It doesn’t. Not 100%. And that’s important to understand.
This script assumes your Lovelace is already organized in a logical way. If you have some weird edge cases, you fix those later. It’s still way better than starting from scratch and clicking around in the UI for hours.
After that, I still generate a customize.yaml
It’s not mandatory, but I like having it.
with open("customize.yaml", "w") as f:
for eid in desired_entity_ids:
f.write(f"{eid}:\n")
f.write(f" friendly_name: \"{generate_friendly_name(eid)}\"\n\n")
Just an extra safety net.
Time to start everything again
ha core start
or Docker:
docker start homeassistant
The first startup might take a bit longer. That’s normal.
When the UI loads… everything is back to normal.
Correct entity_ids, proper names, automations working, Lovelace intact.
A few things I learned the hard way
entity_idis not just cosmetic- the Entity Registry is sacred
customize.yamlhelps, but it’s not magic- always back up first
- an ugly script that works beats a perfect solution that never ships
Today I keep these scripts as part of my Home Assistant setup. If I ever need to reinstall everything again, in five minutes my house speaks human language again, not hexadecimal.
If you made it this far, you’ve probably been angry about this too. Hope this saves you a few hours (and a few swear words).
And if I ever forget how I did this… this post is also for future me.