ESP2866 sometimes disconnects from API after toggling

I configured a Shelly 1 with ESPHome, latest version.
Most times it works, but sometimes it disconnects from HomeAssistant after toggling the Switch of the device (either via HomeAssistant or via the connected Switch).
After that, it takes random time (3 Minutes to 1 hour) to reconnect. It is still connected to WiFi.
When I open the ESPHome-Interface in HA, the availability changes from offline to online. Then the Device also reconnects to HA.

Can anybody help me?

Greetings,
Wolfgang

Here is my config:

# Basic Config
esphome:
  name: silvia
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Silvia Fallback Hotspot"
    password: !secret wifi_password

  manual_ip:
    static_ip: 192.168.0.104
    gateway: 192.168.0.1
    subnet: 255.255.255.0

  power_save_mode: none
  fast_connect: on
  
captive_portal:

# Enable logging
logger:
api:

ota:
  password: "..."

web_server:
  port: 80
  
# Device Specific Config
switch:
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay
    name: "silvia power"
    restore_mode: RESTORE_DEFAULT_OFF

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "silvia switch"
    on_press:
      then:
        - switch.toggle: shelly_1_relay
    internal: true
    id: switchid
    
# Sensors with general information.
sensor:
  # Uptime sensor.
  - platform: uptime
    name: ${device_name} Uptime

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: ${device_name} WiFi Signal
    update_interval: 60s

Serial logs is what you/we need to don’t make wild guesses only :wink:

Maybe the HA logs also tell us a little bit… :page_with_curl:

Sorry, my settings regarding notifications were wrong :thinking:

The HA-Logs only tell

2023-01-23 18:34:47 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for silvia @ 192.168.0.68: Error connecting to ('192.168.0.68', 6053): [Errno 111] Connect call failed ('192.168.0.68', 6053)

Do I have to connect the ESP-Device with USB to get the serial-logs, or do you think, the wireless log console will do it’s job, as long as I catch the moment it’s going away?

I understand that the device is connected to WiFi, but is the WiFi signal strength strong enough? Can you relocate the device and get a different result?
Do pings drop? Other than the mains cable in, what else is connected to the Shelly?

A wireless console log will do, set the LEVEL to VERBOSE and record maybe 5 mins of logs from initialisation.

WiFi strength is not good, as the device is placed inside a full metal coffee maker.
Because of that, the WiFi AP is located in the same room only two meters away, so the strength stays within -63 - -70 dB.

The shelly is powering the coffee maker, so the mains in and out as well as the power switch are connected to it.

Pings seem to be stable.

The strange thing is, sometimes it stays connected 24 hours, and some other time, it disconnects every 3 minutes.

Here is the logs of changing the loglevel to verbose and starting the device:

INFO Reading configuration /config/esphome/silvia.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing silvia (board: esp01_1m; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- ESPAsyncTCP-esphome @ 1.2.3
|-- ESPAsyncWebServer-esphome @ 2.1.0
|   |-- ESPAsyncTCP-esphome @ 1.2.3
|   |-- Hash @ 1.0
|   |-- ESP8266WiFi @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- ArduinoJson @ 6.18.5

[...All the compiling...]

Archiving /data/silvia/.pioenvs/silvia/libFrameworkArduino.a
Linking /data/silvia/.pioenvs/silvia/firmware.elf
RAM:   [====      ]  40.9% (used 33520 bytes from 81920 bytes)
Flash: [====      ]  43.1% (used 441561 bytes from 1023984 bytes)
Building /data/silvia/.pioenvs/silvia/firmware.bin
esp8266_copy_factory_bin(["/data/silvia/.pioenvs/silvia/firmware.bin"], ["/data/silvia/.pioenvs/silvia/firmware.elf"])
======================== [SUCCESS] Took 183.44 seconds ========================
INFO Successfully compiled program.
INFO Connecting to 192.168.0.104
INFO Uploading /data/silvia/.pioenvs/silvia/firmware.bin (445712 bytes)
INFO Compressed to 307379 bytes
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.0.104 using esphome API
INFO Successfully connected to 192.168.0.104
[12:37:25][I][app:102]: ESPHome version 2022.11.3 compiled on Jan 25 2023, 12:35:16
[12:37:25][C][wifi:504]: WiFi:
[12:37:25][C][wifi:362]:   Local MAC: E8:DB:84:D7:62:70
[12:37:25][C][wifi:363]:   SSID: 'athomebaby_EXT'[redacted]
[12:37:25][C][wifi:364]:   IP Address: 192.168.0.104
[12:37:25][C][wifi:365]:   BSSID: C0:C9:E3:DF:EB:70[redacted]
[12:37:25][C][wifi:367]:   Hostname: 'silvia'
[12:37:25][C][wifi:369]:   Signal strength: -67 dB ▂▄▆█
[12:37:25][C][wifi:373]:   Channel: 2
[12:37:25][C][wifi:374]:   Subnet: 255.255.255.0
[12:37:25][C][wifi:375]:   Gateway: 192.168.0.1
[12:37:25][C][wifi:376]:   DNS1: 0.0.0.0
[12:37:25][C][wifi:377]:   DNS2: 0.0.0.0
[12:37:25][C][logger:293]: Logger:
[12:37:25][C][logger:294]:   Level: VERBOSE
[12:37:25][C][logger:295]:   Log Baud Rate: 115200
[12:37:25][C][logger:296]:   Hardware UART: UART0
[12:37:25][C][switch.gpio:050]: GPIO Switch 'silvia power'
[12:37:25][C][switch.gpio:051]:   Pin: GPIO4
[12:37:25][C][switch.gpio:073]:   Restore Mode: Restore (Defaults to OFF)
[12:37:25][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'silvia switch'
[12:37:25][C][gpio.binary_sensor:016]:   Pin: GPIO5
[12:37:25][C][uptime.sensor:031]: Uptime Sensor '${device_name} Uptime'
[12:37:25][C][uptime.sensor:031]:   Device Class: 'duration'
[12:37:25][C][uptime.sensor:031]:   State Class: 'total_increasing'
[12:37:25][C][uptime.sensor:031]:   Unit of Measurement: 's'
[12:37:25][C][uptime.sensor:031]:   Accuracy Decimals: 0
[12:37:25][C][uptime.sensor:031]:   Icon: 'mdi:timer-outline'
[12:37:25][V][uptime.sensor:031]:   Unique ID: 'e8db84d76270-uptime'
[12:37:25][C][captive_portal:088]: Captive Portal:
[12:37:25][C][web_server:125]: Web Server:
[12:37:25][C][web_server:126]:   Address: 192.168.0.104:80
[12:37:25][C][mdns:103]: mDNS:
[12:37:25][C][mdns:104]:   Hostname: silvia
[12:37:25][V][mdns:105]:   Services:
[12:37:25][V][mdns:107]:   - _esphomelib, _tcp, 6053
[12:37:25][V][mdns:109]:     TXT: version = 2022.11.3
[12:37:25][V][mdns:109]:     TXT: mac = e8db84d76270
[12:37:25][V][mdns:109]:     TXT: platform = ESP8266
[12:37:25][V][mdns:109]:     TXT: board = esp01_1m
[12:37:25][V][mdns:109]:     TXT: network = wifi
[12:37:25][V][mdns:107]:   - _http, _tcp, 80
[12:37:25][C][ota:093]: Over-The-Air Updates:
[12:37:25][C][ota:094]:   Address: 192.168.0.104:8266
[12:37:25][C][ota:097]:   Using Password.
[12:37:25][C][api:138]: API Server:
[12:37:25][C][api:139]:   Address: 192.168.0.104:6053
[12:37:25][C][api:143]:   Using noise encryption: NO
[12:37:25][C][wifi_signal.sensor:009]: WiFi Signal '${device_name} WiFi Signal'
[12:37:25][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[12:37:25][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[12:37:25][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[12:37:25][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[12:37:26][V][wifi_signal.sensor:009]:   Unique ID: 'e8db84d76270-wifisignal'
[12:37:58][V][sensor:076]: '${device_name} Uptime': Received new state 49.638000
[12:37:58][D][sensor:126]: '${device_name} Uptime': Sending state 49.63800 s with 0 decimals of accuracy
[12:37:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:37:58][V][json:051]: Size after shrink 80 bytes
[12:38:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -69.000000
[12:38:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -69.00000 dBm with 0 decimals of accuracy
[12:38:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:38:01][V][json:051]: Size after shrink 88 bytes
[12:38:58][V][sensor:076]: '${device_name} Uptime': Received new state 109.638000
[12:38:58][D][sensor:126]: '${device_name} Uptime': Sending state 109.63800 s with 0 decimals of accuracy
[12:38:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:38:58][V][json:051]: Size after shrink 80 bytes
[12:39:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -69.000000
[12:39:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -69.00000 dBm with 0 decimals of accuracy
[12:39:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:39:01][V][json:051]: Size after shrink 88 bytes
[12:39:58][V][sensor:076]: '${device_name} Uptime': Received new state 169.638000
[12:39:58][D][sensor:126]: '${device_name} Uptime': Sending state 169.63800 s with 0 decimals of accuracy
[12:39:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:39:58][V][json:051]: Size after shrink 80 bytes
[12:40:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -69.000000
[12:40:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -69.00000 dBm with 0 decimals of accuracy
[12:40:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:40:01][V][json:051]: Size after shrink 88 bytes
[12:40:58][V][sensor:076]: '${device_name} Uptime': Received new state 229.638000
[12:40:58][D][sensor:126]: '${device_name} Uptime': Sending state 229.63800 s with 0 decimals of accuracy
[12:40:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:40:58][V][json:051]: Size after shrink 80 bytes
[12:41:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -69.000000
[12:41:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -69.00000 dBm with 0 decimals of accuracy
[12:41:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:41:01][V][json:051]: Size after shrink 88 bytes
[12:41:58][V][sensor:076]: '${device_name} Uptime': Received new state 289.638000
[12:41:58][D][sensor:126]: '${device_name} Uptime': Sending state 289.63800 s with 0 decimals of accuracy
[12:41:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:41:58][V][json:051]: Size after shrink 80 bytes
[12:42:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -70.000000
[12:42:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -70.00000 dBm with 0 decimals of accuracy
[12:42:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:42:01][V][json:051]: Size after shrink 88 bytes
[12:42:17][I][ota:113]: Boot seems successful, resetting boot loop counter.
[12:42:58][V][sensor:076]: '${device_name} Uptime': Received new state 349.638000
[12:42:58][D][sensor:126]: '${device_name} Uptime': Sending state 349.63800 s with 0 decimals of accuracy
[12:42:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:42:58][V][json:051]: Size after shrink 80 bytes
[12:43:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -70.000000
[12:43:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -70.00000 dBm with 0 decimals of accuracy
[12:43:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:43:01][V][json:051]: Size after shrink 88 bytes
[12:43:58][V][sensor:076]: '${device_name} Uptime': Received new state 409.638000
[12:43:58][D][sensor:126]: '${device_name} Uptime': Sending state 409.63800 s with 0 decimals of accuracy
[12:43:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:43:58][V][json:051]: Size after shrink 80 bytes
[12:44:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -69.000000
[12:44:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -69.00000 dBm with 0 decimals of accuracy
[12:44:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:44:01][V][json:051]: Size after shrink 88 bytes
[12:44:58][V][sensor:076]: '${device_name} Uptime': Received new state 469.638000
[12:44:58][D][sensor:126]: '${device_name} Uptime': Sending state 469.63800 s with 0 decimals of accuracy
[12:44:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:44:58][V][json:051]: Size after shrink 80 bytes
[12:45:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -71.000000
[12:45:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -71.00000 dBm with 0 decimals of accuracy
[12:45:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:45:01][V][json:051]: Size after shrink 88 bytes
[12:45:58][V][sensor:076]: '${device_name} Uptime': Received new state 529.640015
[12:45:58][D][sensor:126]: '${device_name} Uptime': Sending state 529.64001 s with 0 decimals of accuracy
[12:45:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:45:58][V][json:051]: Size after shrink 80 bytes
[12:46:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -68.000000
[12:46:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -68.00000 dBm with 0 decimals of accuracy
[12:46:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:46:01][V][json:051]: Size after shrink 88 bytes
[12:46:58][V][sensor:076]: '${device_name} Uptime': Received new state 589.638000
[12:46:58][D][sensor:126]: '${device_name} Uptime': Sending state 589.63800 s with 0 decimals of accuracy
[12:46:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:46:58][V][json:051]: Size after shrink 80 bytes
[12:47:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -76.000000
[12:47:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -76.00000 dBm with 0 decimals of accuracy
[12:47:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:47:01][V][json:051]: Size after shrink 88 bytes
[12:47:50][D][binary_sensor:036]: 'silvia switch': Sending state ON
[12:47:50][D][switch:021]: 'silvia power' Toggling OFF.
[12:47:50][D][switch:037]: 'silvia power': Sending state OFF
[12:47:50][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:47:50][V][json:051]: Size after shrink 68 bytes
[12:47:50][D][binary_sensor:036]: 'silvia switch': Sending state OFF
[12:47:58][V][sensor:076]: '${device_name} Uptime': Received new state 649.638000
[12:47:58][D][sensor:126]: '${device_name} Uptime': Sending state 649.63800 s with 0 decimals of accuracy
[12:47:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:47:58][V][json:051]: Size after shrink 80 bytes
[12:48:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -67.000000
[12:48:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -67.00000 dBm with 0 decimals of accuracy
[12:48:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:48:01][V][json:051]: Size after shrink 88 bytes
[12:48:21][D][switch:013]: 'silvia power' Turning ON.
[12:48:21][D][switch:037]: 'silvia power': Sending state ON
[12:48:21][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:48:21][V][json:051]: Size after shrink 68 bytes
[12:48:31][D][switch:017]: 'silvia power' Turning OFF.
[12:48:31][D][switch:037]: 'silvia power': Sending state OFF
[12:48:31][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:48:31][V][json:051]: Size after shrink 68 bytes
[12:48:47][D][switch:013]: 'silvia power' Turning ON.
[12:48:47][D][switch:037]: 'silvia power': Sending state ON
[12:48:47][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:48:47][V][json:051]: Size after shrink 68 bytes
[12:48:58][V][sensor:076]: '${device_name} Uptime': Received new state 709.638000
[12:48:58][D][sensor:126]: '${device_name} Uptime': Sending state 709.63800 s with 0 decimals of accuracy
[12:48:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:48:58][V][json:051]: Size after shrink 80 bytes
[12:49:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -67.000000
[12:49:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -67.00000 dBm with 0 decimals of accuracy
[12:49:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:49:01][V][json:051]: Size after shrink 88 bytes
[12:49:03][D][switch:017]: 'silvia power' Turning OFF.
[12:49:03][D][switch:037]: 'silvia power': Sending state OFF
[12:49:03][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[12:49:03][V][json:051]: Size after shrink 68 bytes

And here is the logs of the moment, the shelly is disconnecting and then connecting again.

INFO Reading configuration /config/esphome/silvia.yaml...
INFO Starting log output from 192.168.0.104 using esphome API
INFO Successfully connected to 192.168.0.104
[13:21:22][I][app:102]: ESPHome version 2022.11.3 compiled on Jan 25 2023, 12:35:16
[13:21:22][C][wifi:504]: WiFi:
[13:21:22][C][wifi:362]:   Local MAC: E8:DB:84:D7:62:70
[13:21:22][C][wifi:363]:   SSID: 'athomebaby_EXT'[redacted]
[13:21:22][C][wifi:364]:   IP Address: 192.168.0.104
[13:21:22][C][wifi:365]:   BSSID: C0:C9:E3:DF:EB:70[redacted]
[13:21:22][C][wifi:367]:   Hostname: 'silvia'
[13:21:22][C][wifi:369]:   Signal strength: -67 dB ▂▄▆█
[13:21:22][C][wifi:373]:   Channel: 2
[13:21:22][C][wifi:374]:   Subnet: 255.255.255.0
[13:21:22][C][wifi:375]:   Gateway: 192.168.0.1
[13:21:22][C][wifi:376]:   DNS1: 0.0.0.0
[13:21:22][C][wifi:377]:   DNS2: 0.0.0.0
[13:21:22][C][logger:293]: Logger:
[13:21:22][C][logger:294]:   Level: VERBOSE
[13:21:22][C][logger:295]:   Log Baud Rate: 115200
[13:21:22][C][logger:296]:   Hardware UART: UART0
[13:21:22][C][switch.gpio:050]: GPIO Switch 'silvia power'
[13:21:22][C][switch.gpio:051]:   Pin: GPIO4
[13:21:22][C][switch.gpio:073]:   Restore Mode: Restore (Defaults to OFF)
[13:21:22][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'silvia switch'
[13:21:22][C][gpio.binary_sensor:016]:   Pin: GPIO5
[13:21:22][C][uptime.sensor:031]: Uptime Sensor '${device_name} Uptime'
[13:21:22][C][uptime.sensor:031]:   Device Class: 'duration'
[13:21:22][C][uptime.sensor:031]:   State Class: 'total_increasing'
[13:21:22][C][uptime.sensor:031]:   Unit of Measurement: 's'
[13:21:22][C][uptime.sensor:031]:   Accuracy Decimals: 0
[13:21:22][C][uptime.sensor:031]:   Icon: 'mdi:timer-outline'
[13:21:22][V][uptime.sensor:031]:   Unique ID: 'e8db84d76270-uptime'
[13:21:22][C][captive_portal:088]: Captive Portal:
[13:21:22][C][web_server:125]: Web Server:
[13:21:22][C][web_server:126]:   Address: 192.168.0.104:80
[13:21:22][C][mdns:103]: mDNS:
[13:21:22][C][mdns:104]:   Hostname: silvia
[13:21:22][V][mdns:105]:   Services:
[13:21:22][V][mdns:107]:   - _esphomelib, _tcp, 6053
[13:21:22][V][mdns:109]:     TXT: version = 2022.11.3
[13:21:22][V][mdns:109]:     TXT: mac = e8db84d76270
[13:21:22][V][mdns:109]:     TXT: platform = ESP8266
[13:21:22][V][mdns:109]:     TXT: board = esp01_1m
[13:21:22][V][mdns:109]:     TXT: network = wifi
[13:21:22][V][mdns:107]:   - _http, _tcp, 80
[13:21:22][C][ota:093]: Over-The-Air Updates:
[13:21:22][C][ota:094]:   Address: 192.168.0.104:8266
[13:21:22][C][ota:097]:   Using Password.
[13:21:22][C][api:138]: API Server:
[13:21:22][C][api:139]:   Address: 192.168.0.104:6053
[13:21:22][C][api:143]:   Using noise encryption: NO
[13:21:22][C][wifi_signal.sensor:009]: WiFi Signal '${device_name} WiFi Signal'
[13:21:22][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[13:21:22][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[13:21:22][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[13:21:22][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[13:21:22][V][wifi_signal.sensor:009]:   Unique ID: 'e8db84d76270-wifisignal'
[13:21:58][V][sensor:076]: '${device_name} Uptime': Received new state 2689.639893
[13:21:58][D][sensor:126]: '${device_name} Uptime': Sending state 2689.63989 s with 0 decimals of accuracy
[13:21:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[13:21:58][V][json:051]: Size after shrink 84 bytes
[13:22:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -67.000000
[13:22:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -67.00000 dBm with 0 decimals of accuracy
[13:22:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[13:22:01][V][json:051]: Size after shrink 88 bytes
[13:22:49][D][switch:013]: 'silvia power' Turning ON.
[13:22:49][D][switch:037]: 'silvia power': Sending state ON
[13:22:49][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[13:22:49][V][json:051]: Size after shrink 68 bytes
[13:22:58][D][api.connection:159]: Home Assistant 2022.3.5 (192.168.0.63) requested disconnected
[13:22:58][V][api:114]: Removing connection to Home Assistant 2022.3.5 (192.168.0.63)
[13:22:58][V][sensor:076]: '${device_name} Uptime': Received new state 2749.644043
[13:22:58][D][sensor:126]: '${device_name} Uptime': Sending state 2749.64404 s with 0 decimals of accuracy
[13:22:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[13:22:58][V][json:051]: Size after shrink 84 bytes
[13:23:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -67.000000
[13:23:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -67.00000 dBm with 0 decimals of accuracy
[13:23:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[13:23:01][V][json:051]: Size after shrink 88 bytes
[13:23:27][D][api:102]: Accepted 192.168.0.63
[13:23:27][V][api.connection:898]: Hello from client: 'Home Assistant 2022.3.5 (192.168.0.63)' | API Version 0.0
[13:23:27][D][api.connection:917]: Home Assistant 2022.3.5 (192.168.0.63): Connected successfully
[13:23:58][V][sensor:076]: '${device_name} Uptime': Received new state 2809.637939
[13:23:58][D][sensor:126]: '${device_name} Uptime': Sending state 2809.63794 s with 0 decimals of accuracy
[13:23:58][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[13:23:58][V][json:051]: Size after shrink 84 bytes
[13:24:01][V][sensor:076]: '${device_name} WiFi Signal': Received new state -68.000000
[13:24:01][D][sensor:126]: '${device_name} WiFi Signal': Sending state -68.00000 dBm with 0 decimals of accuracy
[13:24:01][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[13:24:01][V][json:051]: Size after shrink 88 bytes

On the basis of “[api.connection:159]: Home Assistant 2022.3.5 (192.168.0.63) requested disconnected”, that means it’s HA doing the disconnecting. Are there any logs from HA in relation to this?

There is also some interesting conversation here:

I’d suggest that you test this with the coffee machine very close to the WiFi and see if you still have issues, or try pinging the ESP for a period while the issue happens and see if you get latency jumps which might indicate WiFi issues.

HA has the following related logs:

Can't connect to ESPHome API for silvia @ 192.168.0.104: Error connecting to ('192.168.0.104', 6053): [Errno 113] Connect call failed ('192.168.0.104', 6053)

When I have time, I will try that even closer to the AP.

The strange thing is, that I had tasmota for three years now on the shelly, and I didn’t have these problems. They only started, when I switched to ESPhome. Perhaps the API is there quicker to realize dropouts?

Conversely, I had problems with the OEM firmware dropping out on switch operation on my two Shelly 1 devices, but they’ve been flawless since moving to ESPHome.

This won’t be the problem but you should either define device_name or replace both ${device_name}s with Silvia.

I have a similar config to you but I don’t have the fast_connect or power_save_mode lines.

fast_connect and power_safe_modes were tries to resolve my problem.

Is there a command to start a reconnect from HA-side?
When I open the ESPhome-Dashboard, it reconnects immediatly. Perhaps I could force that with an automation as soon as the device gets unavailable…

It’s working now, since I installed the AP directly behind the coffee machine.

But I still find it strange, that the ESP doesn’t reconnect always, even when Wifi is available.
Sometimes I found it not connecting, while the Log-Window was open in the browser and regularely posting the status-logs…