ESPHome devices in HA become unavailable

Issue:
After a inconsistent amount of time (1-2 days) the ESPHome devices become unavailable in HA, but devices are still reachable via direct URL

Background:
I have a few Sonoff S26 (UK plugs) that have been flashed with ESPHome.
Just before xmas I moved to a new ISP (BT > Sky) which is where my problems started. At one point I thought this might be a mDNS issue so updated the devices to use static addressing but didn’t fix it. Strangely another day I changed the DNS lease length from 2 days to 1 hour (as per my BT Hub) and immediately the ESP devices came back in HA (but issue returned soon). Restarting the Sky router fixes the issue for a while, but it comes back…

When this happens I can reach the devices via its IP in a browser, so its still connected to the network ok, its just unavailable in HA.
An example of the log (via IP) is as follows:-

16:39:55	[D]	[api:103]	Accepted 192.168.0.63
16:39:55	[W]	[component:237] Component api took a long time for an operation (290 ms).
16:39:55	[W]	[component:238] Components should block for at most 30 ms.
16:40:53	[W]	[api.connection:130]  didn't respond to ping request in time. Disconnecting...

I’m not sure how the HA integration works, the above logs implies the HA integration maybe polls the device but I don’t know which part is not responding - Is it the server to the device or other way around?

If I ping the ESPHome device from HA docker, it responds, implying there aren’t any obvious networks issues between the devices.

But additionally when using the ESPHome docker to access the devices (although they show as online) i get the following:-

INFO ESPHome 2024.12.2
INFO Reading configuration /config/sonoffplug1.yaml...
INFO Starting log output from 192.168.0.121 using esphome API
INFO Successfully connected to sonoffplug1 @ 192.168.0.121 in 0.003s
WARNING Can't connect to ESPHome API for sonoffplug1 @ 192.168.0.121: Handshake timed out after 30.0s (TimeoutAPIError)
INFO Trying to connect to sonoffplug1 @ 192.168.0.121 in the background
WARNING sonoffplug1 @ 192.168.0.121: Connection error occurred: sonoffplug1 @ 192.168.0.121: Connection lost
INFO Successfully connected to sonoffplug1 @ 192.168.0.121 in 0.003s

Any help or suggestions would be appreciated.

Setup:
Unraid Server
Home Assistant Core Docker (host)
ESPHome Docker (host)

Check firewall log on router.

Nothing in the logs related to either device (HA or ESHome). Just a few blocked IPV6 attempts.


|FW.IPv6 FORWARD drop , 4948 Attempts, 2025/1/15 14:35:55|Firewall Blocked||
| --- | --- | --- |
|FW.IPv6 INPUT drop , 10418 Attempts, 2025/1/15 14:35:55|Firewall Blocked|
|FW.IPv6 FORWARD drop , 4957 Attempts, 2025/1/15 14:38:11|Firewall Blocked||
| --- | --- | --- |
|FW.IPv6 INPUT drop , 10467 Attempts, 2025/1/15 14:38:11|Firewall Blocked||
|FW.IPv6 INPUT drop , 20026 Attempts, 2025/1/14 16:56:45|Firewall Blocked||
|FW.IPv6 FORWARD drop , 11263 Attempts, 2025/1/14 16:56:45|Firewall Blocked|

Port 6053 is used for communication between ha and esp device. For some reason device can’t communicate to ha and vice versa. And this should somewhere be logged.
You can also check for mdns using avahi-browse -a to see if any device is shown.

Nothing local is blocked on the router, only inbound:-

**LAN-to-WAN :** Allow all.
**WAN-to-LAN :** Block as per below and enable IDS.
IDENT (port 113)

I configured static IP addresses for the ESP devices, so surely mDNS shouldn’t be an issue, but regardless ‘avahi-browse -a’ via the Unraid console included the following;-

+    br0 IPv4 sonoffplug1                 _esphomelib._tcp     local
+    br0 IPv4 sonoffplug1                 _http._tcp           local

You are using both containers in host mode. Sometimes i had problem running ha in host mode. I never look into why. You could try to disable host mode and set ha container to port mode like

    ports:
      - "8123:8123/tcp"
      - "20165:21065/tcp"
      - "5353:5353/udp" 

and do

docker compose up -d

if you are using docker compose. If nothing change revert it back.