Deep sleep wont connect to wifi - Association refused temporarily, comeback time 0 mSec

I have almost got my deep sleep setup working, however when waking, it wont connect to wifi.

It also seems to spew a mass deauth broadcase when trying to connect as everything else on the same AP is disconnected.

The error is

[D][esp-idf:000]: E (5536) wifi:
[D][esp-idf:000]: Association refused temporarily, comeback time 0 mSec
[D][esp-idf:000]: 

[D][esp-idf:000]: E (5555) wifi:
[D][esp-idf:000]: Association refused temporarily, comeback time 0 mSec
[D][esp-idf:000]: 

[D][esp-idf:000]: E (5572) wifi:
[D][esp-idf:000]: Association refused temporarily, comeback time 0 mSec
[D][esp-idf:000]: 

[D][esp-idf:000]: E (5589) wifi:
[D][esp-idf:000]: Association refused temporarily, comeback time 0 mSec
[D][esp-idf:000]: 

[W][wifi_esp32:482]: Event: Disconnected ssid='wifi' bssid=[redacted] reason='Association Failed'
[W][wifi:630]: Error while connecting to network.
[D][wifi:673]: Retrying with hidden networks...
[I][wifi:303]: WiFi Connecting to 'wifi'...
[W][wifi_esp32:479]: Event: Disconnected ssid='IoT' reason='Probe Request Unsuccessful'
[W][wifi:640]: WiFi network can not be found anymore.
[D][wifi:673]: Retrying with hidden networks...
[D][binary_sensor:036]: 'power_button': Sending state OFF
[I][deep_sleep:117]: Beginning Deep Sleep
[D][esp32.preferences:114]: Saving 1 preferences to flash...
[D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

Any ideas on this one? I’m using fast connect with a specific BSSID set.

wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
    bssid: xx:xx:xx:xx:xx:xx
  fast_connect: true

My deepsleep YAML is

  on_boot:
    priority: 200
    then:
      - deep_sleep.enter:
          id: deep_sleep_1

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO32
      mode:
        input: True
        pullup: True
      inverted: False
      allow_other_uses: True 
    name: power_button
    filters:
      - delayed_on: 25ms
      - delayed_off: 500ms
    on_release:
      then:
      # switch relais? 
      # led blink with repeat action etc?
      # delay to complete
      - deep_sleep.enter: deep_sleep_1    

deep_sleep:
  id: deep_sleep_1
  #run_duration: 2min
  #sleep_duration: 1min
  wakeup_pin:
    number: GPIO32
    allow_other_uses: True

Thanks

Post the complete yaml file.

Sure, Complete YAML below. Thanks

esphome:
  name: test
  friendly_name: test

  on_boot:
    priority: 200
    then:
      - deep_sleep.enter:
          id: deep_sleep_1

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

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

ota:
  password: ""

wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
    bssid: 
  fast_connect: true

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test Fallback Hotspot"
    password: ""

captive_portal:
  
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO32
      mode:
        input: True
        pullup: True
      inverted: False
      allow_other_uses: True 
    name: power_button
    filters:
      - delayed_on: 25ms
      - delayed_off: 500ms
    on_release:
      then:
      # switch relais? 
      # led blink with repeat action etc?
      # delay to complete
      - deep_sleep.enter: deep_sleep_1    

deep_sleep:
  id: deep_sleep_1
  #run_duration: 2min
  #sleep_duration: 1min
  wakeup_pin:
    number: GPIO32
    allow_other_uses: True

do (forever){
put the ESP to sleep.
wait for wake pin
}

priority: 200 is probably working, but as soon as the WiFi connects, you put the ESP to sleep again.

Sorry can you elaborate on this a little bit more. I dont understand.

I understand that the ESP is possibly trying to sleep immediately after connecting to wifi,

Should I change the priority?

Thanks for the help

That won’t matter because you are still going from boot to sleep. Nothing else in your YAML will be used.

Here’s how I handle sleep. (Note, I don’t use the ESP32 much since I still have a dozen Wemos D1 Mini’s in my workshop. In fact this code is run on a bare ESP01).

Basically, the first thing the YAML code does is to check if a helper named otamode is on or off. If it’s on, then I skip sleep. If it’s off, I go back to sleep.

So from my desktop I have a switch to turn otamode on or off.

# This is the ESP device inside the Jeep to provide presence (status=connected).
substitutions:
  device_name: jeep
  friendly_name: jeep

packages:
  wifi: !include common/wifi.yaml
  device_base: !include common/esp8266.yaml

esphome:
  on_boot:
    priority: -100.0
    then:
      - delay: 1s
      - script.execute: test_ota



binary_sensor:
  - platform: status
    name: "Jeep Status"
  - platform: homeassistant
    id: otamode
    entity_id: input_boolean.jeep_ota_mode
    
#################################################    
# Script to test if the otamode switch is on or off
script:
  - id: test_ota
    mode: queued
    then:
      - logger.log: "Checking OTA Mode"
      - if:
          condition:
            binary_sensor.is_on: otamode
          then:
            - logger.log: 'OTA Mode ON'
            - deep_sleep.prevent: deep_sleep_handler
          else:
            - logger.log: 'OTA Mode OFF'
      - delay: 2s
      - script.execute: test_ota
    
#################################################
#Deep Sleep
deep_sleep:
  id: deep_sleep_handler
  run_duration: 5s
  sleep_duration: 120s