With the new UI getting better and better it is very beneficient to have any sensor availibe for UI - so that it can be amended to our liking.
Can the unique id be attributed automatically (on attribution of entity name autimatically or via a biult-in service) instead manually input for each and every manually set up entity to benefit from UI?
That would be cool. Why not just automatically use the entity or device name as unique_id. And for all devices/entities automatically generated by integrations simply continue to use the unique number id.
Since no two entities can have the same name, the unique name generated would automatically also be unique.
I would also like to have some kind auf “automated unique id assignment” as it would probably avoid issues like
and plenty of others.
It can’t be the entity id because that can change. That’s one of the the thing having a unique id let’s you do, change the entity id. Plus it can even change accidently on a restart if two integrations try and create an entity with the same id. It’ll just be a race, one will randomly get the id requested, the other will get the id + a number.
And device name definitely doesn’t work. Many entities are not part of a device. And device names are not required to be unique anyway.
The value must be unique and unchanging from the time the entity is first created to when it is removed from HA, no matter how many restarts or whatever occurred in between.
This is what is supposed to happen. An integration is supposed to update to support config entries and unique IDs. And then in it is supposed to generate those unique IDs for users from device/service information in a way it chooses that is guaranteed to be unique.
But there’s a few problems here:
- Integrations have to update to take advantage of this. There’s a lot of integrations, that’s a lot of work. Feature requests help with prioritization but it’s just a time issue.
- For some integrations (like template or command line) there is no device or service info to use to generate a guaranteed unique identifier. So they settled on asking the user for a value.
Now one thing that could be done for #2 is the integration could just generate a guid. That’s what I do after all, probably others too.
However I think even in this case you’d still need a config option like allow_ui_editing
otherwise it would be a breaking change. Because currently all users with command line and template entities that don’t have unique_id
specified are able to change the entity id by simply changing the yaml and can remove the entity by deleting the yaml. Once a unique id is generated then entity IDs can only be changed in the UI and you must delete the entity from the UI.
It might also affect whether the name and icon can be changed in yaml for entities of some integrations, not sure.
Some self-advertising (question which came up during the HA Core 2023.3 update) which shows that it can be a problem adding unique_id
to existing sensors: