A few times I have wanted to “re-arrange” devices for example:
Swapping out a white only smart bulb with a color variant.
Changing out a bulb for a brighter version.
Switching out a PIR sensor for a MM-Wave presence sensor.
When I do this I typically swap in one new device and re-purpose the old device (use it for something else).
I have tried to simply “rename” it in the UI, but between the multitude of setting:
Color
Brightness
On brightness
On delay
Firmware update
Identify
And the various Identities:
Entity ID
Device ID
Name
Description
…
I always seem to end up with some residual attributes of the old identity.
The only reliable way I have found to do this is unpair/delete the device and then re-pair it, entering in a new name and location.
Is there a “proper” way to fully change the identity of a device, so that it sets all the values as if I had purchased a brand new device and just paired it for the first time?
Note: Most of my devices are Zigbee/ZHA (that is my primary concern), but I do have a few WIFI devices.
If you rename it at the device level then HA offers to rename all the entities for you too.
For Zigbee I rename the device in Zigbee2Mqtt and turn on the “update home assistant” button before submitting the change. Through the magic of mqtt discovery this changes everything. Not sure how it is done in ZHA.
That appears to update all the attributes of the device.
After doing that, check your automations/groups/scenes, since they will now have dead references that need to be fixed (delete the old name and add the new one).
I just went through this when I updated my HA hardware and had a bunch of stuff renamed for me. For example, the same model Zigbee devices were discovered in a different sequence, so the _2, _3, etc. suffixes were all on different devices than before, and there was a change in the way ESPHome devices are named recently, so those all came in different.
What I learned from this process is to be thankful for YAML configuration. It’s easy to do a batch “find,” or even a “find and replace” against text files like YAML.
The stuff which is only accessible via the UI is tedious to find and update.
Needless to say, I’m not a big fan of “dumbing things down” to only allow configuration via the UI.
If you get a _2 then the old entity still exists. Either make sure the old entity does no longer exist or rename that too. Then you can remove the _2 from the entity id and all is well again.
All this is under the assumptio you never use device triggers, conditions and actions. Those are a pain when replacing stuff.
Or, in my case, adding multiple ZHA devices with the same model number, which are used to create the device (and ultimately, entity) names. I had added devices over time, but when I went to add them all to the new HA host, they went in a different order, hence “_2” wasn’t assigned to the same device it had been before.
I know I can name each device when I add it. But for things like smart plugs, which can move around, I went with just the default hardware model name that ZHA gives it. I give it a “friendly” name in the UI anyway. And I learned early on to keep a separate list, outside of HA, of where all the devices are.
Probably the biggest thing which saved me during this migration was being able to extract the entire UI configuration, or just one view, into YAML files. Then I could do my search and replace edits there. For the other configuration YAML files, the “find in files” option on my text editor came in handy, too.
Discovering that “Rename Entity IDs” option was also a lifesaver in my migration.
I would probably do it differently if I started over from scratch. Give each device a meaningful name, following a standard pattern, when first adding them. To move or repurpose a device, delete it and re-add it with a new name.
Search and replace won’t help you keep gui based things in tact, unless you replace in .storage, which is a very bad idea. So renaming entity ids to match the previous one is by far the best approach. It is less error prone and the least amount of work. Plus, if you do delete the old one and rename the new without restarting in between, you can keep history.