Using multiple WiFi networks in ESPHome

Read in: English · Polski

My current home network is still far away from what I would consider an ideal setup. Besides the main router, I also have a WiFi extender that creates a separate network. From time to time I change the router location, and many of my wirelessly connected devices require special attention often because I forget to update the credentials to the closest network before the move. Not this time.

ESPHome-powered devices used to be the most problematic case. To change WiFi configuration, you need to provide new credentials, recompile and flash the firmware. You can do this over-the-air, but you only have one chance. If you forget to update the configuration before moving your access point (or if you provide a wrong password), you end up searching for the device to flash it the old-school way – over the wire – like I did many times.

Recently, however, I was smart enough to check if ESPHome supports multiple WiFi networks in its configuration, and the answer is yes, it does. It works exactly as I expected.

You can give ESPHome a number of WiFi networks to connect to. ESPHome will then attempt to connect to the one with the highest signal strength.

In my case I ended up with the definition for my main network and the extended one

wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password
    - ssid: !secret wifi_ext_ssid
      password: !secret wifi_ext_password

Since then, I’ve had no issues after moving the network equipment.

I’m still looking for a similar solution for my Raspberry Pis. Currently, I manually change the network configuration before moving the access point – which works as long as I remember to do it in the right order.

Enjoyed this post?