Adding new devices and replacing devices

The biggest favour you can do yourself is to rename entities to a functional name when you add new devices.

Let’s say if you’ve added a new device, such as a smart switch to control a light and monitor its power. Let’s also say that the integration that allows you to add it to Home Assistant provides you with a technical entity ID such as switch.shelly_1pm_2f4dee. You should rename this to (for example) switch.living_room_lamp, which describes its purpose.

Doing this will ensure that should you one day need to replace the device, you simply need to rename the new device’s entity to the old name. This will allow any script, automations and dashboards that references it to keep working seemlessly. Importantly, in the case of long-term stats (LTS), it will also allow you to retain the previous device’s stats. You will also retain the recent entity history.

Steps when replacing a device:

  1. Delete the old device and entities (don’t worry; the data is safe and won’t be deleted with it).
  2. Restart HA.
  3. Add the new device.
  4. Rename the entities.
9 Likes

This is good advice. Which, unfortunately, I didn’t have when first setting up HA.

I think the biggest problem with this idea is that, by the time you understand the implications of device and entity names, where they are defined and where they are used, it’s too late.

I’ve got it in my mind that some day I’ll go back and re-name everything. But it’s easy to just put meaningful names on the entities in the UI, and leave the “ugly” names in the background, so that project never seems to make it to the top of the list.

All true.

At least, to keep your metrics and minimise the impact, one could rename the new entities to the old (ugly) entities, but that’s not a great option in many cases, since you may be introducing some ambiguity.

That’s probably where lower-barrier requests (in terms of implementation) such as these come from:

As a software engineer, I don’t like renaming of entities. I prefer entities like “light.key9334811” and then I say “virtual_light.kitchen_ceiling is represented by light.key9334811”.

To understand better, how is it useful keeping the original entity ID?

The one reason I can think of is that it potentially encodes information about the physical device: In my example, one would know it’s a Shelly 1PM (to physically identify it) with a MAC address that ends in 2f:4d:ee (to virtually identify it on your network). But, entities like these always belong to a device, where you can have metadata and even navigate to it.

The cookbook belongs to the community (I have no strong feelings about owning this particular page), as to say I’ll entertain this one comment under the category of a feature request, but otherwise the discussion here should ideally about how to improve the cookbook page itself. :slight_smile:

I have around 2000 entities. If I get a new device, for example a motion sensor, I put it in the living room and test if it does what I want. If not, it is moved maybe to the bathroom. Or after putting a shelly in the kitchen, after 2 weeks I find that the wifi signal is very weak and I replace it with a zigbee device. So devices move around. And I have an excel sheet with all the devices where I note for example the last battery change date. So keeping the original device name as some advantages, but also renaming it to the location can be useful.