Help with unique_id and name sensor translate

Hi all, in my integration I’m trying to assign default names to the sensors, based on unique_id.
This is because the sensor changes when it is translated, and takes its name from the translated entity_id.
Assuming I have a sensor with
unique_id: “batterysoc”
translation_key(ita translate): “Batteria Soc”

the sensor is called: sensor.batteria_soc, I would like it to be called sensor.batterysoc

in order to standardize the names for everyone, and give unique directives

class EpCubeSensor(CoordinatorEntity, SensorEntity):
    def __init__(self, coordinator, description):
        super().__init__(coordinator)
        self.coordinator = coordinator
        self.entity_description = description
        self._attr_unique_id = f"epcube_{description.key}"
        self._attr_entity_id = f"sensor.epcube_{description.key}"
        self._attr_has_entity_name = True
        self._attr_unit_of_measurement = description.native_unit_of_measurement
        self._attr_device_class = description.device_class
        self._attr_state_class = description.state_class
        self._attr_entity_category = description.entity_category
        self._attr_device_info = {
            "identifiers": {("epcube", "epcube_device")},
            "name": "EPCUBE",
            "manufacturer": "CanadianSolar",
            "model": "EPCUBE",
            "entry_type": "service",
            "configuration_url": "https://monitoring-eu.epcube.com/"
        }

and for generate sensor:


        translation_key = f"{base_key}_{suffix_label}" if suffix_label else base_key
        
        sensor = SensorEntityDescription(
            key=key,
            translation_key=translation_key,
            native_unit_of_measurement=unit_of_measurement,
            device_class=device_class,
            entity_category=entity_category,
            state_class=state_class,
            entity_registry_enabled_default=entity_registry_enabled_default
        )

full code here: GitHub - Bobsilvio/epcube: Custom Home Assistant integration for monitoring the EP Cube energy storage system.

The default sensor name is based on the device_class (Sensor entity | Home Assistant Developer Docs) so a sensor named sensor.batterysoc is not possible, it will always become like sensor.battery_something.

1 Like

But nowadays the sensor name is changed when translated I think.
So translate it is “Batteriasoc”, then name will contain batterysoc.

On the other hand, if you would even want to add your integration to HA, better stick to the “rules” now :slight_smile: