WTH no entity and friendly names freedom when creating mqtt entities

point 1
The current behavior is inconsistent, depending on whether an entity is assigned to a device or not.

point 2
Due to point 1, adding device to existing entities, breaks current entity naming, thus HA instance.

point 3
There is arbitrary naming way, not giving instance owners to decide about entity names and friendly names

point 4
Points above leads to unreadable representation in GUI (ie Device page)

Current state

  • if name and device are provided

    • the friendly name will be <device_name> <name>
    • the entity name will be <device_name>_(normalized_name) - where normalized name is the original name converted to match lowercase alphanumeric characters and underscore pattern
  • if object_id, name and device are provided, it ignores object_id, applying naming as above

  • if object_id and device are provided

    • entity name is set based on object_id as expected
    • friendly name gets screwed.

here is an example of the last one

Device name: Shelly 3EM MainHouse
Entity definition:

- object_id: "shelly_3em_phase_6_power"
        unique_id: shelly_3em_phase_6_power
        state_topic: "shellies/shelly3em/emeter/1/power"
        unit_of_measurement: "W"
        device_class: power
        device:
          connections: [["mac", "xxxxxxxxxx"]]

The result:
entity name: sensor.shelly_3em_phase_6_power
friendly name: friendly_name: Shelly 3EM MainHouse Powerwhats is this? device name + device class? Really?

It renders on the device page this way:

image

The need
We need to be able to be able to set entity name as well as friendly name.

Possible options:

  • (preferred) add friendly_name to yaml
  • (preferred) Why not use name to be a friendly name when it’s set together with object_id
  • make use of text found in object_id, maintaining original form (event right now it’s possible to put there mixed case, spaces etc).

You can edit both friendly name and entity name in the UI, provided the entity has an “unique id”, which is then, well, the unique identifier of that entity.

I don’t want to edit anything manually.
I’m asking for ability to set it up in yaml.

Actually it worked as I need until I’ve added devices. Since that it’s generates names I don’t want. Example with 3 the same friendly names is extreme example of how bad it’s executed

Not a chance anything will be added back to YAML.
If you want to change in code, do it in .storage/core.config_entries. Unsupported, so at your own risk.

Why? Isn’t HA still evolving?
While there is a trend to provide GUI functionality, yaml is not abandoned afaik. until mqtt entities can be officially created with use of yaml (there are obvious benefits if one chooses this way), it might be subject for improvement always. Isn’t it?

At least there is a serious bug in how it works right now, which should be looked at.

It doesn’t make sense.
I want to control my entities just by editing them in yaml and getting the job done. No additional steps are needed. This is one of the reasons of using yaml.

AFAIK it can be achieved with mqtt discovery. But this is like scratching behind the left ear with the right hand

Anyway, I was raising the issue. I’m not asking for “if it will be resolved”.
Please do not downvote it by saying it cannot be done, it’s not gonna be done etc. I put different questions.

It basically is:

also:

Integrations that communicate with devices and/or services are only configured via the UI. In rare cases, we can make an exception.

Tell me how can I create mqtt entity using GUI. None? Then it’s space to make the exception.

4 years after this document was created, yaml-based mqtt entities still are supported. If supported, and some shortcomings are found, they deserve to be worked on. This is what I’m asking for.

A lot of things were stated as impossible in the past, but then changed (or at least some of them changed their mind about impossibility). So let this question open, please.

You can only upvote a WTH, there’s no downvote button. And anyone can voice their opinion, no? That doesn’t necessarily affect what the devs do with the request.

Maybe I’m taking crazy pills here but I’ve never had a problem with this, I always supply unique_id, object_id, device name, and name. The configuration always takes all 4 and properly uses them without overwriting anything.

unique_id: 832389f9zs8dflaehf9pafeialjhfnalskeejhf
object_id: shelly_3em_phase_6_power
name: MainHouse
state_topic: "shellies/shelly3em/emeter/1/power"
unit_of_measurement: "W"
device_class: power
device:
  connections: [["mac", "xxxxxxxxxx"]]
  name: Shelly 3EM

Will result in a device name of Shelly 3EM an entity name of Shelly 3EM Mainhouse with an entity_id of sensor.shelly_3em_phase_6_power.

I have a number of entities where I alter all 3 and all 3 have different values. They aren’t “ignored”.

e.g. Here’s my discovery info

{
  "name": "Day Cycle",
  "unique_id": "front_yardds",
  "object_id": "front_yard_day_cycle",
  "state_topic": "homeassistant/number/front_yardds/state",
  "command_topic": "homeassistant/number/front_yardds/state",
  "command_template": "{{ value }}",
  "min": 1,
  "max": 10,
  "unit_of_measurement": "days",
  "device": {
    "name": "Front Yard Sprinker Cycle",
    "identifiers": [
      "front_yard"
    ],
    "manufacturer": "Petro"
  },
  "retain": true
}

Here’s my resulting entity:

Showing device name as Front Yard Sprinker Cycle and an entity name of Day Cycle

With the entity_id matching my configured object_id number.front_yard_day_cycle

maybe this is why the mqtt portion of my configuration is the longest part of my configuration

Discovery? Where can I get this info from to verify?

You know… I’ve never had problems with yaml mqtt. I started to used devices not long ago. And didn notice such thing. but with this particular device HA makes up unexpected names. (stripping phase X out of initial text)

So this is real example. I’m adding just another yaml entries to existing device (see unrealistic phase number).

here are 3 combinations

pck_power_metering:
  mqtt:
    sensor:
      - object_id: "shelly_3em_phase_1_power"
        name: "Shelly 3EM Phase 1 Power"
        unique_id: shelly_3em_phase_1_power
        state_topic: "shellies/shelly3em/emeter/0/power"
        unit_of_measurement: "W"
        device_class: power
        device:
          connections: [["mac", "XXXXXXXXX"]]
          name: "Shelly 3EM MainHouse"
          configuration_url: "http://192.168.107.75"
          manufacturer: "Allterco Robotics"
          model: Shelly 3EM
          model_id: SHEM-3

      - object_id: "shelly_3em_phase_5_power"
        name: "Shelly 3EM Phase 5 Power"
        unique_id: shelly_3em_phase_5_power
        state_topic: "shellies/shelly3em/emeter/1/power"
        unit_of_measurement: "W"
        device_class: power
        device:
          connections: [["mac", "XXXXXXXXX"]]

      - object_id: "shelly_3em_phase_6_power"
        unique_id: shelly_3em_phase_6_power
        state_topic: "shellies/shelly3em/emeter/1/power"
        unit_of_measurement: "W"
        device_class: power
        device:
          connections: [["mac", "XXXXXXXXX"]]

      - name: "Shelly 3EM Phase 7 Power"
        unique_id: shelly_3em_phase_7_power
        state_topic: "shellies/shelly3em/emeter/1/power"
        unit_of_measurement: "W"
        device_class: power
        device:
          connections: [["mac", "XXXXXXXXX"]]

So it’s either build the friendly name from device name and entity name, or just makes up the name from unknown pattern (without phase X - see example with phase 6)

Or it’s me who hallucinating?

Here is another entity with the device definition


You aren’t providing device name in any of them…

It also looks like you overwrote the friendly name manually.

Added device definition to above post.

no, I’m not touching GUI. Those entities are just created by hitting reaload of “Manually configured mqtt entities”

The result of this would be:

entity_id of sensor.shelly_3em_phase_1_power because of object_id: "shelly_3em_phase_1_power". The device name will be Shelly 3EM MainHouse because of device: name: "Shelly 3EM MainHouse" and the friendly_name will be Shelly 3EM MainHouse Shelly 3EM Phase 1 Power because of name: "Shelly 3EM Phase 1 Power"

What you should have done was…

pck_power_metering:
  mqtt:
    sensor:
      - object_id: "shelly_3em_phase_1_power"
        name: "Phase 1"
        unique_id: shelly_3em_phase_1_power
        state_topic: "shellies/shelly3em/emeter/0/power"
        unit_of_measurement: "W"
        device_class: power
        device:
          connections: [["mac", "XXXXXXXXX"]]
          name: "Shelly 3EM Mainhouse"
          configuration_url: "http://192.168.107.75"
          manufacturer: "Allterco Robotics"
          model: Shelly 3EM
          model_id: SHEM-3

and you’d end up with:

entity_id: sensor.shelly_3em_phase_1_power
device name: Shelly 3EM Mainhouse
name: Shelly 3EM Mainhouse Phase 1

And when you looked at the device page, it would show Phase 1.

TLDR: You odd naming comes from the fact you’re putting the device name in the entity name.

The naming structure in all of HA, not just MQTT is:

DeviceName EntityName for friendly names of entities. If the DeviceName is in the EntityName, your entity_id and Friendly Name will have double DeviceName. The entity_id is derived from the resulting Friendly Name.

MQTT has the unique ability to override the entity_id in all cases by supplying object_id.

First to say: I really appreciate you entered discussion about this problem. Thank you.

Yes I know that.
It’s all might be generalized to a request to allow overriding the friendly name from yaml too. (I remember there were such requests in the past)

Still we don’t know answer, why Phase X is being stripped from friendly name. It seems like a bug. it looks like Device Name Device Class. Or I’m overlooking something.

PS. I have no certainty about phase 1 entity is not touched through GUI. This is why I’m creating examples with further phase numbers.

That won’t happen. Sorry.

Show me the config entry for the entity where you say phase x is being removed.

config/.storage/config_entries → then search for shelly_3em_phase_1_power

Also, share a screenshot of that entity in developer tools → states page.

It’s a few posts above:

See example for phase 6 (there is source code and screenshot from developer tools)

I need to see the config entry.

and just so you understand, you don’t have a name for that

      - object_id: "shelly_3em_phase_6_power"
        unique_id: shelly_3em_phase_6_power
        state_topic: "shellies/shelly3em/emeter/1/power"
        unit_of_measurement: "W"
        device_class: power
        device:
          connections: [["mac", "XXXXXXXXX"]]

so at most it will get the name from the device.

Remember, object_id only overrides the entity_id, nothing else.

So to me, already there’s no mystery why phase 6 is missing, because you don’t have it in the name.

OK. But the name is given in excample “Phase 5”. And the name is ignored. Or rather… it’s concatenated with the device name.

Simply there is no way how to define final version of friendly name in yaml, if device name is set.