Replacing a device with an identical one doesn't work well in HA

The Home Assistant integration doesn’t seem to handle replacing an ESPHome device particularly well.

The problem seems to stem from the use of the MAC address as a unique identifier for the device.

Basically, I’ve had two instances recently where I’ve swapped out an ESPHome module with an identical device due to a fault (one was a smartplug which got filled with water, the other was a switch module which had a bad relay).

In each case I’ve reflashed the device with an identical configuration: my whole network is built on static IPs to minimize dependencies, so the new device comes up at the same address providing the same services…except that, Home Assistant has trouble relating to it, because the MAC address is different and this is what’s used as the unique ID for entities and devices by ESPHome.

In both cases I’ve had to shutdown Home Assistant, and go into the core.entity_registry and core.device_registry, core.config_entries and replace the old MAC address with the new one to get the device to resume it’s normal place in my automations (I’ve also edited the esphome. file as well here).

This…isn’t great, for what I would consider a normal and expected part of the device lifecycle.

Is there a better option here? Or some parameter or configuration setting I could use to change how the unique IDs are tracked? MAC address is obviously “unique” but its too unique - whether that specific bit of hardware is on the network is not what I want to be unique, it’s whether there is some hardware there which is providing an expected suite of services.

One detail which may matter here is I’m not using mDNS discovery: again, static IPs configured on the devices, with static IPs being programmed into Home Assistant for how to connect. It feels like what’s missing is an option or some automatic logic for this - i.e. what happens when it’s an mDNS or DNS entry?

Yes. Just delete the existing device from the home assistant integration before doing anything. Then flash the new one and let it be discovered. All the entities will be identical and retain their previous history.

1 Like

Do entity name include MAC ? Or both devices produce same entities on joining HA ?
Then just delete particular device integration and discover/join new.

As well static DNS usage just a useless overhead of managing it.