Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All notable changes are listed here. Versions follow [Semantic Versioning](https://semver.org/).

## [0.4.0] - unreleased

A converted plug now boots the full hardware profile, so it reports power and energy right away. No second flash is needed before it is useful.

### Added

- `firmware/esphome/plug-mini.yaml`: the plug's hardware as one public package. Relay output, button, both LEDs, BL0937 power monitoring with calibration and range checks, lifetime and daily energy, chip temperature. No Wi-Fi, API, OTA, names or secrets. Use it as a remote package to build your own config.
- Power, current and voltage are measured every 2 seconds but sent to Home Assistant only on a real change (1 W, 0.05 A, 1 V) plus a heartbeat. Below 1.5 W the plug reads 0. The raw 2 second values stay available on the plug (`id(power)` and so on) for lambdas.
- Device Builder and Home Assistant offer **Adopt** for a converted plug (ESPHome project `wifiguy512.switchback-plug-mini`).
- `firmware/esphome/addon-ble-proxy.yaml`: an optional Bluetooth proxy with passive scanning, to add over OTA. It is not in any payload.
- The relay is latched through clean restarts, so an OTA update does not blip the load.

### Changed

- `sbplug-common.yaml` now includes `plug-mini.yaml` and adds the bootstrap defaults: the "Relay" switch, the button scripts (short press toggles, hold 10 seconds to factory reset), an sntp time source and the captive portal. The relay switch keeps its name and id. The blue LED shows Wi-Fi and Home Assistant state instead of ESPHome's status pattern.
- The button's short press now accepts presses up to 2.9 seconds (was 1 second).

## [0.3.0] - 2026-11-18

First release from this repository, with fresh history.
Expand Down
54 changes: 48 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,40 @@ A plain "check for update" in the app does not work: that path uses SwitchBot's

## After conversion

The image Switchback writes is a small bootstrap. It has:
The image Switchback writes is the full hardware profile, so a plug is useful as soon as it joins your Wi-Fi. It shows up as `sbplug-xxxxxx` with:

- the relay, the button (short press toggles, hold 10 seconds to factory reset) and the blue status LED,
- the ESPHome API **without encryption**,
- OTA with the published password **`switchbota`**.
- **Relay**, a switch. It stays off after a power cut. A clean restart or an OTA update does not blip the load.
- **Outlet Power**, **Outlet Current** and **Outlet Voltage**. The plug measures every 2 seconds but only sends a reading when it changes by a real amount (1 W, 0.05 A, 1 V), plus a heartbeat, so your history stays small. Below 1.5 W it reads 0.
- **Outlet Energy** (lifetime, kWh) and **Outlet Daily Energy** (Wh, resets at midnight), once a minute. Both work with the Home Assistant Energy dashboard.
- **Internal Temp**, the chip temperature, as a diagnostic.
- The button: a short press toggles the relay. Hold it 10 seconds to factory reset.
- The white LED follows the relay. The blue LED blinks fast with no Wi-Fi, stays on with Wi-Fi but no Home Assistant, and glows slowly once Home Assistant is connected.
- The ESPHome API **without encryption**, and OTA with the published password **`switchbota`**.

Adopt the plug in ESPHome or Home Assistant and flash your own config over OTA right away, with your own API key and OTA password. You can build on the same hardware definition as a remote package:
There is no Bluetooth proxy in the image. It would not fit in the first write. Add it later over OTA if you want one (see below).

The power readings use a calibration measured on one batch of plugs (October 2026) against a reference meter. Yours should be within a few percent. To use your own figures, set `voltage_cal`, `current_cal` and `power_cal` in your config.

### Adopt it

Device Builder and Home Assistant offer an **Adopt** button for a converted plug. Adopting writes a short config that pulls in this repository's firmware, pinned to the release, and adds your own Wi-Fi and a fresh API encryption key. Install it once over OTA and you are done. Change the OTA password at the same time:

```yaml
substitutions:
ota_password: !secret ota_password
```

### Or build your own config

`plug-mini.yaml` is the hardware on its own: relay output, button, LEDs, power monitoring. It has no Wi-Fi, API or OTA section, no names and no secrets, so you can build anything on it. Your config supplies the relay switch, the two button scripts (`on_button_press`, `on_button_hold`) and a time source. `sbplug-common.yaml` shows the defaults.

```yaml
esphome:
name: kitchen-kettle

packages:
switchback: github://WiFiGUY512/switchback/firmware/esphome/sbplug-common.yaml@v0.3.0
plug: github://WiFiGUY512/switchback/firmware/esphome/plug-mini.yaml@v0.4.0
# ble: github://WiFiGUY512/switchback/firmware/esphome/addon-ble-proxy.yaml@v0.4.0

api:
encryption:
Expand All @@ -151,8 +174,27 @@ ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

time:
- platform: homeassistant

switch:
- platform: output
name: "Relay"
id: relay
output: relay_output
restore_mode: RESTORE_DEFAULT_ON

script:
- id: on_button_press
then:
- switch.toggle: relay
- id: on_button_hold
then: []
```

Lambdas that act on load (for example, "turn off when the kettle is done") should read the raw 2 second values, `id(power).state`, `id(current).state` and `id(voltage).state`. Home Assistant gets the rate-limited copies.

To flash a config while the plug is still in hotspot mode, join its `sbplug-xxxxxx` network and run `esphome upload your.yaml --device 192.168.4.1` (OTA password `switchbota`).

## Commands
Expand Down
30 changes: 30 additions & 0 deletions firmware/esphome/addon-ble-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#==============================================================================
# Optional: Bluetooth proxy for Home Assistant (add over OTA, after converting)
#==============================================================================
# Not part of any Switchback payload. The Bluetooth stack makes the image too
# large for the flasher's first write, so add it in your own config once the
# plug runs ESPHome:
#
# packages:
# plug: github://WiFiGUY512/switchback/firmware/esphome/plug-mini.yaml@v0.4.0
# ble: github://WiFiGUY512/switchback/firmware/esphome/addon-ble-proxy.yaml@v0.4.0
#
# Wi-Fi and Bluetooth share the ESP32-C3's one radio. Scanning is passive,
# and interval and window are left to ESPHome, which keeps the window at or
# under 320 ms while Wi-Fi is up. Long windows (the old 1100 ms setting)
# starve Wi-Fi. Only add this to plugs that are near Bluetooth devices you
# use; a few well placed proxies beat one on every plug.
#==============================================================================

esp32:
framework:
sdkconfig_options:
CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y

esp32_ble_tracker:
scan_parameters:
active: false

bluetooth_proxy:
active: true
Loading
Loading