INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor bus_c_506_0
But in the web ui the sensor is available through:
Entity: sensor.506_karolinska_sjukhuset_c
How does this name mapping work? Why does hass rename the sensor from bus_c_506_9 to 506_karolinska_sjukhuset_c?
Is it possible to avoid this renaming? Have I missed something?
It’s not renaming it from bus_c_506_9 to 506_karolinska_sjukhuset_c.
The sensor’s name is derived from this:
"name": "506 -> Karolinska sjukhuset (C)"
not this:
"unique_id": "bus_c_506_0"
However, you’ve chosen to include several invalid characters in the sensor’s name. Home Assistant removes them, then converts the remaining characters to lowercase and produces this:
Ok, thanks! Why is it deriving the sensors name from the ‘name’ in this way?
What I’m trying to accomplish is to provide a more describing / human readable text in using the json name property. Wouldn’t it be more correct to use the unique_id for naming the sensor?
I’ve searched a bit an found some mentions about “friendly_name” - but it doesn’t seem possible to send this using mqtt in the config json? Is there another way of giving a sensor a more human readable name and at the same time have control over the resulting entity name?
An entity’s friendly_name is what is used to present it in the Lovelace UI. This is what you should use for “human readable text”.
An entity’s name appears in the States page. It is shown in the Lovelace UI only if there is no friendly_name defined.
An entity’s unique_id serves as an identifier and is used in the Entity Registry (think of it as a social insurance number or license plate number). It is not shown in the States page nor in the Lovelace UI.
For definitive answers, you may wish to direct those questions to the developer(s) responsible for creating and maintaining the MQTT Discovery feature.