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.
Link to the product: SwitchBot Plug Mini
There’s already been some great work to support these in Tasmota, including an OTA flasher so I started there. These are the basic steps I followed:
- setup plugs in SwitchBot app like normal
- use switchbota to install Tasmota
- this is a bit involved in that it requires running a local server and spoofing DNS to point the local server but it’s well explained on the page
- I had to initiate the update directly via Bluetooth using nRF Connect on my iPhone which is explained here
- connect to Tasmota hotspot and configure it for the local network
- created and downloaded an ESPHome firmware with the config below and downloaded it in legacy format
- upload firmware through the Tasmota local webpage
So far it seems to be working great. Few caveats:
- web server is from a PR and hasn’t been pulled into mainline yet
- the value used for the voltage_divider I came to experimentally comparing to my old kill-a-watt
- size of NVS partition seems to be smaller than ideal
substitutions:
name: "switchbot"
friendly_name: "SwitchBot"
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"
external_components:
- source: github://pr#3500
components:
- web_server
- web_server_idf
- web_server_base
web_server:
port: 80
auth:
username: !secret web_user
password: !secret web_pass
# 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
# Enable Bluetooth Proxying
esp32_ble_tracker:
scan_parameters:
interval: 1100ms
window: 1100ms
active: true
bluetooth_proxy:
active: true
switch:
- platform: gpio
name: "Relay"
id: "relay"
device_class: outlet
pin: 6
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
then:
- light.turn_on: white_led
on_turn_off:
then:
- light.turn_off: white_led
binary_sensor:
- platform: gpio
internal: true
pin:
number: 2
mode: INPUT_PULLUP
inverted: true
name: "Button"
filters:
- delayed_on: 10ms
on_press:
then:
- switch.toggle: relay
light:
- platform: binary
internal: true
name: "white led"
id: "white_led"
output: white_output
output:
- id: 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: "Current"
voltage:
name: "Voltage"
power:
name: "Power"
energy:
name: "Energy"
update_interval: 1s
change_mode_every: 4
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