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.
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.
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.
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.
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.
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.
[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.
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.