ESPHOME ESP32 intermittent unavailability "Became unavailable"

I have made a custom PCB with an EPS32 wroom module and a couple of Relays, BME and IR (AC Remote) sensors to control my mains switchboard. While this works as expected but I keep getting these intermittent disconnect messages saying “Became unavailable10:49:00 AM - 10 hours ago”.

Under ESPHome I have set up a manual IP and the power-saving mode is disabled while this reduced the number of “Became unavailable” messages but I still get one or two of these messages every day. The PCB is powered through a UPS and 2Amp 5V supply (I changed a couple of supplies too and current supply has been load tested at 5V 2amps). There are ample decoupling and bulk capacitances on PCB(4 decoupling caps and 2x100uF 10V caps) so I am pretty sure power is not an issue.

HA supervisor does not report any error, ESPHOME module logs also do not show anything related to this and I do not see any other logs in HA config folders, is there any way to understand why my PCB keeps intermittently disconnecting from HA, is this some network/module issue or could it be a power-related issue.

Could be this issue; [SOLVED] ESPHome DHCP client problems, temporary solution with manual fixed IP - #37 by mmakaay

I have seen similar with the esp32 and only when using esphome, in my case I fixed it by switching off native API for esphome and using Mqtt instead, since then it’s been stable.
I haven’t yet tried the fix above.

Thanks for the response and pointing out the bug!

MQTT might not be the best solution for me as I need to set up a broker and communication is quite innefficient and I am also not that familiar with ESPhome’s MQTT setup. I’ll try the TCP bug fix in the API and keep you guys posted.

Regards
Anil

Switching to MQTT works, because the issue occurs in the server-side (API makes the ESP device the server, HA the client), while MQTT makes the ESP the client.

Yesterday, I pushed what might be the final fix for the issue: Better fix for "ack timeout 4" client disconnects. by mmakaay · Pull Request #5 · OttoWinter/AsyncTCP · GitHub

I hope this will go in ESPHome 1.18.0, but that is up to the ESpHome maintainers.
You could already try the code by following the instructions from the abovementioned thread.

1 Like

Hi Maurice,

I have applied the ASYNC TCP fix suggested by Swifty. I see the following files related to ASYNC applied during compilation. Hopefully, this fixes the issue will update in a couple of days.

Compiling /data/ho_junctionbox/.pioenvs/ho_junctionbox/lib150/AsyncTCP-esphome/AsyncTCP.cpp.o
Archiving /data/ho_junctionbox/.pioenvs/ho_junctionbox/lib150/libAsyncTCP-esphome.a

Thank you for following up.

Regards
Anil

Did it fix your specific issue?

I have just applied the fix. “became unavailable” used to pop-up every 6-12 hours so ill have to wait and see to confirm the fix.

Regards
Anil Verma B

1 Like

ASYNCTCP fix by mmkakaay seems to have fixed the issue, I no longer get the “became unavailable message”.

1 Like

Because I’m getting various questions about this, I wrote up some collected pointers in the pull request.

1 Like

Awesome…thanks for the step-by-step fix. This will definitely help a lot of people trying to apply this fix the right way.

Here is how my log output looks…

HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif32 3.10004.210126 (1.0.4) 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)
Library Manager: Installing Hash
Library Manager: Already installed, built-in library
Dependency Graph
|-- <AsyncTCP-esphome> 1.1.1
|-- <ESPmDNS> 1.0
|   |-- <WiFi> 1.0
|-- <FS> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
|   |-- <AsyncTCP-esphome> 1.1.1
|   |-- <FS> 1.0
|   |-- <WiFi> 1.0
|-- <Wire> 1.0.1
|-- <DNSServer> 1.1.0
|   |-- <WiFi> 1.0
|-- <Update> 1.0
|-- <WiFi> 1.0

all of a sudden got a bunch of these errors and settled down again. captured these logs in verbose mode at esphome’s docker level.

looks like the error seems to have come back after upgrading to 1.17.2

[10:52:33][D][binary_sensor:036]: 'PIR Sensor': Sending state OFF
[11:00:22][D][api:067]: Disconnecting Home Assistant 2021.5.1 (192.168.1.30)
[11:02:31][D][api.connection:617]: Client 'Home Assistant 2021.5.2 (192.168.1.30)' connected successfully!
[11:02:37][D][api:067]: Disconnecting Home Assistant 2021.5.2 (192.168.1.30)
[11:02:37][D][api.connection:617]: Client 'Home Assistant 2021.5.2 (192.168.1.30)' connected successfully!
[11:13:53][D][binary_sensor:036]: 'PIR Sensor': Sending state ON
[11:14:37][D][binary_sensor:036]: 'PIR Sensor': Sending state OFF
[11:14:55][D][binary_sensor:036]: 'PIR Sensor': Sending state ON
[11:15:38][D][binary_sensor:036]: 'PIR Sensor': Sending state OFF
[11:15:42][D][binary_sensor:036]: 'PIR Sensor': Sending state ON
[11:16:09][D][bme280.sensor:197]: Got temperature=30.4°C pressure=910.9hPa humidity=54.3%
[11:16:09][D][sensor:099]: 'temperature': Sending state 30.41000 °C with 1 decimals of accuracy
[11:16:09][D][sensor:099]: 'pressure': Sending state 910.93469 hPa with 1 decimals of accuracy
[11:16:09][D][sensor:099]: 'humidity': Sending state 54.27246 % with 1 decimals of accuracy
[11:16:22][D][binary_sensor:036]: 'PIR Sensor': Sending state OFF
[11:16:28][D][binary_sensor:036]: 'PIR Sensor': Sending state ON
[11:17:21][D][binary_sensor:036]: 'PIR Sensor': Sending state OFF
[11:18:38][D][api:067]: Disconnecting Home Assistant 2021.5.2 (192.168.1.30)
[11:19:11][D][api.connection:617]: Client 'Home Assistant 2021.5.2 (192.168.1.30)' connected successfully!
[11:19:13][D][binary_sensor:036]: 'PIR Sensor': Sending state ON
[11:19:47][D][api:067]: Disconnecting Home Assistant 2021.5.2 (192.168.1.30)
[11:19:58][D][binary_sensor:036]: 'PIR Sensor': Sending state OFF
[11:20:20][D][api.connection:617]: Client 'Home Assistant 2021.5.2 (192.168.1.30)' connected successfully!
[11:20:27][D][api:067]: Disconnecting Home Assistant 2021.5.2 (192.168.1.30)
[11:20:27][D][api.connection:617]: Client 'Home Assistant 2021.5.2 (192.168.1.30)' connected successfully!
[11:23:50][D][api:067]: Disconnecting Home Assistant 2021.5.2 (192.168.1.30)
[11:24:28][D][api.connection:617]: Client 'Home Assistant 2021.5.2 (192.168.1.30)' connected successfully!

I was extremely frustrated about this ‘became unavailable’ issue. What finally fixed it for me was to set the option power_save_mode: none in the wifi configuration of the ESP32

This is already part of my configuration but the errors still used to appear once or twice a day. What really helped was the “mmmkaay” ASYNC" fix on ESPHome 1.17.1 but a couple of days later ESPHome updated to 1.17.2 and issue came back again. I tried with and without the Async fix on 1.17.2 but does not seem to be helping.

esphome:
#  platformio_options:
#    lib_extra_dirs: /config/esphome/libs
  name: ho_junctionbox
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "*********"
  password: "*********"

  power_save_mode: none
  fast_connect: on

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.15
    gateway: 192.168.1.1
    subnet: 255.255.255.0

So I built another Node but this time with a NodeMCU-32S board (the earlier board was my own custom PCB) and attached it to a couple of relays and BME380. Now both my custom PCB and NodeMCU-32S disconnect and become unavailable sometimes at similar timestamps and sometimes completely random time stamps. At this point, I am not sure if it’s my network/router issue or still something to do with the API on ESPHOME. Logs are at default “debug” mode, BME polling is done every 30 mins and the IR transmitter to control AC runs ad-hoc to control temperature.

image