Mass Customizing Similar Entities & Renaming Entity IDs

I’m trying to get my head around how I satisfy my OCD within the constraints of Home Assistant and the halfway world it is possibly in between UI and configuration.yaml (?) right at the minute.

  1. I have several identical door/window sensors created as devices by Zigbee2Mqtt (and also Zwave2Mqtt). Each has sensor entities for various "…_electric_consumption_X’ where X is “a” (current), “v” (voltage), “kw” (power) and “kWh” (energy). Ideally, I’d like to name them all something like “Energy Usage [kWh]: Device Name” and “Power [kW]: Device Name”.

I can’t see that you can use customize_glob.yaml to achieve this. I know you can use a wildcard to identify all the “sensor.*_electric_consumption_kwh”, for example, but then it appears you’d have to set the friendly_name for each to something identical such as “Energy Usage”. You can’t use the wildcard somehow in the output? This works fine for a device card where the devices name is at the top, but if you use all these energy entities on the Energy Dashboard (again, for example) then you’ll have “n” ambiguously named sensors. Is there a way around this that isn’t manually entering each in the UI?

  1. The UI lets me edit entity_id so if I wanted to clean up the “electric_consumption_kwh” to something shorter and more elegant like “power_kwh” (and I’m sure someone once said “energy can’t be created or destroyed/consumed” anyway!) it appears I can… but whether I should is a different story.

How does renaming entities work with integrations such as Zigbee2Mqtt? Is there a primary key in this mystical registry somewhere that I’m not privy to that allows this, or will it break the matrix exercising this power? At times it won’t let me rename an entity because that ID already exists… but for the life of me I can’t find that entity in the UI so I feel like I’m missing part of the story. (In that actual instance I was removing an auto appended “_2” that has been added to avoid duplicate entities created by the integration, but I can’t see the original copy and think it may have been deleted. Geez it would be nice to clean this up and delete any orphans etc properly.)

1 Like

I use shell scripts for this sort of stuff using the hass-cli

Thanks for this. Will take a detailed look. From what I can tell but, these are commands you execute from CLI to make a change, and whilst you can use a wildcard and possibly make changes quicker than the UI, every time a new device is added you’d need to re-run the command to change its entities right?

Yes, since I typically have multiple of the same devices, over time I have built a library of these naming scripts, packages and automations that get applied for every device of a specific type. This was its easy to make a change to the “template” and update multiple devices. For example, adding a low temperature alert to every temperature sensor.

You could also go directly into the .storage folder and edit the entity configuration directly - its all in one file, You should only do this with HA shutdown and make a backup in case you hose up the file.