Is there a simple way to detect the presence of a particular SSID?

In our house we have a couple of Wifi networks. One, in particular, is used to link devices far away (tens to hundreds of meters) from the house back to the house network. This (these) access points are managed by a cloud service (for Reasons) and when they power up, they don’t get configured properly if the Internet isn’t available to them (via the home network). This means that when we lose power and then get it back, the outdoor Wifi mesh usually fails to come back and I have to intervene manually.

We live in the woods, and wind, rain, drunk tourists, and other natural hazards take out the power or the Internet link (and usually both) with annoying frequency. I’d like to have an alert notification when the outdoor mesh network is not detected, and then when it comes back. This feels like something that I could achieve, if I had a device that I could plug into the home network, and then have the device use a wireless interface to scan for SSIDs. If we go a few minutes without seeing the outdoor mesh, then set an alert status. If the outdoor mesh shows up, clear the alert.

Anyway, does this seem right? If so, can anyone recommend a device that does this? If I’m going about it all wrong, I’d totally welcome any suggestions!

An ESP that has this SSID in it’s wifi credentials?
That means it can only connect when the wifi is up, and naturally not connect when it’s down.
ESP-Home has scan feature, but I believe it is only used when it’s not connected to a wifi and I don’t think you can get the information from it, it just outputs in the console

Ping sensor on the APs IP?

2 Likes

I know you selected @WallyR’s answer as solution but I just wanted to throw in a piece of code that I developed to solve a similar problem for the Chromecast issues I encountered.
I got it to work on an ESP32 with 2.4GHz networks but failed to implement it on an ESP32-C5 using it for 5GHz networks.

Either way, here’s the code if you’re interested - this special version provides a sensor in HA that lists all SSID staring with “T” (for Test):

esphome:
  name: ssid-scanner
  friendly_name: SSID-Scanner

esp32:
  board: esp32dev

logger:

api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxxxx"

ota:
  - platform: esphome
    password: "password"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  on_connect:
    then:
      - lambda: |-
          ESP_LOGD("scan", "Wi-Fi connected — configuring continuous scan");

          static wifi_scan_config_t scan_conf = {};
          scan_conf.scan_type   = WIFI_SCAN_TYPE_ACTIVE;
          scan_conf.show_hidden = false;

          static esp_event_handler_instance_t scan_done_hinst;
          esp_event_handler_instance_register(
            WIFI_EVENT,
            WIFI_EVENT_SCAN_DONE,
            [](void*, esp_event_base_t, int32_t, void*) {
              ESP_LOGD("scan", "WIFI_EVENT_SCAN_DONE — filtering SSIDs");

              uint16_t ap_count = 0;
              esp_wifi_scan_get_ap_num(&ap_count);
              if (ap_count == 0) {
                id(last_found_ssids).publish_state("None");
                ESP_LOGI("scan", "No APs found");
              } else {
                auto *aps = (wifi_ap_record_t*)malloc(sizeof(wifi_ap_record_t) * ap_count);
                esp_wifi_scan_get_ap_records(&ap_count, aps);

                std::string ssid_list;
                for (int i = 0; i < ap_count; i++) {
                  const char* ssid = reinterpret_cast<const char*>(aps[i].ssid);
                  if (ssid[0] == 'T') {  // Filter condition — adjust as needed
                    if (!ssid_list.empty()) ssid_list += ", ";
                    ssid_list += ssid;
                  }
                }

                if (ssid_list.empty()) {
                  id(last_found_ssids).publish_state("None");
                  ESP_LOGI("scan", "No matching SSIDs found");
                } else {
                  id(last_found_ssids).publish_state(ssid_list);
                  ESP_LOGI("scan", "Matched SSIDs: %s", ssid_list.c_str());
                }

                free(aps);
              }

              vTaskDelay(pdMS_TO_TICKS(5000));  // 5s pause between scans
              esp_wifi_scan_start(&scan_conf, false);
            },
            nullptr,
            &scan_done_hinst
          );

          esp_wifi_scan_start(&scan_conf, false);

  ap:
    ssid: "SSID-Checker Fallback Hotspot"
    password: "password"

captive_portal:

web_server:
  port: 80
  include_internal: true

text_sensor:
  - platform: template
    name: "Last Found SSIDs"
    id: last_found_ssids
1 Like