I recently started trying out the ESPHome Add-On in home assistant. With this, I was able to add and upgrade some ESP devices, however I soon realized after adding one of them, that the auto-generated name may not be wanted (or if you’re moving a device around and want a new name). So I did some research and worked out the process for renaming the device in ESPHome.
Configs
We want to start out by modifying the configuration for the ESP device. This is done through the ESPHome addon (since that allows editing and installing the new configs). We’ll start by changing the name in the config, and adding the current IP address as the “use_address” option in the config. The use address option will be removed later to allow DHCP to work correctly.
esphome: name: new_name ... wifi: use_address: old_name.local ...
Install the new config to add the name to the device. Once its installed, remove the use_address, and install again. I also renamed the device access point name during this process.
wifi: ssid: !secret wifi_ssid password: !secret wifi_password # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "new_name" password: "long good password"
Once the device is renamed and the configs are done, you then go in and change the filenames on the system for the device. This can be done using VS Code and selecting the file, hitting F2 (shortcut for editing filenames) and changing the name (making sure to follow the naming convention).
This worked, though the old name did stay showing up in ESPHome as a device that could be added. I believe this was due to using a separate PC and ESPHome web to add the device. This phantom device disappeared after a while (and a possibly a reboot). The newly renamed device stayed available in home assistant and could be integrated into automations and remotely updated using ESPHome.