Wifi multiple networks specific SSID

Hi All,

I’m using ESPHome for years and loving it. Have for about 15 devices in my home. Latest development is using them outside. Most of the time ESP32 with several sensors connected. My latest is a motion detection (HC-RS501) for garden lights. In my experiance with that sensor low power Wifi is neccesary and using my non 5ghz Wifi setup. I’m using a setup with two possible SSID’s. But i have 4 different SSID’s in my environment.

To use multi wifi networks i’m using this setup:

    - ssid: !secret 2_wifi_ssid
    - password: !secret 2_wifi_password
    - ssid: !secret 3_wifi_ssid
    - password: !secret 3_wifi_password
  output_power: 8.5dB
  power_save_mode: HIGH

In my secrets.yaml:

# Your Wi-Fi SSID and password
1_wifi_ssid: "wwwmdfotonlmesh"
1_wifi_password: "xxxxxx"

2_wifi_ssid: "wwwmdfotonl"
2_wifi_password: "xxxxxx"

3_wifi_ssid: "wwwmdfotonliot"
3_wifi_password: "xxxxxx"

So i’m trying to connect to a specific wifi network 2_wifi / 3_wifi using secrets.
The device is connecting to all possible wifi ap’s listed in the secret.yaml file as shown here:

[07:23:39][C][wifi:504]: WiFi:
[07:23:39][C][wifi:362]:   Local MAC: xx:B8:15:C1:xx:xx
[07:23:39][C][wifi:363]:   SSID: **[wwwmdfotonlmesh]**
[07:23:39][C][wifi:364]:   IP Address:
[07:23:39][C][wifi:366]:   BSSID: [redacted]
[07:23:39][C][wifi:367]:   Hostname: 'bewbuiten1'

Didn’t i understand the way this should be working? Or did i make a config fault?


doesn’t fit with the docs:

# Example configuration entry
  - ssid: FirstNetworkToConnectTo
    password: VerySafePassword
  - ssid: SecondNetworkToConnectTo
    password: VerySafePassword
  # Other options
  # ...

Thanks for your reply.
So bassicly what you (or the documentation) descripes that we Can’t use SECRET in multiple networks?

It says dat you shouldn’t use the dash - in front of the password. Only in front of the ssid

Yes you can. Here’s mine:

# Multiple networks with DHCP
  - ssid: Kaywinnet
    password: !secret wifi_password
  - ssid: Serenity
    password: !secret serenity_password
  - ssid: Naboo
    password: !secret naboo_password

But your secrets.yaml has a problem. (Note, I am YAML-challenged and not an expert).
The secrets file is a list of substitutions using the format:
key: "data"
and you are using the same keywords more than once. I don’t think it will throw an error, but only the first key will be used.


No he’s not. How is 1_wifi_password: the same as 2_wifi_password:

You are correct. I had brain fog and missed the 1_, 2_, etc. I would recommend that the OP use more descriptive keywords, however.

No. :no_entry:

That instead :point_up_2:

thanks all!

Got it working.

Nice. Feel free to mark your topic as :white_check_mark: solved

sorry for asking, but it’s not 100% clear for me:
Is the statement “…that we Can’t use SECRET in multiple networks?..” correct or is it possible to use also secret.yaml with multiple wifi-networks, so more than one SSID + PW in secrets.yaml?

You can use secrets in any value you like. Also with multiple ssid’s.

1 Like

thank you for your quick response - unfortunatelly I’m not a native speaker … what does this mean:

That instead :point_up_2:

Dash is the minus sign. -

It actually just means you need to use the correct syntax in the yaml.
But this is all in the documentation.

1 Like

ahhh, the minus before in front of each line - now it’s clear, thanks a lot!