Achronite / mqtt-energenie-ener314rt

MQTT interface for Energenie ENER314-RT add-on board for the Raspberry Pi, designed for use by Home Assistant.
MIT License
13 stars 5 forks source link

Prefix `device_name` to `entity_name` #41

Closed webash closed 1 year ago

webash commented 1 year ago

Since Home Assistant builds the entity_id from the name property of an HA discovery packet, this ensures entity_ids are more specific than just apparent_power.

When displaying the entities, particularly on the device page, Home Assistant will omit the device name part of the string, because it will match the device name and that's how HA device-->entity hierarchy is maintained in the display names.

Having descriptive/specific entity_id is useful when only being able to glance at the entity_id in a config. Similarly, the entity name containing the device name means that if you update the device name, all the entity (display) names of that device also update to match.

Specific name and id make auto-complete/entity-only views clearer when trying to pick something like a reactive_power amongst a list of multiple of them; because now the entity ID or display name tell you which device without having to look it up separately.

How will this affect existing users?

All new users, or any existing users who configure the option AND delete their existing Home Assistant objects will see the intended behaviour, with all entity_id having the device id specified in it.

Any existing users who want this change, but are not wishing to lose the history of objects already added can update the entity_id for each entity manually before or after adding "discovery_entityname_prefix_with_devicename": true to their config file.

webash commented 1 year ago

Ugh, it appears 2023.8 of Home Assistant is changing the behaviour of this. I haven't yet updated, so I'll do that shortly and figure out whether this is still required. Probably isn't.

webash commented 1 year ago

Yep; Home Assistant 2023.8 now finally configures the initial entity_id of an entity linked (via identifier or connection) to a device with the device name included, so that you don't end up with binary_sensor.motion as the entity_id for an MQTT entity configured with only the entity_name of motion. Now it will finally configure that at as binary_sensor.device_name_motion.

So this workaround that I added in this PR is no longer required for anyone on 2023.8 onwards.

I'll leave it open for now, but I'm guessing there isn't much point in adding it

Achronite commented 1 year ago

I used to have the device_name prefixing the entity names, but had to change it due to the changes in naming standards (enforced in HA 2023.8). See #34. So, sorry, I'm going to have to reject this pull request as it is.