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
70.13k stars 29.18k forks source link

ESPHome - Recorded IP address of ESP device changes on HASS reboot. #118239

Open jamespreedy opened 2 months ago

jamespreedy commented 2 months ago

The problem

IP address changes incorrectly for ESPHome devices, causing entities to appear unavailable in HASS.

Logger: aioesphomeapi.reconnect_logic
Source: runner.py:190
First occurred: 12:04:58 PM (2 occurrences)
Last logged: 12:04:58 PM

Can't connect to ESPHome API for esp-kitchen-atom @ 192.168.1.232: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.232', port=6053))]: [Errno 113] Connect call failed ('192.168.1.232', 6053) (SocketAPIError)
Can't connect to ESPHome API for esp-bedroom-3-atom @ 192.168.1.237: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.237', port=6053))]: [Errno 113] Connect call failed ('192.168.1.237', 6053) (SocketAPIError)

What version of Home Assistant Core has the issue?

core-2024.5.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

ESPHome

Link to integration documentation on our website

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

Diagnostics information

Relevant config from devices in ESPHome.

wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
  fast_connect: true
  domain: .local
  manual_ip:
    static_ip: 192.168.1.118
    gateway: 192.168.1.1
    subnet: 255.255.254.0
    dns1: 192.168.1.2
    dns2: 192.168.1.3
wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
  fast_connect: true
  domain: .local
  manual_ip:
    static_ip: 192.168.1.113
    gateway: 192.168.1.1
    subnet: 255.255.254.0
    dns1: 192.168.1.2
    dns2: 192.168.1.3

If I delete devices from Home Assistant, they reappear with zeroconf and ask to be added. When I add them, they are added to .storage/core.config_entries with correct IP addresses.

  {
    "entry_id": "c8f77fc536a70c4afd81093bb1b73a0b",
    "version": 1,
    "minor_version": 1,
    "domain": "esphome",
    "title": "ESP Bedroom 3 Atom",
    "data": {
      "host": "192.168.1.118",
      "port": 6053,
      "password": "",
      "noise_psk": "d2GOSAW0BQBaDrH/qTU781xxKgwOvLaLy061r+8oMe4=",
      "device_name": "esp-bedroom-3-atom"
    },
    "options": {
      "allow_service_calls": false
    },
    "pref_disable_new_entities": false,
    "pref_disable_polling": false,
    "source": "zeroconf",
    "unique_id": "34:b7:da:5e:b2:10",
    "disabled_by": null
  },
  {
    "entry_id": "414db1cb51031243bbab2c446bf29793",
    "version": 1,
    "minor_version": 1,
    "domain": "esphome",
    "title": "ESP Kitchen Atom",
    "data": {
      "host": "192.168.1.113",
      "port": 6053,
      "password": "",
      "noise_psk": "d2GOSAW0BQBaDrH/qTU781xxKgwOvLaLy061r+8oMe4=",
      "device_name": "esp-kitchen-atom"
    },
    "options": {
      "allow_service_calls": false
    },
    "pref_disable_new_entities": false,
    "pref_disable_polling": false,
    "source": "zeroconf",
    "unique_id": "34:b7:da:5e:aa:80",
    "disabled_by": null

However, when HASS is rebooted, .storage/core.config_entries is updated, and incorrect IPs replace correct IPs.

      {
        "entry_id": "c8f77fc536a70c4afd81093bb1b73a0b",
        "version": 1,
        "minor_version": 1,
        "domain": "esphome",
        "title": "ESP Bedroom 3 Atom",
        "data": {
          "host": "192.168.1.237",
          "port": 6053,
          "password": "",
          "noise_psk": "d2GOSAW0BQBaDrH/qTU781xxKgwOvLaLy061r+8oMe4=",
          "device_name": "esp-bedroom-3-atom"
        },
        "options": {
          "allow_service_calls": false
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "zeroconf",
        "unique_id": "34:b7:da:5e:b2:10",
        "disabled_by": null
      },
      {
        "entry_id": "414db1cb51031243bbab2c446bf29793",
        "version": 1,
        "minor_version": 1,
        "domain": "esphome",
        "title": "ESP Kitchen Atom",
        "data": {
          "host": "192.168.1.232",
          "port": 6053,
          "password": "",
          "noise_psk": "d2GOSAW0BQBaDrH/qTU781xxKgwOvLaLy061r+8oMe4=",
          "device_name": "esp-kitchen-atom"
        },
        "options": {
          "allow_service_calls": false
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "zeroconf",
        "unique_id": "34:b7:da:5e:aa:80",
        "disabled_by": null
      }

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-05-27 12:33:44.359 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for esp-kitchen-atom @ 192.168.1.232: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.232', port=6053))]: [Errno 113] Connect call failed ('192.168.1.232', 6053) (SocketAPIError)
2024-05-27 12:33:44.743 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for esp-bedroom-3-atom @ 192.168.1.237: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.237', port=6053))]: [Errno 113] Connect call failed ('192.168.1.237', 6053) (SocketAPIError)

### Additional information

MDNS looks ok on local network.

$ dns-sd -q esp-kitchen-atom.local DATE: ---Mon 27 May 2024--- 12:07:29.965 ...STARTING... Timestamp A/R Flags IF Name Type Class Rdata 12:07:29.966 Add 2 0 esp-kitchen-atom.local. Addr IN 192.168.1.113 12:07:30.211 Add 2 14 esp-kitchen-atom.local. Addr IN 192.168.1.113 12:07:30.545 Add 2 12 esp-kitchen-atom.local. Addr IN 192.168.1.113 12:07:45.969 Rmv 0 0 esp-kitchen-atom.local. Addr IN 192.168.1.113 12:07:48.642 Add 2 0 esp-kitchen-atom.local. Addr IN 192.168.1.113

and 

$ dns-sd -q esp-bedroom-3-atom.local DATE: ---Mon 27 May 2024--- 12:08:34.482 ...STARTING... Timestamp A/R Flags IF Name Type Class Rdata 12:08:34.484 Add 2 0 esp-bedroom-3-atom.local. Addr IN 192.168.1.118 12:08:34.843 Add 2 14 esp-bedroom-3-atom.local. Addr IN 192.168.1.118 12:08:35.279 Add 2 12 esp-bedroom-3-atom.local. Addr IN 192.168.1.118 12:11:09.666 Rmv 0 0 esp-bedroom-3-atom.local. Addr IN 192.168.1.118 12:11:11.002 Add 2 0 esp-bedroom-3-atom.local. Addr IN 192.168.1.118 12:12:16.110 Rmv 0 0 esp-bedroom-3-atom.local. Addr IN 192.168.1.118 12:12:17.668 Add 2 0 esp-bedroom-3-atom.local. Addr IN 192.168.1.118


DNS resolves ok on local network.

$ dig esp-bedroom-3-atom.local

; <<>> DiG 9.10.6 <<>> esp-bedroom-3-atom.local ;; global options: +cmd ;; Got answer: ;; WARNING: .local is reserved for Multicast DNS ;; You are currently testing what happens when an mDNS query is leaked to DNS ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40042 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;esp-bedroom-3-atom.local. IN A

;; ANSWER SECTION: esp-bedroom-3-atom.local. 0 IN A 192.168.1.118

;; Query time: 1 msec ;; SERVER: 192.168.1.2#53(192.168.1.2) ;; WHEN: Mon May 27 12:12:35 BST 2024 ;; MSG SIZE rcvd: 69

and

$ dig esp-kitchen-atom.local

; <<>> DiG 9.10.6 <<>> esp-kitchen-atom.local ;; global options: +cmd ;; Got answer: ;; WARNING: .local is reserved for Multicast DNS ;; You are currently testing what happens when an mDNS query is leaked to DNS ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51218 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;esp-kitchen-atom.local. IN A

;; ANSWER SECTION: esp-kitchen-atom.local. 0 IN A 192.168.1.113

;; Query time: 0 msec ;; SERVER: 192.168.1.2#53(192.168.1.2) ;; WHEN: Mon May 27 12:12:54 BST 2024 ;; MSG SIZE rcvd: 67

home-assistant[bot] commented 2 months ago

Hey there @ottowinter, @jesserockz, @kbx81, @bdraco, 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` Renames 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


esphome documentation esphome source (message by IssueLinks)

akdri commented 4 days ago

Same problem.

If I change the device's IP in the Esphome code, when the device is updated it works correctly, but if you restart home assistant, it loses the connection with the device, having to update all the devices whose IP was changed every time you restart home assistant so that it recognizes them again.

Until they fix it I have gone back to the old IPs