From 7b222f773f5fb31c19f057931dd61c99b8daa614 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 1 Apr 2026 12:32:11 -1000 Subject: [PATCH] Fix: skip update_connected_state_ only when already connected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After wifi_loop_() processes the STA_CONNECTED event, state_ is still CONNECTING (state machine hasn't run yet). update_connected_state_() runs but is_connected_() returns false. Then check_connecting_finished() transitions to STA_CONNECTED. Next iteration: no events, state is STA_CONNECTED, so we skipped update — connected_ stayed false forever. Fix: check connected_ instead of state_. Only skip when connected_ is already true (steady state). When connected_ is false, always re-evaluate so the flag gets set after the state machine transitions. --- esphome/components/wifi/wifi_component.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 8ae6a3f14c..7761041213 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -735,7 +735,9 @@ void WiFiComponent::loop() { // Connection state can only change when events are processed (ESP-IDF/LibreTiny) // or polled (ESP8266/Pico W). Skip the expensive wifi_sta_connect_status_() call // when no events arrived and we're already in steady state. - if (events_processed || this->state_ != WIFI_COMPONENT_STATE_STA_CONNECTED) { + // Must also run when connected_ is false — after state transitions to STA_CONNECTED, + // connected_ won't be set until update_connected_state_() runs. + if (events_processed || !this->connected_) { this->update_connected_state_(); }