Why does MQTT discovery add device name to entity name?

I have a procedure I run (on an external computer) that sends MQTT discovery messages to Home Assistant. I group some of my lights into a device with the name: “HomeVisionXL X10”.

Example:

homeassistant/light/HVXLb1d0d912ed315aad_C_5/config

{
    "uniq_id": "HVXLb1d0d912ed315aad_C_5",
    "name": "C-5 Kitchen Table",
    "ret": false,
    "qos": 1,
    "dev": {
        "ids": [
            "HVXLb1d0d912ed315aad_X10"
        ],
        "name": "HomeVisionXL X10",
        "mdl": "HomeVision",
        "mf": "CustomSolutions"
    },
    "~": "stat/KitchenTable/RESULT",
    "stat_t": "~",
    "cmd_t": "cmnd/KitchenTable/POWER",
    "pl_on": "ON",
    "pl_off": "OFF",
    "stat_val_tpl": "{{ value_json.POWER }}",
    "bri_cmd_t": "cmnd/KitchenTable/POWER",
    "bri_stat_t": "~",
    "bri_scl": "100",
    "bri_val_tpl": "{{ value_json.Dimmer }}",
    "on_cmd_type": "brightness"
}

The above creates an entity, “light.c_5_kitchen_table”, and a Device, “HomeVisionXL X10”.

Looking at the Device in the GUI shows the light as “C-5 Kitchen Table” in the “Controls” list, as expected.

But, when I add the light to an entity card, I get this default name:

HomeVisionXL X10 C-5 Kitchen Table

Why is the device name prepended to the Entity’s name? How to I prevent that?

I know I can manually edit the entity card to delete the device name portion in the name, but I have many entities like this spread out over 10+ devices.

I checked the forum and the web in general, and haven’t found an answer.

Prepending the device name is an architectural decision made a long time ago but wasn’t implemented in the MQTT integration, specifically the MQTT Discovery feature, until version 2023.8.0.

If you don’t want the device name prepended to entity’s friendly_name, you’ll need to do what you have already mentioned (manually rename its friendly_name).

I have several dozen of such entities so I used Manual Customization to modify entity names in bulk.

Copy-paste the following template into the Template Editor.

{% for id in integration_entities('mqtt')
  | map('device_id') | unique | reject ('eq', None) | sort %}
{% set name = device_attr(id, "name_by_user") or device_attr(id, "name") %}
# {{ name }}
{%- for e in device_entities(id) | sort %}
{{ e }}:
  friendly_name: {{ state_attr(e, 'friendly_name') | replace(name, '') | trim }}
{%- endfor -%}
{%- endfor -%}

The Template Editor’s results window should now contain a neatly formatted YAML listing of your MQTT-based entities, grouped by device, showing each one’s entity_id and its friendly_name stripped of its device name.

Example of what the template generated

Each entity’s desired friendly_name has been stripped of its device name (HAI Omnistat2) .

# HAI Omnistat2
binary_sensor.hvac_fan_status:
  friendly_name: Furnace Fan
climate.thermostat:
  friendly_name: Thermostat
sensor.indoor_humidity:
  friendly_name: Indoor Humidity
sensor.indoor_temperature:
  friendly_name: Indoor Temperature

Copy-paste the generated listing into the customize section of your configuration.yaml file. In my case, I have that section in a separate customize.yaml file.

Make any required corrections, like proper YAML indentation, then save the file and restart Home Assistant.

5 Likes

Ah, that may be why I didn’t notice this until (relatively) recently.
I’ll give your work-around a try soon.
Thanks!

Let me know how it goes. You’re the first person (other than me) who will try the template. I’m curious to know how it will perform in your environment.

Just tried it. Works great! Generated a ~300 line (~150 entities over 12 devices) output in the template editor, which I put into a separate .yaml file which I included in comfiguration.yaml.

Saves me a lot of typing! Thanks again.

1 Like

BTW, This is how I added the file:

homeassistant:
  customize: !include customize.yaml
  customize: !include customize_mqtt_disc.yaml

This seems to work, but doesn’t “feel” right (duplicate “customize:” ). But I’m too much of a noob to know for sure if this is OK, or should be done differently.

I think on startup it will use only the second file, not the first one.

Good thing I don’t have anything in the first one yet. :slight_smile:
So is it possible to somehow have multiple include files for one “thing” (like customize:, etc.)
I couldn’t find anything that indicated a way that would do that.

Reference

Splitting up the configuration - Advanced usage

I had read that one, but didn’t see how to do what I wanted. But since you referenced it, I thought I’d better read it again, and eventually did this:

In configuration.yaml:

homeassistant:
  customize:  !include_dir_merge_named customize/

and in a new dir customize, I put

customize.yaml
customize_mqtt_disc.yaml

This seems to work fine, picking up everything in each file - I moved a small portion of the template editor results into what was otherwise an empty customize.yaml to make sure both were picked up.
I’ve since moved that part back to customize_mqtt_disc.yaml and let customize.yaml have any other general customizations I want in the future.

Thank again for your help and patience to a HA noob!

1 Like