ESPHome encryption key is invalid

I have noticed this lately also. Seems to be happening on a lot of devices I renamed at some point by going to esphome, then rename (config file never touched). While not the exact issue, it’s almost like it thinks the name and friendly_name are 2 different devices now. Certainly sporadic but just noticed it in a lot of devices renamed at some point. Maybe I’m way off, just something I noticed. I also should do some esphome and orphan entity cleanup so that’s on me.

I am also having trouble with this. Device has been added and removed and renamed a couple of times. Now the following occurs

  1. Do clean install with a new device name through esphome.
  2. HA sees new device and asks to configure it.
  3. No request for api key, device is just integrated into HA.
  4. Device works fine for several days
  5. Suddenly HA asks to reconfigure device and then will request api key. The api key I get from esphome is not recognized.
  6. I delete the device from HA and reboot
  7. HA sees the device again and asks to configure it.
    Now go back to step 4

It does this even if I remove the api key all together in esphome.
Driving me nuts!

Simply disable the device, restart Home Assistant then enable the device again!!! It worked for me

2 Likes

Same here. Happened after a router change. Carefully recorded all IPS and macs before change and recreated them on new router but all esp home devices said they were offline in espweb but data was being received ok in HA. I’m left with a device that is difficult to access so not easy to connect to serial. Tried the suggestions above about disabled and restart HA but didn’t work. Anyone else solved it? I won’t be the only person to change a router with esp home devices on the network.

Hi! How did you accessed your previous build? where is it saved? Thanks!

I got it from the esp page. No clue why it gets confused
same key as before

Still no solution?

Not sure that there is a problem

FWIW, I have had notifications that things need to be reconfigured. After a reboot they go away. I think my Synology VM host is slow.

I have run into this. I believe it happens when it gets an IP of another existing ESPHome device that has that IP. Just speculation but something I noticed. Since HA relies on mDNS since it just cares about IP address. You can setup zeroconf but I think that’s a bit of a headache just for name resolution.

When an mDNS client needs to resolve a hostname, it sends an IP multicast query message that asks the host having that name to identify itself. That target machine then multicasts a message that includes its IP address. All machines in that subnet can then use that information to update their mDNS caches. Any host can relinquish its claim to a name by sending a response packet with a time to live (TTL) equal to zero.

By default, mDNS exclusively resolves hostnames ending with the .local top-level domain. This can cause problems if .local includes hosts that do not implement mDNS but that can be found via a conventional unicast DNS server. Resolving such conflicts requires network-configuration changes that mDNS was designed to avoid.

I started statically defining the network address in the config file and haven’t had that issue since doing so.

2 Likes

I’m pretty sure the issue is mdns and how it works (see previous post). You can setup zeroconf for a real DNS solution because mdns only seems to care about the IP by design.

I believe I have same issue. I have a ESP32 board that works with Home Assistant. It did take several attempts to flash it and get it to communicate with HA, but it is currently working. All sensors are working great. The problem is I cannot update this board because it complains of an invalid encryption key. I also cannot connect to download logs. I have a key in the yaml but it is clearly not the same that is on the card. Is there anything I can do besides reflashing?

This seems to have worked for me too. Thanks!
i.e. disable the device (settings, devices, ESPHome, click three dots next to device name, Disable), restart HA, then Enable the device, restart HA again.

For anyone coming to this in 2024, I have just come across this issue while re-installing my athom smart plugs. I ended up just setting secrets for all the plugs and dereferencing the same exact encryption key in all unique secrets. I believe my issue is that for some reason, ESPHome is using a yaml file which acts as though only one device configuration needs to be read, so it picks the first one added. I noticed that the initial plug integration add didn’t even ask me for the key.

Hence, I realized that it must be failing because it wants me to use the same key in the yaml file which was used for the first device added.

Here is an example:

api:
  encryption:
    key: !secret athm-plg-6-key

All the devices use the same key string, however, they have a unique secret, just in case this gets fixed and I can go back to using unique encryption keys within the dereferenced secrets.

1 Like

Worked on a ESP 8266 as well

The problem I had was a bad TTL adapter, it was using a fake RT232 chip, the moment I used a TTL adapter with a CP2102 chip it worked without a problem.
I guess not many people use a TTL adapter but I wasn’t able to plug it in directly.

I solved my issue.
I hade the same error message. The problem for me was that the device was removed in both HA and ESPHome. I removed the alert by using vscode and search for the name of the device, i found it in the trash. I renamed the file adding .old after .yaml (espname.yaml.old) restarted homeassistant and the isuse was gone.