home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.11k stars 31.1k forks source link

ESPHome integration fails to connect after DHCP address reallocated #87875

Closed stonegray closed 1 year ago

stonegray commented 1 year ago

The problem

After DHCP addresses change, ESPHome devices will show as "Attention Required" in the /config/integrations page on the web UI. When clicked, it prompts to update the transport encryption key. Even when the correct key is entered, it rejects it.

(Note: In the following examples, device sonoff-s31-1.local changed from xxx.133 to xxx.132)

This appears to be caused by the DHCP server re-assigning the IP address to another sensor. Using dig to query the address from my computer or server returns the correct result:

 # dig -p 5353 sonoff-s31-1.local @224.0.0.251

; <<>> DiG 9.10.6 <<>> -p 5353 sonoff-s31-1.local @224.0.0.251
;; global options: +cmd
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19651
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;sonoff-s31-1.local.            IN      A

;; ANSWER SECTION:
sonoff-s31-1.local.     120     IN      A       192.168.4.132

;; Query time: 106 msec
;; SERVER: 192.168.4.132#5353(224.0.0.251)

Connecting from the ESPHome web UI, ping etc work fine.

But the logs show that Home Assistant is looking at the wrong address (and thus getting the wrong device; explaining why updating the key does not work)

Logger: aioesphomeapi.reconnect_logic
Source: runner.py:120 
First occurred: February 9, 2023, 11:47:48 PM (8 occurrences) 
Last logged: 5:39:55 AM

Can't connect to ESPHome API for primecables-flexispot-1 @ 192.168.4.134: Invalid encryption key
Can't connect to ESPHome API for sonoff-s31-4 @ 192.168.4.129: Invalid encryption key
Can't connect to ESPHome API for sonoff-powr2-1 @ 192.168.4.128: Invalid encryption key
Can't connect to ESPHome API for sonoff-s31-3 @ 192.168.4.135: Timeout while connecting to ('192.168.4.135', 6053)
Can't connect to ESPHome API for sonoff-s31-1 @ 192.168.4.133: Invalid encryption key

We see sonoff-s31-1.local should be resolving to 192.168.4.132, but is instead using the old 192.168.4.133 address.

What I've tried

What works

I've had this happen a few times now so hoping for a solution. Nothing critical is running on it, and I can switch to MQTT if needed, but this is a pretty big pain to re-add everything by hand.

What version of Home Assistant Core has the issue?

Home Assistant 2023.1.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Esphome

Link to integration documentation on our website

https://www.home-assistant.io/integrations/esphome/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @ottowinter, @jesserockz, mind taking a look at this issue as it has been labeled with an integration (esphome) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `esphome` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign esphome` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


esphome documentation esphome source (message by IssueLinks)

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.