3.4 KiB
Project Context
This project is a Dockerised SwitchBot temperature dashboard built from an initial SwitchBot API v1.1 Python proof of concept.
Current Shape
docker-compose.ymlstarts three services:db: MySQL 8.4 with themysql_datavolume.web: Flask app served by Gunicorn on port 8000.collector: Python polling loop.
app/switchbot.pycontains the SwitchBot v1.1 signed request client.app/collector.pysyncs devices from SwitchBot and records sensor readings.app/web.pyserves the dashboard, reports, CSV export, and per-device views.switchbot_poc.pyremains as a low-level API sanity-check script.
Configuration
Runtime config is provided by .env, copied from .env.example.
Required values:
SWITCHBOT_TOKEN=...
SWITCHBOT_SECRET=...
FLASK_SECRET_KEY=...
Important: do not commit .env; it is intentionally ignored.
The default polling interval is:
COLLECT_INTERVAL_SECONDS=900
The default timezone is:
APP_TIMEZONE=Europe/London
SwitchBot Notes
The SwitchBot API only exposes devices owned by the account that generated the
token/secret. Devices merely shared with the account do not appear in
/devices.
Working discovered devices were:
CB11A9610CFB:Hub Mini FB,Hub Mini2EE2E01862061:Meds Cupboard,WoIOSensorEE2E0446360E:Fridge Med,WoIOSensorEE2E05C6434C:Main Room,WoIOSensor
Hub Mini2 is treated as infrastructure. It is stored in the database when
discovered, but hidden from the dashboard/reports and skipped by the collector
for readings.
Current sensor allow-list:
SENSOR_DEVICE_TYPES = {"WoIOSensor"}
Features Implemented
- Responsive dashboard at
/. - Sensor cards show latest reading, day low, day high, and battery.
- Hub devices are suppressed from the dashboard.
- Day-so-far graph rendered with local canvas JavaScript, no CDN.
- Clicking a sensor card opens
/devices/<device_id>. - Per-device page shows:
- selected day
- samples
- low/high temperature
- graph for that device/day
- timestamped readings table
- Reports at
/reports. - CSV export at
/reports.csv.
Common Commands
Start or restart:
docker compose up --build -d
Follow collector logs:
docker compose logs -f collector
Check row counts:
docker compose exec -T db mysql -uswitchbot -pswitchbot_password switchbot \
-e "select count(*) as devices from devices; select count(*) as readings from readings;"
Run the original POC:
python3 switchbot_poc.py
python3 switchbot_poc.py --endpoint /devices/EE2E01862061/status
Verification Performed
- Python syntax checks pass for the app modules.
- Docker build succeeded.
- MySQL became healthy.
- Web app responded with
HTTP 200 OK. - Reports and CSV endpoints responded with
HTTP 200 OK. - Collector successfully recorded readings for the three
WoIOSensordevices. - Browser verification confirmed:
- dashboard shows only the three sensors
- Hub Mini is hidden
- clicking a tile opens the device/day readings page
- timestamped readings display in local time
Likely Next Improvements
- Add migrations instead of using
Base.metadata.create_all. - Add a manual "collect now" endpoint/button.
- Add CSV export for a single device/day readings table.
- Add alert thresholds for fridge/medicine storage temperatures.
- Add authentication if exposed beyond a trusted local network.