diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 634691a6d81..35b521cc28d 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -1968,11 +1968,6 @@ void WiFiComponent::check_roaming_(uint32_t now) { if (!this->post_connect_roaming_) return; - // Guard: not for hidden networks (may not appear in scan) - const WiFiAP *selected = this->get_selected_sta_(); - if (selected == nullptr || selected->get_hidden()) - return; - // Guard: attempt limit if (this->roaming_attempts_ >= ROAMING_MAX_ATTEMPTS) return; @@ -1990,6 +1985,11 @@ void WiFiComponent::check_roaming_(uint32_t now) { if (current_rssi == WIFI_RSSI_DISCONNECTED) return; + // Guard: not for hidden networks (may not appear in scan) + const WiFiAP *selected = this->get_selected_sta_(); + if (selected == nullptr || selected->get_hidden()) + return; + this->roaming_last_check_ = now; ESP_LOGD(TAG, "Roaming: scanning for better AP (current RSSI %d dBm)", current_rssi); this->roaming_scan_active_ = true;