ESPHome MQTT devices have duplicated names

This problem started with the MQTT name change in 2023.8, I am now on 2023.8.4 which was supposed to remove some of the change and did not help me.

Short version: Names that looked like piano_outlet now look like piano_oulet_piano_outlet with a duplicated name, which broke all the scripts, automations, and such.

I have tried a variety of things without success. It appears I can sometimes fix this by changing the “Name:” attribute in the esphome file to be slightly different, but that appears to only work when I have invalid device names (I had old names with an underscore, which esphome does not now allow as best I can tell).

The problem APPEARS to be that if the “Name” field in the esphome file has the device name as part of it, it gets duplicated. If I leave it out, it does not duplicate but then devices disappear as duplicated.

Example consider these two separate files (all the other stuff omitted as irrelevant):

esphome:
  name: "piano-outlet"
switch:
  - platform: gpio
    name: "Switch"

esphome:
  name: "north-outlet"
switch:
  - platform: gpio
    name: "Toggle"

This yields devices:

switch.piano_outlet_switch
switch.north_outlet_toggle

If instead I change the word toggle to “switch” then the north_outlet_switch disappears and it complains about a duplicate in the log (oddly complaing about piano not north). This despite being in separate devices in separate files (and the MQTT topics are appropriately different).

If instead, which is what I had at first, I do this:

esphome:
  name: "piano-outlet"
switch:
  - platform: gpio
    name: "Piano Outlet Switch"

esphome:
  name: "north-outlet"
switch:
  - platform: gpio
    name: "North Outlet Switch"

This yields devices:

switch.piano_outlet_piano_outlet_switch
switch.north_outlet_north_outlet_switch

with duplicated names. Which also do not work with existing scripts (and I really do not want those as then google assistant I have to repeat the names).

I installed 2023.8.4 because it was supposed to have a change to this, but I see no difference.

Am I missing something or did they just fundamentally break the MQTT link from ESPHOME?

Should I try switching to the API? I’ve never used the API.

Linwood

I probably should add this: I use MQTT for device discovery for home grown devices like a weather station, generating my own discovery topic and data topics. Those continue to work fine. The only problem is coming from the ESPHOME devices.

I set up the API vs MQTT and using legacy naming this works fine. Though I actually prefer MQTT since it will auto-discover, I don’t have to manually link them in by IP. So I would still like to know if it is possible to keep using MQTT and have my names work.

This whole 2023.08 change to MQTT names is a real pain.

This could be a bug. You should only get prefixed device names from the friendly_name (not name):

https://esphome.io/components/esphome.html#configuration-variables
Screenshot 2023-09-03 at 11-09-47 ESPHome Core Configuration

There appear to be two issues open for this:

1 Like

I ended up changing all of the devices I had to the API, because it appears this duplication of naming is a feature, at least it is defended aggressively when people complained.

Interestingly all of my MQTT devices that are home grown MQTT topics, not esphome, continued to work fine.

Hopefully this posting will give other people a workaround for the naming change that was rolled out.

I’m about to upgrade one ESPHome device from 2022.12.8 to the latest version. I learned about the “prefix problem” from HA Changelogs as well as the forum. Currently, all the sensor entities from my ESPHome are shown in HA without a device prefix.

Does anyone know what happens to my sensor data if the ESPHome integration should change the entity names of my sensors after the upgrade? Will I loose all the historic data of those sensors in the database?

In my case it was Home Assistant and/or changes to MQTT (i’m still not clear) that caused the problem, not an ESPHOME upgrade. Or at least it appeared to be. There is not a lot of visibility in what duplicates the names.

Did you loose any history because of the changed entity names? That’s my biggest worry.

You won’t lose any history even if the entity_ids change. The history will still be accessible via the old entity id. So just change the entity id back to what it was and you are all good.

I didn’t check, history is not that important to most of what I have.

Thank you @tom_l @Linwood !

The history is important to me. On the other hand I don’t have any automations with the ESPHome sensors.

I’ll do the upgrade now and report how it went.

Everything went smoothly and and the entity names have not been changed in Home Assistant. History is there as well.

I’m guessing it’s because I don’t have the friendly_name property in my esphome yaml config?

I don’t think you are out of the woods since the name seems fine after the esphome update to the version you are now. I am on esphome 2023.6.5 and I did something stupid recently. I wanted to delete a mqtt device that was not in use but was showing up in HA. I thought I was deleting just that mqtt device, but instead I deleted the MQTT integration. Reinstalling the mqtt integration fixed it, but it duplicated some entity names such like one of the esphome device I am still using mqtt and not the api.

I am same boat with Linwood, either change all the names manually (52 entities were affected) or go with the api method.