core: Esphome devices don't reconnect on zeroconf advertisement

The problem

When an esphome device boots it sends an mDNS advertisement, HA is supposed to catch it and immediately reconnect to the device (which makes reconnections much faster). But in 2023.11.1 this doesn’t seem to work.

In the attached logs it looks like zeroconf sees the device at 16:37:49. At this moment the device is already pingable. But aioesphomeapi tries to connect to it almost a full minute later (I guess during its regular reconnection attempts).

What version of Home Assistant Core has the issue?

core-2023.11.1

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

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-11-06 16:37:49.943 DEBUG (MainThread) [homeassistant.components.zeroconf] service_update: type=_esphomelib._tcp.local. name=led-controller-balcony._esphomelib._tcp.local. state_change=ServiceStateChange.Updated
2023-11-06 16:37:49.943 DEBUG (MainThread) [homeassistant.components.zeroconf] Discovered new device led-controller-balcony._esphomelib._tcp.local. ZeroconfServiceInfo(ip_address=IPv4Address('192.168.50.50'), ip_addresses=[IPv4Address('192.168.50.50')], port=6053, hostname='led-controller-balcony.local.', type='_esphomelib._tcp.local.', name='led-controller-balcony._esphomelib._tcp.local.', properties={'version': '2023.10.3', 'mac': 'bcff4d4c2888', 'platform': 'ESP8266', 'board': 'esp01_1m', 'network': 'wifi', 'api_encryption': 'Noise_NNpsk0_25519_ChaChaPoly_SHA256'})


2023-11-06 16:38:31.344 DEBUG (MainThread) [aioesphomeapi.reconnect_logic] Trying to connect to led-controller-balcony @ 192.168.50.50
2023-11-06 16:38:31.344 DEBUG (MainThread) [aioesphomeapi.reconnect_logic] Connected lock acquired for led-controller-balcony @ 192.168.50.50
2023-11-06 16:38:31.344 DEBUG (MainThread) [aioesphomeapi.connection] led-controller-balcony @ 192.168.50.50: Connecting to 192.168.50.50:6053 (AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.50.50', port=6053)))
2023-11-06 16:38:31.448 DEBUG (MainThread) [aioesphomeapi.connection] led-controller-balcony @ 192.168.50.50: Opened socket to 192.168.50.50:6053 (AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.50.50', port=6053)))
2023-11-06 16:38:31.448 INFO (MainThread) [aioesphomeapi.reconnect_logic] Successfully connected to led-controller-balcony @ 192.168.50.50
2023-11-06 16:38:31.448 DEBUG (MainThread) [aioesphomeapi.reconnect_logic] Removing zeroconf listener for led-controller-balcony

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 35 (32 by maintainers)

Most upvoted comments

@jeroen85 : if you want to try the fix without waiting for 2023.11.2 and you can open a shell inside the homeassistant container: set aioesphomeapi==18.2.4 in /usr/src/homeassistant/homeassistant/components/esphome/manifest.json and restart.

There is a simple logic reversal refactoring error in the lib. https://github.com/esphome/aioesphomeapi/pull/613 will fix it. I also added tests for the zeroconf reconnect logic since we didn’t have anything for it

Here’s the log since the last restart: aioesphome.log

PS. I kept only the entries relevant to this device, otherwise it’s a big mess (I have 30+ devices).