I got a good deal on a 4 pack of SwitchBot Plug Minis on Prime day so I thought I’d try to get them working in ESPHome. I’m fairly new to ESPHome so this might not be the best way to do this but I had some luck and didn’t see where anyone else had posted about it yet so am posting my config in case others are interested. My goal was to have a locally controller on/off outlet that supported energy monitoring and integrated well with HA and these appear to fit that goal well and a great price.
edit: added sdk config options needed to flash with larger firmware or use ble
edit2: added config to set blue led as status_led
edit3: added lines to enable new bluetooth proxying
edit4: added web server from PR3500 and note about NVS partition size
edit5: removed custom component as web_server is now included in ESPHome as of 2023.7.0
I had exactly the same thought (I’ve got like 20 xiaomi temp/hum sensors throughout the house). I did try to add the “esp32_ble_tracker” module into the config but it failed to compile. I haven’t had time to dive into why but suspect that module isn’t supported in esp-if framework yet. It’ll be a great option once it’s supported.
I played around some more and found some good info in an GitHub issue that let me get ble tracking working. You have to add a few sdk config options to the config to get it to compile and OTA update properly.
In short once you have the above config working you need to modify the esp32 section to look like this:
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"
Then you need to flash that before adding the esp32_ble_tracker to your config otherwise the image gets too big and timeout when trying to OTA update. After that’s pushed you can add the esp32_ble_tracker to your config.
I can now get rid of the various ble listeners I have around the house and replace them with these much nicer looking plugs.
In the ESPHome interface when you click Install then “Manual Download” it offers you options for either the “Modern format” or “Legacy format”, I selected Legacy.
I tried loading it up and can see it detecting BLE packets so think it should be good. At some point I’ll likely replace my existing BLE gateway devices with these but they’re already working well so not a priority.
Hey @taylormia & @apnar I’ve done the initial flash from official to tasmota and want to move it to esphome.
I’m worried that if I flash something incorrect that I won’t be able to recover it without opening up the physical smart plug – so I’m trying to think of all situations on how I can maintain access through esphome.
I noticed that the captive portal throws an error on the YAML. Does the AP under the wifi section still work even if captive portal is not in the config?
I also came across BLE Improv Component – can I add this on the first flash to use this to recover in the event of incorrect wifi credentials or are the BLE features not enabled until I add this on the second flash:
sdkconfig_options:
CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y
CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10"
@LUNZ I haven’t used either of the components you reference so I can’t confirm they’d work. I will say that I did try doing the initial Tasmota to ESPHome conversion flash with the config options and ble config in place and that was successful so a step wise approach isn’t necessarily required.
Does the official Bluetooth Proxy feature work with these BLE sdkconfig options? Has anyone tried the new active BLE proxy option?
I see that esp32_ble_trackerdoes seem to work on the plugs, and that bodes well because the Bluetooth Proxy component documentation says that it depends on this.
But then the Bluetooth Proxy feature page says that “This option only works for “plain” ESP32 and not for ESP32-C3 or other variants”…
I haven’t tried any active connections yet but I do seem to be getting some BLE packets hitting my BLE monitor and into iBeacon. I’ll update the top post.
When I included the scan_parameters: elements my plug stopped connecting over WiFi. This meant I had to disassemble the plug and re-flash over serial.
After reverting to an empty esp32_ble_tracker: entry and flashing using https://web.esphome.io, I ran into a boot loop which was solved with:
esphome:
# only needed for initial UART flash
# can be removed for subsequent uploads
platformio_options:
board_build.flash_mode: dio
Hopefully this was a one-time glitch, but in case it wasn’t I’ll be sticking to the default values for esp32_ble_tracker or possibly even removing it entirely.
Just guessing here, but it looks like you’re trying to run ESPHome on a box with an arm processor and one of the needed components in the toolchain isn’t available for arm. I’ve only run ESPHome on x86 (amd64) machines so don’t know how well it is supposed to work on arm.