Changing entity_id based on configuration input

I’m trying to add a configuration option to the mitemp_bt custom component. What I would like to achieve is that the user can couple a mac-address to a custom sensor_name in the configuration.yaml and, if specified, that the ‘entity_id’ is changed, based on this input. So, if a name is specified, it uses the specified name, if not, it uses the mac address as default name.

I managed to change the friendly_name attribute in this way, but I also would like to change the entity_id, while keeping the unique_id as it was. People have asked for this function, but I can’t figure out how to change the entity_id, without changing the unique_id as well (which is basically creating a new sensor, while the old one becomes unavailable).

To me, it sound better is only the entity_id is being changed, but I can’t figure out how.

I tried to change the object_id in the class of the sensor like this.

class TemperatureSensor(Entity):
    """Representation of a sensor."""
    def __init__(self, config, mac):
        "Initialize the sensor."""
        self._state = None
        self._sensor_name = sensor_name(config, mac)
        self._object_id = "mi_t_" + self._sensor_name
        self._unique_id = "t_" + mac
        self._device_state_attributes = {}

    @property
    def name(self):
        """Return the name of the sensor."""
        return "Temperature {}".format(self._sensor_name)

    @property
    def object_id(self):
        """Return object id."""
        return self._object_id

Unfortunately, only the friendly_name changes in this way, not the entity_id.