Support for SwitchBot Plug Mini (W1901400) with bluetooth proxying

@lensherm is the Bluetooth proxying working for you with that yaml config? Did you have to make any changes?

Hoping to avoid opening up a plug like @rootnegativ1 had to do with the config causing the bootloop.

Last week I used the updated config from the first post, and it’s working for me. Haven’t tried the modified one yet.

1 Like

I noticed that the blue light on the Switchbot Plug Mini that I had flashed with Esphome as above, and recently they all started flashing and could not figure out why. The plugs were still working, but it was odd (because it did not flash previously - presumably the change was related to updating HA or Esphome-addon). I noticed there was an update available for the device in Esphome (2023.7.1 to 2023.12.3) and decided to try the update.

The update appeared to compile and upload fine, but I can no longer connect to the plug. I see wifi handshakes with my router, but it never connects to the network. I got the plug into wifi fallback mode (by turning off my wifi AP) and see the fallback network, but I am unable to connect to the network with my laptop.
Bummer!
Any other ideas of what might have happened or how to fix??
Thanks!

Start by looking at how quickly the blue LED is blinking. I’ve also recently noticed blue blinking whenever a device successfully connects to my wifi but hasn’t been added in HA.

Also consider not modifying the scan_parameters values in esp32_ble_tracker. Changing these values can lead to wireless problems and should only be done so when combined with ethernet . For what it’s worth, other posters in this thread seem to be fine with these non-default values. All I know for sure is when I included them, I had the same wireless issues as you.

Ultimately, it sounds like you may have to disassemble the plug(s) and reflash them over serial. It’s not that bad, just take your time. Use something like a metal spudger or thin flat screwdriver to SLOWLY work around the back of the plug. Eventually, you’ll find a gap where you can start prying off the back. The more time you take basically carving a groove in the back, the easier it’ll pop off.

Flashing the board is easy so long as you have a usb serial converter:

  • Connect (1) VCC to 3.3v, (2) GND to ground, (3) TX to RX, (4) RX to TX, and (5) P9 to ground. GPIO9 on the ESP32-C3 is like GPIO0 on previous espressif boards. Pulling P9 to ground will put the chip into flashing mode.
  • Modify your yaml file to include:
    esphome:
      # other stuff
      platformio_options:
        # esp32-c3-devkitm-1 board config tries qio when UART flashing
        # which goes into a boot loop
        # https://github.com/platformio/platform-espressif32/blob/ee1dd5a6c65a250dc5e3031c62e8c688f2665ce6/boards/esp32-c3-devkitm-1.json
        board_build.flash_mode: dio
    
  • Manually download your firmware in the modern version and use web.esphome.io to do the flashing
  • Disconnect the converter and squeeze the plug together

Thanks all for the suggestions.

After re-reading the ESPHome documentation, I noticed several mentions of how web_server: and esp32_ble_tracker: can result in memory overload on some devices and cause flaky behavior.

After leaving the devices powered on with the flashing blue (~1 hour), they eventually are able to connect to the wifi at which point I reflashed them through ESPHome addon with web_server: and esp32_ble_tracker: commented out. Now back to working as expected and immediately connect to the wifi.
Thankfully I did not have to open them up to serial flash.

So now my reliably working config is down to:

#from https://community.home-assistant.io/t/support-for-switchbot-plug-mini-w1901400-with-bluetooth-proxying/441893
substitutions:
  name: "switchbot2"
  friendly_name: "SwitchBot2 upstairs"

esphome:
  name: ${name}

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y
      CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
      CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10"

#disable web server due to memory concerns as per https://esphome.io/components/bluetooth_proxy
#web_server:
#esp32_ble_tracker:

# Enable logging
logger:

# all the usual wifi configs
<<: !include common/wifi.yaml

# Enable Home Assistant API
api:
  password: !secret api_password

ota:
  password: !secret ota_pass

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

bluetooth_proxy:
  active: true

switch:
  - platform: gpio
    name: "${name} Relay"
    id: "${name}_relay"
    device_class: outlet
    pin: 6
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
      then:
        - light.turn_on: "${name}_white_led"
    on_turn_off:
      then:
        - light.turn_off: "${name}_white_led"

binary_sensor:
  - platform: gpio
    internal: true
    pin:
      number: 2
      mode: INPUT_PULLUP
      inverted: true
    name: "${name} Button"
    filters:
      - delayed_on: 10ms
    on_press:
      then:
        - switch.toggle: "${name}_relay"
      
light:
  - platform: binary
    internal: true
    name: "${name} white led"
    id: "${name}_white_led"
    output: "${name}_white_output"
    
output:
  - id: "${name}_white_output"
    platform: gpio
    pin: GPIO7
    inverted: true

# set blue led as status
status_led:
  pin:
    number: GPIO8
    inverted: true

sensor:
  - platform: hlw8012
    sel_pin:
      number: 20
      inverted: true
    cf_pin: 18
    cf1_pin: 19
    model: BL0937
    voltage_divider: 1467
    current:
      name: "${name} Current"
    voltage:
      name: "${name} Voltage"
    power:
      name: "${name} Power"
    energy:
      name: "${name} Energy"
    update_interval: 1s
    change_mode_every: 4

##############

wifi:
  ssid: SSID
  password: PASS

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Switchbot Fallback Hotspot"
    password: PASS

captive_portal:

It appears there is a workaround for the newly introduced wifi flakiness. See Devices with esp32-c3-devkitm-1 Inaccessible after updating 2023.12.* · Issue #5276 · esphome/issues · GitHub

I noticed that after implementing the workaround, the plugs connect to wifi as before updating esphome to 2023.12.*. Note, you may need to delete the device from the integrations page, restart HA and readd the device if it continues to blink blue.

1 Like

You don’t need to open them. You can reboot them until they go to safe mode, at which point you can OTA update them.

1 Like

Do you know if there is a way to flash the ESPresense firmware into these switches?

Yes, I have it working witout any issues, just pick the right fw.

@sseib Can you please clarify how to do that?

Let it run for about 30 seconds, then power cycle it. Do this until it connects to the wifi. Then you have a few minutes to OTA update it.

1 Like

I am just getting started with esphome and have successfully flashed multiple plugs with switchbota. I am hoping to put esphome on these devices using your yaml but I’m unsure what you did for step 4 (“created and downloaded an esphome firmware”).

Did you do this with the command line install or is there a way to do this with your HA instance to use your secrets file?

Sounds like you’re new to ESPHome. If you’re running HA via HASS OS you can install ESPHome as an add-on and create the configuration there. If you’re running HA another way you can run ESPHome separately (I run mine as a separate Docker container). Either way you can create the config and download it through the ESPHome web interface. I suspect once you get ESPHome running it’ll be more clear.

Thank you. I had esphome installed and totally missed the green button in the bottom right corner (+New Device) :man_facepalming: