So I wanted to move a bunch of esphome devices (a mix of esp8266 and esp32 boards) from one network to another, changing wifi ap/SSID and all network settings. And I wanted to do this over the air!

As there were quite a few nodes and these were used in various IoT settings, not all of them were convenient to just fetch and plug into a computer which would otherwise have been a straightforward solution.

Luckily esphome has a couple of tricks up its sleeve that made this practically painless once I figured it out.

By first adding both networks to the config I could upload the firmware with the new network (iot);

wifi:
 networks:
 - ssid: ahomenetwork
   password: 'originalsupersecretpassword'
   priority: 1
 - ssid: iot
   password: 'anothersupersecretpassword'
   manual_ip:
     static_ip: 192.168.9.19
     gateway: 192.168.9.254
     subnet: 255.255.255.0
   priority: 2
 use_address: someiotdevice.local

Here use_address is the devices name with .local appended. The devices current IP address could also be used if name resolution does not work for one reason or another..

Once this was uploaded I removed the parts relating to the old network and uploaded the firmware again with just a single wifi network;

wifi:
  ssid: iot
  password: 'samepasswordasabove'
  manual_ip:
   static_ip: 192.168.9.19  
   gateway: 192.168.9.254
   subnet: 255.255.255.0

When given a static IP address esphome will default to use that so no use_address needed, just like it was not before when it was on just the old network.

For more, see the esphome wifi component documentation

And that was it! Just these few steps to change wifi network in esphome. Migration complete.

These nodes talk with Home Assistant and in that end this was all transparent, no need to remove and re-add the devices or anything.

Previous Post Next Post