ESP constantly flipping between connect and disconnect status


after latest Home Assistant update 2022.5.4, my esp32dev is constantly flipping between connect and disconnect status

[08:58:18][C][wifi:360]:   Signal strength: -34 dB ▂▄▆█
[08:58:18][C][wifi:364]:   Channel: 11

[08:56:42][D][api.connection:159]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A) requested disconnected
[08:56:42][D][api:102]: Accepted ::FFFF:C0A8:10A
[08:56:42][D][api.connection:827]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A): Connected successfully
[08:56:49][D][api.connection:159]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A) requested disconnected
[08:56:49][D][api:102]: Accepted ::FFFF:C0A8:10A
[08:56:50][D][api.connection:827]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A): Connected successfully
[08:56:56][D][api.connection:159]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A) requested disconnected
[08:56:56][D][api:102]: Accepted ::FFFF:C0A8:10A
[08:56:56][D][api.connection:827]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A): Connected successfully
[08:57:02][D][api.connection:159]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A) requested disconnected
[08:57:03][D][api:102]: Accepted ::FFFF:C0A8:10A
[08:57:03][D][api.connection:827]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A): Connected successfully
[08:57:08][D][api.connection:159]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A) requested disconnected
[08:57:08][D][api:102]: Accepted ::FFFF:C0A8:10A
[08:57:08][D][api.connection:827]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A): Connected successfully
[08:57:14][D][api.connection:159]: Home Assistant 2022.5.4 (::FFFF:C0A8:10A) requested disconnected

anyone has any ideas?


Put some distances between your Wifi AP and the ESP ! Looks to receive way too much of Wifi signal !
Have you checked also your ESP is well powered ?

Thank you,
I will do some tests, what sounds strange is that it worked without issues for months
and I just surfaced the issue after the last update

I should have another spare esp32, I will try to replace it as well

@vincen , thank you for your suggestions


Post your yaml file for the device, please.

Just a few things I’ve seen with esp32s. Hope it helps you and others.

Could be lack of current on the power supply. esp32 can use a lot more then say a computers usb supply for example.
Could be too large of code. Anything over 48ish % the compiler doesn’t know that’s too large and will cycle.
Could be a error in your code. The compiler sometimes does not recognize bad code. In your case maybe a breaking change.
Could be an old router or out of date firmware on your router. New ubiquiti ap’s fixed my esp32’s from tons of disconnects.

Could just need to power cycle your router or ap.

@stevemann Here my code:

  device_name: bentel-control
  friendly_name: "Bentel Control"
  device_platform: ESP32
  device_board: esp32dev
  device_ip: x.x.x.x

  wifi: !include common/device_wifi_1.yaml
  device_base: !include common/device_base_ESP32.yaml
  home_assistant_api: !include common/device_api.yaml
  sensor_wifi_ip_address: !include common/sensor_wifi_ip_address.yaml  

    - ./src/bentel_kyo32.h
# Enable logging
  level: DEBUG
  baud_rate: 0

  id: uart_bus
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 9600
  data_bits: 8
  parity: EVEN

  - platform: safe_mode
    name: "ESPKyoGate (Safe Mode)"  

  - platform: custom
    lambda: |-
      auto kyo32 = new Bentel_Kyo32(id(uart_bus));
      return {





      - id: kyo_comunication
        name: "Bentel Comunication"
      - id: status_siren
        name: "Bentel status siren"
      - id: warn_missing_network
        name: "Bentel missing network"
      - id: warn_lost_bpi
        name: "Bentel lost BPI"
      - id: warn_fuse
        name: "Bentel fuse"
      - id: warn_battery_low
        name: "Bentel battery low"
      - id: warn_fault_line_phone
        name: "Bentel fault line phone"
      - id: warn_code_default
        name: "Bentel code Default"
      - id: warn_wireless
        name: "Bentel Wireless"
      - id: sabotage_zone
        name: "Bentel sabotage zone"
      - id: sabotage_system
        name: "Bentel sabotage system"
      - id: sabotage_bpi
        name: "Bentel sabotage BPI"
      - id: sabotage_key_false
        name: "Bentel sabotage key false"
      - id: sabotage_jam
        name: "Bentel sabotage Jam"
      - id: sabotage_wireless
        name: "Bentel sabotage wireless"  

      - id: zone_1
        name: "Bentel zone 1"
      - id: zone_2
        name: "Bentel zone 2"
      - id: zone_3
        name: "Bentel zone 3"
      - id: zone_4
        name: "Bentel zone 4"
      - id: zone_5
        name: "Bentel zone 5"
      - id: zone_6
        name: "Bentel zone 6"
      - id: zone_7
        name: "Bentel zone 7"
      - id: zone_8
        name: "Bentel zone 8"
      - id: zone_9
        name: "Bentel zone 9"
      - id: zone_10
        name: "Bentel zone 10"
      - id: zone_11
        name: "Bentel zone 11"
      - id: zone_12
        name: "Bentel zone 12"
      - id: zone_13
        name: "Bentel zone 13"
      - id: zone_14
        name: "Bentel zone 14"
      - id: zone_15
        name: "Bentel zone 15"
      - id: zone_16
        name: "Bentel zone 16"
      - id: zone_17
        name: "Bentel zone 17"
      - id: zone_18
        name: "Bentel zone 18"
      - id: zone_19
        name: "Bentel zone 19"
#      - id: zone_20
#        name: "Bentel zone 20"
#      - id: zone_21
#        name: "Bentel zone 21"
#      - id: zone_22
#        name: "Bentel zone 22"
#      - id: zone_23
#        name: "Bentel zone 23"
#      - id: zone_24
#        name: "Bentel zone 24"
#      - id: zone_25
#        name: "Bentel zone 25"
#      - id: zone_26
#        name: "Bentel zone 26"
#      - id: zone_27
#        name: "Bentel zone 27"
#      - id: zone_28
#        name: "Bentel zone 28"
#      - id: zone_29
#        name: "Bentel zone 29"
#      - id: zone_30
#        name: "Bentel zone 30"
#      - id: zone_31
#        name: "Bentel zone 31"
#      - id: zone_32
#        name: "Bentel zone 32"

      - id: zone_sabotage_1
        name: "Bentel sabotage zone 1"
      - id: zone_sabotage_2
        name: "Bentel sabotage zone 2"
      - id: zone_sabotage_3
        name: "Bentel sabotage zone 3"
      - id: zone_sabotage_4
        name: "Bentel sabotage zone 4"
      - id: zone_sabotage_5
        name: "Bentel sabotage zone 5"
      - id: zone_sabotage_6
        name: "Bentel sabotage zone 6"
      - id: zone_sabotage_7
        name: "Bentel sabotage zone 7"
      - id: zone_sabotage_8
        name: "Bentel sabotage zone 8"
      - id: zone_sabotage_9
        name: "Bentel sabotage zone 9"
      - id: zone_sabotage_10
        name: "Bentel sabotage zone 10"
      - id: zone_sabotage_11
        name: "Bentel sabotage zone 11"
      - id: zone_sabotage_12
        name: "Bentel sabotage zone 12"
      - id: zone_sabotage_13
        name: "Bentel sabotage zone 13"
      - id: zone_sabotage_14
        name: "Bentel sabotage zone 14"
      - id: zone_sabotage_15
        name: "Bentel sabotage zone 15"
      - id: zone_sabotage_16
        name: "Bentel sabotage zone 16"
      - id: zone_sabotage_17
        name: "Bentel sabotage zone 17"
      - id: zone_sabotage_18
        name: "Bentel sabotage zone 18"
      - id: zone_sabotage_19
        name: "Bentel sabotage zone 19"
#      - id: zone_sabotage_20
#        name: "Bentel sabotage zone 20"
#      - id: zone_sabotage_21
#        name: "Bentel sabotage zone 21"
#      - id: zone_sabotage_22
#        name: "Bentel sabotage zone 22"
#      - id: zone_sabotage_23
#        name: "Bentel sabotage zone 23"
#      - id: zone_sabotage_24
#        name: "Bentel sabotage zone 24"
#      - id: zone_sabotage_25
#        name: "Bentel sabotage zone 25"
#      - id: zone_sabotage_26
#        name: "Bentel sabotage zone 26"
#      - id: zone_sabotage_27
#        name: "Bentel sabotage zone 27"
#      - id: zone_sabotage_28
#        name: "Bentel sabotage zone 28"
#      - id: zone_sabotage_29
#        name: "Bentel sabotage zone 29"
#      - id: zone_sabotage_30
#        name: "Bentel sabotage zone 30"
#      - id: zone_sabotage_31
#        name: "Bentel sabotage zone 31"
#      - id: zone_sabotage_32
#        name: "Bentel sabotage zone 32"

      - id: zone_exclude_1
        name: "Bentel exclude zone 1"
      - id: zone_exclude_2
        name: "Bentel exclude zone 2"
      - id: zone_exclude_3
        name: "Bentel exclude zone 3"        
      - id: zone_exclude_4
        name: "Bentel exclude zone 4"
      - id: zone_exclude_5
        name: "Bentel exclude zone 5"
      - id: zone_exclude_6
        name: "Bentel exclude zone 6"
      - id: zone_exclude_7
        name: "Bentel exclude zone 7"
      - id: zone_exclude_8
        name: "Bentel exclude zone 8"        
      - id: zone_exclude_9
        name: "Bentel exclude zone 9"
      - id: zone_exclude_10
        name: "Bentel exclude zone 10"        
      - id: zone_exclude_11
        name: "Bentel exclude zone 11"
      - id: zone_exclude_12
        name: "Bentel exclude zone 12"
      - id: zone_exclude_13
        name: "Bentel exclude zone 13"        
      - id: zone_exclude_14
        name: "Bentel exclude zone 14"
      - id: zone_exclude_15
        name: "Bentel exclude zone 15"
      - id: zone_exclude_16
        name: "Bentel exclude zone 16"
      - id: zone_exclude_17
        name: "Bentel exclude zone 17"
      - id: zone_exclude_18
        name: "Bentel exclude zone 18"        
      - id: zone_exclude_19
        name: "Bentel exclude zone 19"
#      - id: zone_exclude_20
#        name: "Bentel exclude zone 20"
#      - id: zone_exclude_21
#        name: "Bentel exclude zone 21"                
#      - id: zone_exclude_22
#        name: "Bentel exclude zone 22"
#      - id: zone_exclude_23
#        name: "Bentel exclude zone 23"        
#      - id: zone_exclude_24
#        name: "Bentel exclude zone 24"
#      - id: zone_exclude_25
#        name: "Bentel exclude zone 25"                
#      - id: zone_exclude_26
#        name: "Bentel exclude zone 26"
#      - id: zone_exclude_27
#        name: "Bentel exclude zone 27"        
#      - id: zone_exclude_28
#        name: "Bentel exclude zone 28"
#      - id: zone_exclude_29
#        name: "Bentel exclude zone 29"        
#      - id: zone_exclude_30
#        name: "Bentel exclude zone 30"
#      - id: zone_exclude_31
#        name: "Bentel exclude zone 31"        
#      - id: zone_exclude_32
#        name: "Bentel exclude zone 32"
      - id: memory_alarm_zone_1
        name: "Bentel memory alarm zone 1"
      - id: memory_alarm_zone_2
        name: "Bentel memory alarm zone 2"        
      - id: memory_alarm_zone_3
        name: "Bentel memory alarm zone 3"
      - id: memory_alarm_zone_4
        name: "Bentel memory alarm zone 4"
      - id: memory_alarm_zone_5
        name: "Bentel memory alarm zone 5"
      - id: memory_alarm_zone_6
        name: "Bentel memory alarm zone 6"
      - id: memory_alarm_zone_7
        name: "Bentel memory alarm zone 7"        
      - id: memory_alarm_zone_8
        name: "Bentel memory alarm zone 8"
      - id: memory_alarm_zone_9
        name: "Bentel memory alarm zone 9"
      - id: memory_alarm_zone_10
        name: "Bentel memory alarm zone 10"
      - id: memory_alarm_zone_11
        name: "Bentel memory alarm zone 11"
      - id: memory_alarm_zone_12
        name: "Bentel memory alarm zone 12"        
      - id: memory_alarm_zone_13
        name: "Bentel memory alarm zone 13"
      - id: memory_alarm_zone_14
        name: "Bentel memory alarm zone 14"
      - id: memory_alarm_zone_15
        name: "Bentel memory alarm zone 15"
      - id: memory_alarm_zone_16
        name: "Bentel memory alarm zone 16"
      - id: memory_alarm_zone_17
        name: "Bentel memory alarm zone 17"        
      - id: memory_alarm_zone_18
        name: "Bentel memory alarm zone 18"
      - id: memory_alarm_zone_19
        name: "Bentel memory alarm zone 19"
#      - id: memory_alarm_zone_20
#        name: "Bentel memory alarm zone 20"
#      - id: memory_alarm_zone_21
#        name: "Bentel memory alarm zone 21"                
#      - id: memory_alarm_zone_22
#        name: "Bentel memory alarm zone 22"
#      - id: memory_alarm_zone_23
#        name: "Bentel memory alarm zone 23"
#      - id: memory_alarm_zone_24
#        name: "Bentel memory alarm zone 24"
#      - id: memory_alarm_zone_25
#        name: "Bentel memory alarm zone 25"
#      - id: memory_alarm_zone_26
#        name: "Bentel memory alarm zone 26"                
#      - id: memory_alarm_zone_27
#        name: "Bentel memory alarm zone 27"
#      - id: memory_alarm_zone_28
#        name: "Bentel memory alarm zone 28"
#      - id: memory_alarm_zone_29
#        name: "Bentel memory alarm zone 29"
#      - id: memory_alarm_zone_30
#        name: "Bentel memory alarm zone 30"
#      - id: memory_alarm_zone_31
#        name: "Bentel memory alarm zone 31"
#      - id: memory_alarm_zone_32
#        name: "Bentel memory alarm zone 32"  

      - id: memory_sabotage_zone_1
        name: "Bentel memory sabotage zone 1"
      - id: memory_sabotage_zone_2
        name: "Bentel memory sabotage zone 2"        
      - id: memory_sabotage_zone_3
        name: "Bentel memory sabotage zone 3"
      - id: memory_sabotage_zone_4
        name: "Bentel memory sabotage zone 4"
      - id: memory_sabotage_zone_5
        name: "Bentel memory sabotage zone 5"
      - id: memory_sabotage_zone_6
        name: "Bentel memory sabotage zone 6"
      - id: memory_sabotage_zone_7
        name: "Bentel memory sabotage zone 7"        
      - id: memory_sabotage_zone_8
        name: "Bentel memory sabotage zone 8"
      - id: memory_sabotage_zone_9
        name: "Bentel memory sabotage zone 9"
      - id: memory_sabotage_zone_10
        name: "Bentel memory sabotage zone 10"
      - id: memory_sabotage_zone_11
        name: "Bentel memory sabotage zone 11"
      - id: memory_sabotage_zone_12
        name: "Bentel memory sabotage zone 12"        
      - id: memory_sabotage_zone_13
        name: "Bentel memory sabotage zone 13"
      - id: memory_sabotage_zone_14
        name: "Bentel memory sabotage zone 14"
      - id: memory_sabotage_zone_15
        name: "Bentel memory sabotage zone 15"
      - id: memory_sabotage_zone_16
        name: "Bentel memory sabotage zone 16"
      - id: memory_sabotage_zone_17
        name: "Bentel memory sabotage zone 17"        
      - id: memory_sabotage_zone_18
        name: "Bentel memory sabotage zone 18"
      - id: memory_sabotage_zone_19
        name: "Bentel memory sabotage zone 19"
#      - id: memory_sabotage_zone_20
#        name: "Bentel memory sabotage zone 20"
#      - id: memory_sabotage_zone_21
#        name: "Bentel memory sabotage zone 21"                
#      - id: memory_sabotage_zone_22
#        name: "Bentel memory sabotage zone 22"
#      - id: memory_sabotage_zone_23
#        name: "Bentel memory sabotage zone 23"
#      - id: memory_sabotage_zone_24
#        name: "Bentel memory sabotage zone 24"
#      - id: memory_sabotage_zone_25
#        name: "Bentel memory sabotage zone 25"
#      - id: memory_sabotage_zone_26
#        name: "Bentel memory sabotage zone 26"                
#      - id: memory_sabotage_zone_27
#        name: "Bentel memory sabotage zone 27"
#      - id: memory_sabotage_zone_28
#        name: "Bentel memory sabotage zone 28"
#      - id: memory_sabotage_zone_29
#        name: "Bentel memory sabotage zone 29"
#      - id: memory_sabotage_zone_30
#        name: "Bentel memory sabotage zone 30"
#      - id: memory_sabotage_zone_31
#        name: "Bentel memory sabotage zone 31"
#      - id: memory_sabotage_zone_32
#        name: "Bentel memory sabotage zone 32"   

      - id: alarm_area_1
        name: "Bentel alarm area 1"
      - id: alarm_area_2
        name: "Bentel alarm area 2"
      - id: alarm_area_3
        name: "Bentel alarm area 3"
      - id: alarm_area_4
        name: "Bentel alarm area 4"
      - id: alarm_area_5
        name: "Bentel alarm area 5"
      - id: alarm_area_6
        name: "Bentel alarm area 6"
      - id: alarm_area_7
        name: "Bentel alarm area 7"
      - id: alarm_area_8
        name: "Bentel alarm area 8"

      - id: insert_full_area_1
        name: "Bentel insert full Area 1"
      - id: insert_full_area_2
        name: "Bentel insert full Area 2"
      - id: insert_full_area_3
        name: "Bentel insert full Area 3"
      - id: insert_full_area_4
        name: "Bentel insert full Area 4"
      - id: insert_full_area_5
        name: "Bentel insert full Area 5"
      - id: insert_full_area_6
        name: "Bentel insert full Area 6"
      - id: insert_full_area_7
        name: "Bentel insert full Area 7"
      - id: insert_full_area_8
        name: "Bentel insert full Area 8"

      - id: insert_partial_area_1
        name: "Bentel insert partial Area 1"
      - id: insert_partial_area_2
        name: "Bentel insert partial Area 2"
      - id: insert_partial_area_3
        name: "Bentel insert partial Area 3"
      - id: insert_partial_area_4
        name: "Bentel insert partial Area 4"        
      - id: insert_partial_area_5
        name: "Bentel insert partial Area 5"
      - id: insert_partial_area_6
        name: "Bentel insert partial Area 6"
      - id: insert_partial_area_7
        name: "Bentel insert partial Area 7"
      - id: insert_partial_area_8
        name: "Bentel insert partial Area 8"   

      - id: insert_partial_delay_0_area_1
        name: "Bentel insert partial delay 0  Area 1"
      - id: insert_partial_delay_0_area_2
        name: "Bentel insert partial delay 0  Area 2"
      - id: insert_partial_delay_0_area_3
        name: "Bentel insert partial delay 0  Area 3"
      - id: insert_partial_delay_0_area_4
        name: "Bentel insert partial delay 0  Area 4"
      - id: insert_partial_delay_0_area_5
        name: "Bentel insert partial delay 0  Area 5"
      - id: insert_partial_delay_0_area_6
        name: "Bentel insert partial delay 0  Area 6"
      - id: insert_partial_delay_0_area_7
        name: "Bentel insert partial delay 0  Area 7"
      - id: insert_partial_delay_0_area_8
        name: "Bentel insert partial delay 0  Area 8"

      - id: disarm_area_1
        name: "Bentel disarm Area 1"
      - id: disarm_area_2
        name: "Bentel disarm Area 2"
      - id: disarm_area_3
        name: "Bentel disarm Area 3"
      - id: disarm_area_4
        name: "Bentel disarm Area 4"
      - id: disarm_area_5
        name: "Bentel disarm Area 5"
      - id: disarm_area_6
        name: "Bentel disarm Area 6"
      - id: disarm_area_7
        name: "Bentel disarm Area 7"
      - id: disarm_area_8
        name: "Bentel disarm Area 8"   

      - id: status_exit_1
        name: "Bentel status exit 1"
      - id: status_exit_2
        name: "Bentel status exit 2"
      - id: status_exit_3
        name: "Bentel status exit 3"
      - id: status_exit_4
        name: "Bentel status exit 4"        
      - id: status_exit_5
        name: "Bentel status exit 5"
      - id: status_exit_6
        name: "Bentel status exit 6"
      - id: status_exit_7
        name: "Bentel status exit 7"
      - id: status_exit_8
        name: "Bentel status exit 8"


I’m using this guy to convert from 12v to 5v

what is strange is that it started this behavior few days ago

What are we looking at in the last image? Did you do the update to 222.5.4 on the morning of May 14.
Thanks for the code. It didn’t show anything suspicious but I learned something from reading it.
I don’t think changing the ESP will fix it, but if it’s easy to swap, try it. (I try to socket all of my projects).

Is the ESP connecting/reconnecting or is it rebooting? Can you monitor the debug output on a terminal?

What about the PSU/Converter? I’ve had one of those fail on me a few months ago.


The latest image is one of the sensors that the ESP is tracking, most of the time it was OFF (I have the stats since April) but after May 14 the sensor becomes “Unavailable” based on the continuous API connect/disconnect flip. all the sensors are showing the same behavior/time

Yes, I did the update to the 2022.5.4 on May 14

I think that the behavior is probably connecting/reconnecting

I also see an high TTL for the ping

here 3hrs statistics summary

I changed the code to load only the esp settings without the UART and all the sensors (just to exclude some unexpected load with the serial communication) but the results are the same

I’m now looking at the wifi or (as you suggested) at the PSU/Converter (but I need to buy another one as I don’t have a spare part to test it “quickly”)


if this can help

Just out of curiosity, can you restore a snapshot from prior to the update? If the problem goes away you could be looking at a real bug. (Do a current snapshot before the restore).

  1. Do you have other EPS32s working good on your network? Is this just the only one disconnecting?

If others are working good. Try disconnecting one of them and seeing how long they take to rejoin the network and check if they cycle connections a few time before a solid connection.

What ESP32 board are you using? I’ve had the worst luck with the ESP32cam. Constant reconnects until I changed my Router/AP.

  1. Start with basic code on that device. See if the problem is the code. If this solves the problem and then work up from there.
    Add your code back until you start seeing the disconnects.

I can’t switch back; this time I didn’t create the snapshot :frowning:

  1. this is the only ESP I have connected with the WIFI, I have shelly devices connected to same wifi but they work without any issue
    i’m using an ESP32-WROOM-32D, v4 i think

this is the log of the binary sensor that I’m using to check the status

  # Connection status
  - platform: status
    name: ${friendly_name} Status

as you can see, there was on the previous days a kind of series, it was unavailable for 6h, then available for 1h, and then back to unavailable for 6h and so on
but today the time is different. however, even when it shows unavailable, I’m able to ping it (really high ttl and 4-5% of packet lost)

i can also connect and see the logs using the esphome add-on

  1. i did, same result

What router brand and age are you using?

If you cleared the code just to the basics and still get disconnects, I bet your router don’t like your esp32.

Slim chance it’s a bad esp32, but it could be.

A new router from best buy or amazon are amazingly cheap to get the latest wifi protocols.