esphome / esphome/feature-requests
Use ids rather than names to identify entities to HA via api
- Dominant language
- No language data
- Stars
- 450
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the problem you have/What new integration you would like**
(I'm posting this in Feature Requests because although it's aimed at fixing a problem, the problem is one of design not implementation, and thus not strictly a bug.)
I recently encountered a problem with HA documented here: https://github.com/home-assistant/core/issues/97726
After some digging it appears the core of the problem is that ESPHome constructs a "unique" id to identify an entity to HA by mangling the entity name and the device name. Changing either name makes it seem that the entity has disappeared and a new one created. So:
1. I propose that the id used within the API should be based on the ESPHome id if provided (if not provided, I guess falling back to name-mangling is the only good option.) This would ensure that entity name changes do not change the identity of the entity.
2. There is no good reason that I can see for including the device name in the unique ID. HA is already able to maintain the device identity across device name changes, and only needs to uniquely identify an entity within the namespace for a given device.
These are obviously significant changes, but in the long term I believe it would make the API more robust. Implementation will have some challenges:
1. Breaking existing devices - clearly it would be unacceptable to have existing devices change their entitities' identities on an upgrade. This should be able to be managed with API versioning.
2. Changes are required on the HA and ESPHome side and will need to be coordinated.
The actual implementation on the ESPHome side shouldn't be too hard, probably more work on the HA side. The biggest obstacle to getting this done will be convincing the respective dev teams that the gain is worth the pain, and that requires some discussion, and devising a workable implementation strategy.
**Please describe your use case for this integration and alternatives you've tried:**
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the linked Home Assistant issue 97726 and then trace how ESPHome currently constructs entity IDs for its API. Review the compatibility and API-versioning constraints for both projects. Done means a coordinated design preserves existing entity identities while allowing stable IDs independent of names.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, embedded-iot
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100