Set wifi phy mode to 802.11b/g

post removed by user, its no longer exist

Pretty sure you will have to do that in a lambda using wifi_set_phy_mode

see Change Wifi standard b/g/n to make the most output power - Everything ESP8266

Well automatic change of channel in Wifi AP is always a bad idea, it generates a lot more of problems than it solves :wink:

For future reference, this config seems to do it:

esphome:
  name: ${device_name}
  min_version: 2022.10.2
  on_boot:
    priority: 300
    then:
      lambda: |-
        esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G);
2 Likes

since original post is gone and Xmister’s code snippet is not enough for it to compile (not declared values) then i found help from esphome discord and here’s snippet that compiles without extra code

esphome:
  name: ${device_name}
  min_version: 2022.10.2
  on_boot:
    priority: 300
    then:
      lambda: |-
        WiFi.setPhyMode(WIFI_PHY_MODE_11G);
1 Like

I think it’s a difference between ESP chipsets. Mine works on ESP32, and yours is on ESP8266.
I should have stated that I was working on ESP32.

Can say it works on ESP32. It’s nice to have a better wifi connection without a extra AP and good enough for low data rate.

I am trying to use the code in this thread with both an ESP8266 and an ESP32 (to address connection issues with an Asus router). The ESP8266 version of the code seems to work perfectly for me, and the router logs shows that device connected in wifi G mode. However, the ESP32 code in this thread does not seem to work for me, as the router still shows that device connected in wifi N mode. I have tried both the current default arduino version, and version 2.0.7 which looks to have been the current version when the code in this thread worked for others. It compiles without errors, it just doesn’t seem to work. Does anyone have any suggestions?

I posted too soon - I fixed it myself! In case it helps someone else: I changed the on_boot priority of the ESP32 code to 200 (from 300 in the snippet above), which should execute the command after wifi is initialized, and it now works (the router indicates a connection in G mode).

edit: Switching to arduino framework from esp-idf allowed it to compile. Hopefully fix connection issue

esp32:
  board: esp32dev
  framework:
    type: arduino

Has anyone tried this on ESPHome 2025.11.x for an ESP32? I have one 32 device with a bad connection. Using the WiFi.setPhyMode makes my esp8266’s more stable, so hoping could do the same on a 32.

Neither WiFi.setPhyMode(WIFI_PHY_MODE_11G) or esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G);

error: 'WIFI_PHY_MODE_11G' was not declared in this scope
    8 |         WiFi.setPhyMode(WIFI_PHY_MODE_11G);
error: 'esp_wifi_set_protocol' was not declared in this scope
    8 |         esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G);

edit:
You need to include the wifi header file in latest version of esphome if use esp-idf

esphome:
  name: watermeter32
  includes:
    - <esp_wifi.h>
  min_version: 2022.10.2
  on_boot:
    priority: 300
    then:
      lambda: |-
        esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G);

esp32:
  board: esp32dev
  framework:
    type: esp-idf