diff --git a/esphome/components/wifi/wifi_component_esp8266.cpp b/esphome/components/wifi/wifi_component_esp8266.cpp index 6fb5dd5769..4c204f7cf3 100644 --- a/esphome/components/wifi/wifi_component_esp8266.cpp +++ b/esphome/components/wifi/wifi_component_esp8266.cpp @@ -698,6 +698,10 @@ bool WiFiComponent::wifi_scan_start_(bool passive) { if (!this->wifi_mode_(true, {})) return false; + // Reset scan_done_ before starting new scan to prevent stale flag from previous scan + // (e.g., roaming scan completed just before unexpected disconnect) + this->scan_done_ = false; + struct scan_config config {}; memset(&config, 0, sizeof(config)); config.ssid = nullptr; diff --git a/esphome/components/wifi/wifi_component_libretiny.cpp b/esphome/components/wifi/wifi_component_libretiny.cpp index cc9f4ec193..20cd32fa8f 100644 --- a/esphome/components/wifi/wifi_component_libretiny.cpp +++ b/esphome/components/wifi/wifi_component_libretiny.cpp @@ -649,6 +649,10 @@ bool WiFiComponent::wifi_scan_start_(bool passive) { if (!this->wifi_mode_(true, {})) return false; + // Reset scan_done_ before starting new scan to prevent stale flag from previous scan + // (e.g., roaming scan completed just before unexpected disconnect) + this->scan_done_ = false; + // need to use WiFi because of WiFiScanClass allocations :( int16_t err = WiFi.scanNetworks(true, true, passive, 200); if (err != WIFI_SCAN_RUNNING) {