diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index a7a3fb8949..76797f4a7d 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -683,15 +683,15 @@ void WiFiComponent::check_scanning_finished() { log_scan_result(res); } - if (!this->scan_result_[0].get_matches()) { + // Find matching config for on-demand connection params building + const WiFiScanResult &scan_res = this->scan_result_[0]; + + if (!scan_res.get_matches()) { ESP_LOGW(TAG, "No matching network found"); this->retry_connect(); return; } - // Find matching config for on-demand connection params building - const WiFiScanResult &scan_res = this->scan_result_[0]; - for (size_t i = 0; i < this->sta_.size(); i++) { // search for matching STA config, at least one will match (from checks before) if (!scan_res.matches(this->sta_[i])) {