This renames the ‘friendly name’, not the entity.
If I rename the device, then the entities are renamed too.
That is if the entities are still using there autogenerated name.
If I have renamed the entities manually then its not renamed with the device.
It renames all of the entity friendly names, plus the IDs, as long as the sub-string match criteria is met.
Oh damn! You are right! I cannot believe i have been renaming each entity name and entity ID individually for every entity! Thanks for the heads up
You have to go to the Device page of the device you want to rename. You are showing the Integrations and Device registry.
Does this take awhile to happen? I bough some WiZ bulbs and have renamed the devices. As initially mentioned, when I changed the device name, I selected “rename” to also rename the device entities. The friendly name of the entities is updating but not the entity_id. I’ve restarted my Yellow a few times now.
I’m curious too, I did a typo entering the name of a device in the companion app… Renaming the device didn’t seem to update the entities Ids.
I’m having the same issue. Even though clicking ‘rename’ on the Rename all the entities? This will break automations!
-question, the entities of some devices refuse to rename.
I thought it could be related to the entities having ‘history’ records (e.g. graphs for temperature etc) but this is wrong. Renaming them one-by-one seems to work.
My other hunch is that this ‘sub-string match criteria’ @freshcoast spoke about does not always work out. For example, one of my devices is called Frient A/S Smoke Sensor SMSZB-120
with entities like sensor.frient_a_s_smoke_sensor_smszb_120_temperature
. Perhaps it chokes on the /
in that name trying to find entities to rename?
Another device i cant rename ‘all at once’ is called lumi.lumi Weather
.
And one that did work was called ‘IKEA of Sweden TRADFRI Remote Control’ without any special characters.
Are we on to a little improvement here?
For the cases where the automatic entity_id-renaming via changing the device name does not work, another way to bulk rename entities is to edit some text/yaml files manually.
I don’t know if this has any negative side-effects, but I’ve done this multiple times and have not noticed anything bad. You only lose the entity’s history, but that also happens when auto-renaming via the device name.
- Using a method of your choice, get access to the “config” folder (e.g. using the add-on “Samba share” or “Terminal & SSH”)
- Open
.storage/core.entity_registry
in a text editor - Use search and replace to rename your entity.
- e.g. I had many lines of this format:
"entity_id": "binary_sensor.lumi_lumi_sensor_magnet_aq2_opening",
, so I searched forlumi_lumi_sensor_magnet_aq2
and replaced withkitchen_window
- e.g. I had many lines of this format:
- If needed, perform the same search and replace on
automations.yaml
,scripts.yaml
, and whatever other yaml files (outside of.storage
) you are using the renamed entities in. I usually do a grep/search for the old entity-prefix to find the files I need to modify. - Restart home assistant. I use the shell command
ha core restart
for this. - Enjoy
I now developed a python script to bulk rename entities with regular expressions and without losing their history:
I just finish renaming lots of my entities with the “Rename all the entities” feature when renaming a device. I actually had to go through the sources of the frontend to find out, what exactly the “sub-string match criteria” means. So, I thought, I’d come back here and drop a note:
The criterion means that all entities will be renamed, if they (a) belong to the device and (b) contain the slugified device name in their entity id. They will be renamed by replacing the old device name by the new device name. So, some_domain.bla_olddevice_battery_2
will become some_domain.bla_newdevice_battery_2
.
I was able to install run this from one of my WSL instances and it works great! Thanks.
I do have one question, trying to run this for a friend of mine who only has access via SSH in HassOS, but doing that reveles that Python is not installed. Is it advisible to install Python3 in HassOS? Any other options?
I’m having this issue, I click on the pencil icon in the device name to rename, but I never get the question to rename all entities at all. Using hass 2024.2.2. Any ideas of what could be wrong? I want to do a mass rename of devices to have a common naming scheme and it would be impossible to do if this doesn’t work. I’d rather not run an “old script posted in the internet” for reliability reasons, don’t want to end up with a messed up installation.
Edit: OK, I see @five5607’s script actually uses the API, it doesn’t mess with the YAML files, so I guess it should be safe, but still if there is supposed to be an official way to do it I’d rather do that.
I don’t really get how he uses Home Assistant if he only has access via SSH, but of the top of my head I see two options:
- Install python into the container either temporarily with
apk add python3
or permanently as documented here. - He could use ssh port forwarding:
- Change
AllowTcpForwarding no
toyes
in/etc/ssh/sshd_config
(I recommend to revert this change afterwards) - Restart the ssh server (I didn’t see a nice way of doing this.
killall sshd
worked. ) - forward homeassistant.local:8123 to localhost:8123:
ssh -N -L 8123:homeassistant.local:8123 your-hassos-server
- Point my script to localhost:8123 and use it like normal.
- Change
Sometimes I used to have an issue when trying to change bulk entity ids by changing the device name due to the "Do you also want to rename the entity IDs of your entities?"
feature not working. This seems to happen when the device name and the device name portion of the entity id do not match. For anyone running into the same issue the solution is to rename the device name so it matches the device name portion of the entity id and then rename it again the way you want.
- Click on one of the device entities and copy the device name portion of the entity id. Ex: In
sensor.echo_dot_next_reminder
copy theecho_dot
portion. - Rename the device to the copied name. Ex:
echo_dot
. - If you check one of the device entity ids it should now match the device name.
- Rename your device again but this time use the name you want.
- When you get the prompt
"Do you also want to rename the entity IDs of your entities?"
make sure you clickRENAME
. - All of the device entity ids should now include the device name.
alighmty59’s suggestion of renaming the device name portion to match the entity id and then renaming the device again helped with one device, although it seems like a fairly bad user interface since nothing is explained to the user and it appears that the entity renaming worked when it didnt.
However, there is another device is stuck with a _2 at the end, e.g. switch_main_bedroom_light_2. There are NO entities without the _2 (there’s no switch_main_bedroom_light). Home assistant gives no notice that the renaming failed, and so you’re stuck looking at the entity table to see. I have a ton of automations referring to the entity without the _2, but I can’t rename the entities to not have it. Manually renaming each one works, but the switch has over 30 entities associated with it.
It appears to be a problem if the Device was previously renamed, and one chose the option to “rename the entity IDs” when they previously did it.
It no longer offers the option to “name the entity IDs” if you try to do it again to the same Device…
This might explain why this “sometimes” happens to people.