ESPHome API Authentication Expired

All of my ESPhome devices seem to need their API key reinstating every 12 hours or so at random. I have a full list of repairs for ESPHome devices. I haven’t changed anything on the ESPHome devices. Sometimes just clicking on the repair is enough, and sometimes it brings up the windows to paste in the API key.

How might I resolve this?



All YAML files have encryption key inside ?

Yes, all devices have a unique API key in their YAML file.

Screenshot 2024-05-06 at 11.12.18 AM

Looks fine. Can You share one device complete config ?
To see more details - DHCP/Static, name, …

Me using same API key for all devices to have less administrative overhead.
It allow to keep key once in secrets.yaml. 30+ devices - remmeber no issues with API.

substitutions:
  devicename: desk-fan
  friendly_name: Desk Fan
  device_description: Sonoff Basic in Desk Fan

esp8266:
  board: sonoff_basic

esphome:
  name: ${devicename}
  comment: ${device_description}

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${friendly_name}
    password: !secret AP_Password

captive_portal:

web_server:

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "uWkcub+U+5rZ5Bb5gPJQc6LaUeE1S0nXMTHbDMlSBI0="

ota:
  password: !secret OTA_Password

fan:
  - platform: binary
    output: output_1
    name: "Fan"

output:
  - platform: gpio
    pin: GPIO12
    id: output_1

status_led:
  pin:
    number: GPIO13
    inverted: yes

This is a basic device I have configured. All devices are DHCP with unique key. I did have one common key in secrets but I changed to unique keys to try stop multiple devices appearing for the same integration.

Home Assistant seems to be getting confused if devices change IP address by DHCP. When I click “visit” on a device page, it takes me to the webpage of a different ESPHome device. I thought ESPHome used hostnames to prevent this?

What that mean ?
I have that “picture” in Integrations view:
image

IMHO AFAIK ESPHome devices anyway will be show grouped under same Integration regardless of same of different api encryption keys.

Had same issues ?

Never seen that in my environment for 2+ years.
DHCP is for IP assignment, then mDNS for name resolving.

Can try “Bonjouir Browser” for Windows to see mDNS in local network segment.

DHCP would assign an IP which used to be assigned to ESPHome device “X” to ESPHome device “Y”. Because the API keys were common to all devices, Home Assistant would accept device Y into the same integration as device X because, as far as it was concerned, the IP is the same and the key is accepted so it must be the same device, right? This would cause 2 devices to register under one integration:

Safe to say, my ESPHome devices ended up in a mess. To fix this I used unique API keys, so even if the IP was reassigned to another ESPHome device, it wouldn’t accept it into the old devices integration. I suspect this is now why I get the issues I have today.

This is what I thought, and Home Assistant uses mDNS to resolve ESPHome hostnames so it should be irrelevant what IP it has.

1 Like

Stuff happens not exactly in this way, as You described.

IP address of device does not matter, it have only meaning for IP packet transmission, not for ESPHome and HA devices naming.


This happened not because of same key, not because of changed IP.
But because of assigning same name to multiple devices and not deleting obsolete one - lack of housekeeping…
When You decide to assign same name to another device - need to delete previous one.

Believe me, lot of people use same key for devices, DHCP for IP assigning - and no duplicates.
As well lot of topics created before - when and why more ESPHome devices become as single HA device. Just need to take care of clean up.

Sorry my bad English.

But still have no idea about original issue :frowning:

One of my esphome devices has decided it’s authentication has expired.

Weird thing is, it doesn’t even have a key in the yaml. And it isn’t even plugged in so isn’t on the network.

There is definitely no duplicate device names. All my ESPHome devices have always had unique names. Each ESP chip has only ever been programmed specifically for the device it controls. I’ve never reused a ESP chip from an obsolete device and uploaded a config from a different device to it, so no issues with duplicate MAC addresses etc. By your theory I would have had to duplicate every device, because it used to happen with every device before I changed to unique keys. That has definitely not happened.

My theory was on the basis that if a device was assigned an IP which was previously assigned to another ESPHome device Home Assistant got confused and registered it as a new device under the old devices integration because the API key was the same across the board. Now I have changed to unique keys, it doesn’t add it to the old integration and instead complains because the API key of the new device (which it thinks is the old one) doesn’t match the old device that was using that IP.

Have same Home Assistant software as all around, 30+ ESPHome devices on DHCP only & same api key for all of them.

Multiple ESPHome devices was associated with single HA device when and only same device name used on more boards while testing, upgrades, etc. That’s my experience so far.

Yeah, in my case it seemed to be devices with completely different names that would associate with a single home assistant device.