I have an integration for the franklin_wh home energy system, but some of my users have more than one of them and I'm trying to work out how to support that. I can set a nickname in the configuration and template that into my _attr_name if set, but it seems like that's not how hass wants me to do it. I am reading https://developers.home-assistant.io/docs/core/entity/ and it looks like maybe the property I want is unique_id but that says it shouldn't be configurable by the user.
#Trying to support more than one instance of an entity with a friendly name
1 messages · Page 1 of 1 (latest)
You should set a unique_id - like a serial number or something. Then you can use DeviceInfo to assign to different devices. Device name will be prepended to entity name then.
ok, thankyou!
ok, so I tried this out on my local install with something like:
def __init__(self, cache):
self._cache = cache
self._attr_unique_id = "1005000xxxxxxx"
@property
def device_info(self) -> DeviceInfo:
"""Return the device info."""
return DeviceInfo(
identifiers={
# Serial numbers are unique identifiers within a specific domain
("franklin_wh", self.unique_id)
},
name="primary",
)
which I thought would cause either my unique_id or the name primary to wind up in the entity_id but neither did
I'm not really sure where I've made the mistake, the docs say this will only work if it's loaded from a config entry, which I believe is true in my case (it's specified in my configuration.yaml)
Oh right. A config entry is created from a ConfigFlow. Yaml is different.
You'll also need _attr_has_entity_name = True but that may already be set in the base class - not sure right now.
Ah I see, is there a supported way to do this from yaml? I will experiment with _attr_has_entity_name
I'm pretty close to just templating a prefix into the _attr_names but I suspect there are consequences to doing that
No config entry, no devices. You need to at least set up the integration from a config flow. In theory you can still set up entities from yaml then (for a custom component, for core this won't be accepted).