I guess it’s because the change that disallowed device prefix in the name.
As many, I had name: “${device_name} …” in esphome config files everywhere and relied on the auto-generated sensor.device_name_sensor_name_id as the entity_id in home assistant. Friendly names all had the prefix removed and capitalized, looking nice.
Now, updated HA past 2024.2.0 and everything broke. MQTT entities become device_name_device_name_sensor_name, API still good. Okay, I googled, found out, spent all day removing the prefix, reuploaded the firmware to all my devices. Still wrong. Now MQTT devices have a single prefix in the name (not by me, automagically), API devices don’t, those now look like name_2/_3/…, which is completely unaccaptable.
Step 2 - Give the community some idea what MQTT client devices you are using so we can help.
Tasmota? Shelly? Custom code? Paho Python library? Z2MQTT? PDP11 with a serial cable?
“Friendly Name” might hint at Tasmota - which would is very easy to fix:
Configure Other
Device Name = hardware device based - e.g TH16
Friendly Name 1 = usage based - e.g. HW Cylinder
Some folk post issues after adding HASS updates only a few times a year, then don’t update integrations and get issues - e.g. Z2MQTT was updated for this old change several months ago. Personally, a RPi4 makes a good pre-production test-bed if you really don’t like tracking current releases.
I saw that thread. And I understand the naming recommendation. It just creates a problem for me that I am unable to solve.
There are smart plugs, bluetooth sensors, 443mhz sensors, the usual things. All running on esp boards. Some I have at home, some in other locations (where I use mqtt). There is a common yaml code base for the sensors, and depending on the location, I include the mqtt: or the api: yaml files to set the connection type.
With this change I can no longer have the same name. For mqtt I don’t need the prefix, for api I do, because there HA does not put it into the entity_id. I either have double prefix or auto-numbered useless ids, which I cannot use in automations and scripts, becuase I refuse to cross-reference them every time. It also breaks my historical data.
I only use the ESPHome and the MQTT integration. All up to date. This is a very ESPHome specific problem, but it has nothing to do with ESPHome. That’s why I asked it here.
Sorry - I didn’t pick up on the ESPhome tag, only the MQTT problem statement, probably as I assumed (wrongly?) that ESPhome is tightly integrated into HASS, so the transport underneath is pretty transparent (e.g. local API).
For remote MQTT, I’ve only used raw code and not ESPhome so can’t contrast local API verses remote MQTT. The post I linked to includes mosquitto_pub examples if you need to compare the ESPhome code against what the broker and HASS publishes, verses what actually works in MQTTexplorer.
For me, naming is just a case of changing the friendly_name to the human-readable text for each device e.g.
substitutions:
name: "heater-switch" # generic hardware device name
friendly_name: "En Suite Towel Radiator" # human-readable instance name
version_s: "0.4"
esphome:
name: ${name} # generic hardware device name
friendly_name: ${friendly_name} # human-readable instance name
# Automatically add the mac address to the name
# so you can use a single firmware for all devices
#name_add_mac_suffix: true
# This will allow for (future) project identification,
# configuration and updates.
project:
name: floatingboater.$name
version: $version_s
Not relying on autogenerated friendly_name can fix one problem, but that’s only cosmetic. What I really need is a unique entity_id and to be cosistent between both integrations. It used to work. But now MQTT is trying to be smart and prefixes it with the device name. This was not the case.
Not sure in relation to mqtt, but why not just remove the friendly name for the esp and keep the prefix? If there’s no friendly name, the esp won’t prefix it, so you just have your own prefix.
I have no friendly_name in my yaml. The way MQTT integration alters the entity_id is my problem really. It prefixes, like I used to do, device_name + name.
In that case, maybe you should set the friendly name for the esp and not do your own prefixing for the entities? Same as mqtt, that name is prefixed automatically by HA.
To be clear, I’m talking about this, the friendly name for the device (the device name):
esphome:
friendly_name: ${friendly_name} # human-readable instance name
friendly_name (Optional, string): This is the name sent to the frontend. It is used by Home Assistant as the integration name, device name, and is automatically prefixed to entities where necessary.
It is refledted in the entity id for all my devices.
Confirmed. It does affect the id. It’s like a secret hidden function, but kinda important. The id only changes when deleting and re-adding the device. Have to be careful not to be fooled by the old values. And mqtt still does not care, it adds the prefix without asking. At least it is consistent now.