diff --git a/esphome/components/captive_portal/captive_portal.cpp b/esphome/components/captive_portal/captive_portal.cpp index b70fa4d0ca..459ac557c8 100644 --- a/esphome/components/captive_portal/captive_portal.cpp +++ b/esphome/components/captive_portal/captive_portal.cpp @@ -51,11 +51,7 @@ void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) { ESP_LOGI(TAG, " SSID='%s'", ssid.c_str()); ESP_LOGI(TAG, " Password=" LOG_SECRET("'%s'"), psk.c_str()); // Defer save to main loop thread to avoid NVS operations from HTTP thread - this->defer([ssid, psk]() { - wifi::global_wifi_component->save_wifi_sta(ssid, psk); - // Trigger connection attempt (exits cooldown if needed) - wifi::global_wifi_component->connect_soon(); - }); + this->defer([ssid, psk]() { wifi::global_wifi_component->save_wifi_sta(ssid, psk); }); request->redirect(ESPHOME_F("/?save")); } diff --git a/esphome/components/esp32_improv/esp32_improv_component.cpp b/esphome/components/esp32_improv/esp32_improv_component.cpp index c456ad7d33..398b1d4251 100644 --- a/esphome/components/esp32_improv/esp32_improv_component.cpp +++ b/esphome/components/esp32_improv/esp32_improv_component.cpp @@ -381,8 +381,6 @@ void ESP32ImprovComponent::check_wifi_connection_() { if (this->state_ == improv::STATE_PROVISIONING) { wifi::global_wifi_component->save_wifi_sta(this->connecting_sta_.get_ssid(), this->connecting_sta_.get_password()); - // Trigger connection attempt (exits cooldown if needed, no-op if already connected) - wifi::global_wifi_component->connect_soon(); this->connecting_sta_ = {}; this->cancel_timeout("wifi-connect-timeout"); diff --git a/esphome/components/improv_serial/improv_serial_component.cpp b/esphome/components/improv_serial/improv_serial_component.cpp index 51f8c8b839..70260eeab3 100644 --- a/esphome/components/improv_serial/improv_serial_component.cpp +++ b/esphome/components/improv_serial/improv_serial_component.cpp @@ -50,8 +50,6 @@ void ImprovSerialComponent::loop() { if (wifi::global_wifi_component->is_connected()) { wifi::global_wifi_component->save_wifi_sta(this->connecting_sta_.get_ssid(), this->connecting_sta_.get_password()); - // Trigger connection attempt (exits cooldown if needed, no-op if already connected) - wifi::global_wifi_component->connect_soon(); this->connecting_sta_ = {}; this->cancel_timeout("wifi-connect-timeout"); this->set_state_(improv::STATE_PROVISIONED); diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 401c60267e..5adc0c0489 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -674,6 +674,9 @@ void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &pa // Force scan on next attempt even if captive portal is still active // This ensures new credentials are tried with proper BSSID selection after provisioning this->force_scan_after_provision_ = true; + + // Trigger connection attempt (exits cooldown if needed, no-op if already connecting/connected) + this->connect_soon(); } void WiFiComponent::connect_soon() {