ESPHome has delay

esphome:
  name: 3d-printkast
  friendly_name: 3d-printkast

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.20.8
  manual_ip:
    static_ip: 192.168.20.8
    gateway: 192.168.0.1
    subnet: 255.255.255.0
  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "3dprintkast Fallback Hotspot"
    password: ""

captive_portal:

output:
  - platform: gpio
    pin: GPIO23
    id: led
  - platform: gpio
    pin: GPIO25
    id: relay_pin_1
  - platform: gpio
    pin: GPIO26
    id: relay_pin_2
  - platform: gpio
    pin: GPIO27
    id: relay_pin_3
  - platform: gpio
    pin: GPIO14
    id: relay_pin_4

# Define the switches based on the relay pins
switch:
  - platform: output
    id: relay_1
    name: "Relay 1"
    output: relay_pin_1

  - platform: output
    id: relay_2
    name: "Relay 2"
    output: relay_pin_2

  - platform: output
    id: relay_3
    name: "Relay 3"
    output: relay_pin_3

  - platform: output
    id: relay_4
    name: "Relay 4"
    output: relay_pin_4

# Status LED
light:
#   - platform: status_led
#     name: "RelayBoard Led"
#     restore_mode: ALWAYS_ON
#     pin:
#       number: GPIO23
# interval:
#   - interval: 1000ms
#     then:
#       - output.turn_on: led
#       - delay: 500ms
#       - output.turn_off: led

  - platform: neopixelbus
    type: GRB
    variant: WS2812x
    pin: GPIO17
    num_leds: 144
    name: "CR10 3D Pinter"
      



I have 4 relays and a ledstrip. The above code is flashed.
Everything works 1 time, and then it seems like I loose connection or something. Nothing is responsive anymore, sometimes the light and relays do switch after a few minutes of delay.

In the logging I read the following:

WARNING Canā€™t connect to ESPHome API for 3d-printkast @ 192.168.20.8: Timeout while connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address=ā€˜192.168.20.8ā€™, port=6053))] (TimeoutAPIError)
INFO Trying to connect to 3d-printkast @ 192.168.20.8 in the background
INFO Successfully connected to 3d-printkast @ 192.168.20.8 in 0.115s
INFO Successful handshake with 3d-printkast @ 192.168.20.8 in 0.091s

A bit later I get:

[10:04:34][D][api:102]: Accepted 192.168.20.40
[10:04:34][W][component:237]: Component api took a long time for an operation (51 ms).
[10:04:34][W][component:238]: Components should block for at most 30 ms.
[10:04:34][D][api.connection:1321]: Home Assistant 2024.5.5 (192.168.20.40): Connected successfully
WARNING 3d-printkast @ 192.168.20.8: Connection error occurred: 3d-printkast @ 192.168.20.8: EOF received
INFO Processing unexpected disconnect from ESPHome API for 3d-printkast @ 192.168.20.8
WARNING Disconnected from API
INFO Successfully connected to 3d-printkast @ 192.168.20.8 in 0.011s
INFO Successful handshake with 3d-printkast @ 192.168.20.8 in 0.091s
[10:07:04][W][api.connection:129]: Home Assistant 2024.5.5 (192.168.20.40) didnā€™t respond to ping request in time. Disconnectingā€¦
[10:07:04][D][api:102]: Accepted 192.168.20.40
[10:07:04][W][component:237]: Component api took a long time for an operation (51 ms).
[10:07:04][W][component:238]: Components should block for at most 30 ms.
[10:07:04][D][api.connection:1321]: Home Assistant 2024.5.5 (192.168.20.40): Connected successfully
[10:08:10][I][ota:117]: Boot seems successful, resetting boot loop counter.
[10:08:10][D][esp32.preferences:114]: Saving 1 preferences to flashā€¦
[10:08:10][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
WARNING 3d-printkast @ 192.168.20.8: Connection error occurred: 3d-printkast @ 192.168.20.8: EOF received
INFO Processing unexpected disconnect from ESPHome API for 3d-printkast @ 192.168.20.8
WARNING Disconnected from API
INFO Successfully connected to 3d-printkast @ 192.168.20.8 in 0.010s
INFO Successful handshake with 3d-printkast @ 192.168.20.8 in 0.088s

Your gateway is wrong for a start in your static ip subnet you have defined, not sure if that is your issue though.

What would the right gateway be then?

With your data gateway would be probably 192.168.20.1 - try to ping it to see if you get a reply.

And line ā€œuse_address: ā€¦ā€ is used only once when/if you want to change IP of the module, after that you either delete it or comment it out.

.20 is my IOT Vlan and the router that provides the internet has the .0.1 address.

However, I have another ESP32 device with that same gateway setting and use_address setting. And that one is working just fine.

Iā€™m starting to suspect that this device is just made of bad quality? Or the wifi hardware is broken?

After trying multiple different ESP32 devices, I have the same problem

  manual_ip:
    static_ip: 192.168.20.8
    gateway: 192.168.0.1
    subnet: 255.255.255.0
    dns1: 192.168.0.1
    dns2: 8.8.8.8
  fast_connect: true

You could try some extra settings as above. It could also be a router setting. Something as simple as device getting confused if you run 2.4 and 5.8ghz with same ssid name.

1 Like

So I would not exclude wiring/power supply issueā€¦

Looking again at your logs itā€™s more likely a API disconnect than wifi. Are there any logs on HA (settings/system/logs)that mention API disconnects

Have you looked if another device has the same IP address a duplicate IP is a distinct possibility with static addressing. Iā€™d switch off this device and try pinging from the address from your IoT vlan. You could try changing to something different.

I now have a setup with the 4 channel relay board directly connected to the ESP32. No additional powersupply. But still the issue persists.

I have Unifi hardware, so I can pretty easily see who gets which IP. So everything should be in order there.

I agree! My WiFi should be very stable.

Unfortunatly I cannot find anything meaningfull in the logs :confused:

What I also find strange is that when flashing new software OTA.
To add the setting that @Spiro suggested, it takes a long time for the esp32 to start up.

The reason is the following:

[07:26:39][D][api:102]: Accepted 192.168.20.40
[07:26:39][W][component:237]: Component api took a long time for an operation (51 ms).
[07:26:39][W][component:238]: Components should block for at most 30 ms.
[07:26:39][D][api.connection:1321]: Home Assistant 2024.5.5 (192.168.20.40): Connected successfully

But I have no idea why the API components takes so long or how to resolve / trouble shoot this.

Switch to using MQTT for that device and see if problems go away.

Got any pointers on how to get started on this?

I can run a docker container with an MQTT server, but how do I configure a client device?

# Enable Home Assistant API
#api:
#  encryption:
#    key: ""

mqtt:
  broker: ip address of your broker
  username: user name of broker
  password: password of broker

ā€œ#ā€ out the lines that refer to api and add lines above

1 Like

I dontā€™ want insist but the problem could be opposite, Esp not getting enough power causing a voltage drop. Always better with external PSU.
I personally would test that setup with some simple arduino code to exclude hardware issue.

I have had tries yesterday with only PSU power. 5V 15A PSU where I regulated the voltage to be 5V, even under load.

I got it to work, first time for me using MQTT with HomeAssistant.

However the delay is the same, and it is caused due to a disconnection.

MQTT logs:

1716713307: New client connected from 192.168.20.11:53441 as 3dprintkastv2-b8d61a5f196c (p2, c0, k15, uā€™homeassistantā€™).
1716713408: Client 3dprintkastv2-b8d61a5f196c closed its connection.

HA Logs:

Logger: aioesphomeapi.connection
Source: runner.py:190
First occurred: 10:31:57 AM (10 occurrences)
Last logged: 10:50:58 AM

  • 3dprintkastv2 @ 192.168.20.11: Connection error occurred: 3dprintkastv2 @ 192.168.20.11: EOF received
  • 3dprintkastv2 @ 192.168.20.11: Connection error occurred: [Errno 104] Connection reset by peer