Question regarding MQTT auto discovery and naming of entities

Hi!

I’m experimenting with MQTT and HomeAssistant and I’m having some issues…

I’m publishing topics and payloads like this:

  1. homeassistant/sensor/bus_c_506_0/config
{
  "unique_id": "bus_c_506_0",
  "name": "506 -> Karolinska sjukhuset (C)",
  "state_topic": "homeassistant/sensor/bus_c_506_0/state",
  "icon": "mdi:bus",
  "availability_topic": "homeassistant/sensor/bus_c_506_0/availability",
  "value_template": "{{ value_json.display_time }}"
}
  1. homeassistant/sensor/bus_c_506_0/availability
    "online"
  2. homeassistant/sensor/bus_c_506_0/state:
    {"display_time":"3 min"}

In the log I then can then see messages like:

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?

Best regards

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:

 506_karolinska_sjukhuset_c

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?

Best regards

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.

Ok! Thanks for clarifying this, I’m a bit new to HomeAssistant.

I tried to send friendly_name using mqtt, but that doesn’t seem to work, in the logs I’m getting an exception:

2019-10-23 23:38:00 ERROR (MainThread) [homeassistant.components.mqtt.sensor] Exception in async_discover_sensor when dispatching 'mqtt_discovery_new_sensor_mqtt': ({'unique_id': 'tram_3_22_1', 'name': 'tram_3_22_1', 'state_topic': 'homeassistant/sensor/tram_3_22_1/state', 'icon': 'mdi:tram', 'availability_topic': 'homeassistant/sensor/tram_3_22_1/availability', 'friendly_name': '22 -> Solna station (3)', 'value_template': '{{ value_json.display_time }}', 'platform': 'mqtt'},)
Traceback (most recent call last):
  File "/home/homeassistant/venv/lib/python3.7/site-packages/homeassistant/components/mqtt/sensor.py", line 81, in async_discover_sensor
    config = PLATFORM_SCHEMA(discovery_payload)
  File "/home/homeassistant/venv/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/home/homeassistant/venv/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/home/homeassistant/venv/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: extra keys not allowed @ data['friendly_name']

So it doesn’t seem to be possible to send friendly_name over mqtt, maybe I’m doing it wrong?

Best regards

It’s not listed as one of the supported parameters. See the list here: MQTT Discovery

Yes, I wonder why? Are there any architectural issues in supporting friendly_name over mqtt or is it just that it hasn’t been implemented yet?

For definitive answers, you may wish to direct those questions to the developer(s) responsible for creating and maintaining the MQTT Discovery feature.

Yes. I’ve created an account on the discord server…
Thanks for your time and input!

Did you find a solution.
Having the same issue.

You can send the name, but not the friendly name.