Better handling of MAC address mismatch with ESPHome devices

If you delete a config entry that was created before the current friendly naming system was introduced (or before you set a friendly name in the ESPHome config)—and it used the legacy naming scheme—those names won’t be preserved when you re-add the device. The new config entry will follow the updated naming rules.

Backwards compatibility for entity names and IDs only applies for the lifetime of the existing config entry. Once a new entry is created, the updated rules take effect.

The naming behavior is documented here:
Entity Naming and IDs Documentation

And the relevant code can be found here:

Also, device name conflicts aren’t currently handled automatically. When a conflict occurs, an error is logged, and manual resolution is required.

This pull request aims to improve that behavior:

1 Like

The PR was introduced more than 26 months ago. They first installed their device 8 months ago.

But then added the friendly name 6 months ago (without deleting the device) and it did not change the entity ids.

Only when deleting and re-adding the device were the entity ids changed.

I adjusted the post to clarify:

If you delete a config entry that was created before the current friendly naming system was introduced (or before you set a friendly name in the ESPHome config)

1 Like

Well, the plot thickens a little. It turns out that the presence or not of a friendly name does affect the constructed entity names for a device - but it’s not the friendly name that gets used!

So if I add a device with this config:

esphome:
  name: esp-testing

Then for the “Uptime” sensor I get an entity named sensor.uptime. So the device name has been ignored.

But if I change the config to:

esphome:
  name: esp-testing
  friendly_name: ESP Test

Then delete and re-add the device, now the same sensor is called sensor.esp_testing_uptime.

So while the presence of the friendly name has an effect, its value is not used for this purpose, the name is. Now it makes sense to me that the name should be used, but it makes no sense that it is only used if the friendly name is set.