Rust power monitoring bridge for TP-Link Kasa smart plugs
- Rust 95.9%
- Dockerfile 4.1%
Rust binary using kasa-core to poll TP-Link Kasa smart plugs (EP25s and HS300s) over XOR/KLAP protocols, exposing readings as a JSON HTTP endpoint for downstream ingestion by Redpanda Connect. Plug inventory is configured via env vars (SMART_KLAP_PLUGS, IOT_XOR_PLUGS, HS300_PLUGS) rather than hardcoded IPs. |
||
|---|---|---|
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| Dockerfile | ||
| README.md | ||
kasa-bridge
Polls TP-Link Kasa smart plugs via kasa-core and exposes the readings as a JSON HTTP endpoint. Designed as the ingestion source for a Redpanda Connect pipeline.
What it does
- Polls Kasa plugs on the local network every 10 seconds
- Handles three protocol variants transparently:
- XOR / IOT family — older firmware, no credentials
- KLAP / SMART family — newer plugs, cloud credentials
- KLAP / IOT family — HS300 power strips, cloud credentials, per-outlet queries
- Serves
GET /readingsreturning a JSON array of per-outlet readings GET /healthfor liveness probes
Reading schema
{
"plug_id": "10.10.10.185-slot3",
"alias": "Asgard 2",
"timestamp": "2026-06-21T02:59:35.762Z",
"watts": 14.6,
"volts": 115.9,
"amps": 0.16,
"kwh_today": null,
"kwh_month": null,
"kwh_total": 19.9,
"on_state": true,
"rssi": -43,
"model": "HS300"
}
Configuration
| Env var | Default | Description |
|---|---|---|
KASA_USERNAME |
— | TP-Link cloud account email (required for KLAP plugs) |
KASA_PASSWORD |
— | TP-Link cloud account password (required for KLAP plugs) |
SMART_KLAP_PLUGS |
— | Comma/space-separated IPs of SMART-family KLAP plugs (e.g. EP25 hw2.6) |
IOT_XOR_PLUGS |
— | Comma/space-separated IPs of IOT-family XOR plugs (e.g. EP25 hw1.0, no credentials) |
HS300_PLUGS |
— | Comma/space-separated IPs of IOT-family KLAP power strips (e.g. HS300) |
HS300_OUTLETS |
6 |
Number of outlets per power strip |
POLL_INTERVAL_SECS |
10 |
Seconds between polls |
BIND_ADDR |
0.0.0.0:8080 |
HTTP server bind address |
RUST_LOG |
info |
Tracing log level |
Each plug list accepts comma- or whitespace-separated IPs/hostnames, e.g.:
SMART_KLAP_PLUGS=10.10.10.115,10.10.10.163
IOT_XOR_PLUGS="10.10.10.59 10.10.10.218"
HS300_PLUGS=10.10.10.108,10.10.10.185
Build
cargo build --release
Container image
Multi-stage Dockerfile builds a slim debian image:
podman build -t kasa-bridge .
The container image is published to the Forgejo OCI registry at git.clee.sh/clee/kasa-bridge.