2026-09-06 15:53:58 +02:00
|
|
|
# Hue RRD Flask dashboard
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
A lightweight Flask application for Raspberry Pi that reads the Philips Hue v2 API,
|
|
|
|
|
stores history in fixed-size RRDtool databases, and serves a local web dashboard.
|
2026-09-06 15:31:57 +02:00
|
|
|
|
|
|
|
|
The dashboard contains:
|
|
|
|
|
|
|
|
|
|
- One graph for every room and zone. Unavailable, off, and on lights form a stacked
|
|
|
|
|
percentage area, with average intensity of shining lights drawn as a line.
|
2026-09-06 15:53:58 +02:00
|
|
|
- Temperature and illuminance graphs for every Hue sensor.
|
2026-09-06 15:31:57 +02:00
|
|
|
- 6-hour, 24-hour, 7-day, and 30-day time ranges.
|
|
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
RRD storage remains bounded automatically: raw samples are retained for 7 days,
|
2026-09-06 15:31:57 +02:00
|
|
|
approximately five-minute averages for 90 days, and hourly averages for two years.
|
|
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
## Install on Raspberry Pi OS or Debian
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-09-06 15:57:14 +02:00
|
|
|
Install Python's virtual-environment support and the native headers needed to build
|
|
|
|
|
the RRDtool package, then install every Python dependency into `.venv`:
|
2026-09-06 15:53:58 +02:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo apt update
|
2026-09-06 15:57:14 +02:00
|
|
|
sudo apt install python3 python3-venv python3-dev build-essential librrd-dev fonts-dejavu-core
|
|
|
|
|
python3 -m venv .venv
|
|
|
|
|
. .venv/bin/activate
|
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
|
python -m pip install -r requirements.txt
|
2026-09-06 15:53:58 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Create the Hue application key if you do not have one yet. Press the bridge link
|
|
|
|
|
button immediately before running:
|
2026-09-06 15:31:57 +02:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
curl -k -X POST https://BRIDGE_IP/api \
|
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
|
-d '{"devicetype":"local-hue-collector"}'
|
|
|
|
|
```
|
|
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
The returned `username` is the application key.
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
Configure and run the Flask application from the project directory:
|
2026-09-06 15:31:57 +02:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cp .env.example .env
|
|
|
|
|
# Edit .env with the bridge IP and application key.
|
2026-09-06 15:53:58 +02:00
|
|
|
set -a
|
|
|
|
|
. ./.env
|
|
|
|
|
set +a
|
2026-09-06 15:57:14 +02:00
|
|
|
python -m hue_collector
|
2026-09-06 15:31:57 +02:00
|
|
|
```
|
|
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
Open `http://PI_ADDRESS:8000`. The RRD files are written to `DATA_DIR`, which defaults
|
|
|
|
|
to the project's `data/` directory.
|
|
|
|
|
|
|
|
|
|
## Run continuously with systemd
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-09-06 15:57:14 +02:00
|
|
|
The included unit expects this repository at `/srv/service_hue_collector`, including
|
|
|
|
|
its `.venv` and `.env` files:
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
```bash
|
2026-09-06 15:57:14 +02:00
|
|
|
sudo chmod 600 /srv/service_hue_collector/.env
|
2026-09-06 15:53:58 +02:00
|
|
|
sudo cp hue-collector.service /etc/systemd/system/
|
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
sudo systemctl enable --now hue-collector
|
2026-09-06 15:31:57 +02:00
|
|
|
```
|
|
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
The included unit uses a restricted dynamic service account and stores RRD files in
|
|
|
|
|
`/var/lib/hue-collector`. Inspect it with:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
systemctl status hue-collector
|
|
|
|
|
journalctl -u hue-collector -f
|
|
|
|
|
```
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
After updating the application files, restart it with:
|
2026-09-06 15:31:57 +02:00
|
|
|
|
|
|
|
|
```bash
|
2026-09-06 15:53:58 +02:00
|
|
|
sudo systemctl restart hue-collector
|
2026-09-06 15:31:57 +02:00
|
|
|
```
|
|
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
## Configuration
|
|
|
|
|
|
|
|
|
|
- `HUE_BRIDGE_HOST`: Hue bridge IP or hostname; required.
|
|
|
|
|
- `HUE_APPLICATION_KEY`: Hue v2 application key; required.
|
|
|
|
|
- `HUE_VERIFY_TLS`: verify the bridge certificate; defaults to `false` because Hue
|
|
|
|
|
bridges normally use a self-signed certificate.
|
|
|
|
|
- `COLLECT_INTERVAL_SECONDS`: sampling interval; defaults to 30 seconds. Changing it
|
|
|
|
|
after RRD files have been created does not change those existing files' step.
|
|
|
|
|
- `LISTEN_HOST`: Flask bind address; defaults to `0.0.0.0` for LAN access.
|
|
|
|
|
- `LISTEN_PORT`: dashboard port; defaults to `8000`.
|
|
|
|
|
- `DATA_DIR`: RRD directory; defaults to `data`.
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-09-06 15:53:58 +02:00
|
|
|
The application is intended for a trusted home network and does not provide
|
|
|
|
|
authentication or TLS. Restrict access with the Pi firewall if the network is not
|
|
|
|
|
trusted.
|
2026-08-30 14:26:11 +02:00
|
|
|
|
|
|
|
|
## Development
|
|
|
|
|
|
2026-09-06 15:57:14 +02:00
|
|
|
Create the virtual environment and install all application dependencies from the
|
|
|
|
|
requirements file:
|
2026-09-06 15:31:57 +02:00
|
|
|
|
2026-08-30 14:26:11 +02:00
|
|
|
```bash
|
2026-09-06 15:57:14 +02:00
|
|
|
sudo apt install python3-venv python3-dev build-essential librrd-dev fonts-dejavu-core
|
|
|
|
|
python3 -m venv .venv
|
|
|
|
|
. .venv/bin/activate
|
|
|
|
|
python -m pip install -r requirements.txt
|
|
|
|
|
python -m unittest discover -s tests
|
2026-08-30 14:26:11 +02:00
|
|
|
```
|