A full-stack energy dashboard that schedules a home battery against 24-hour demand, solar, and grid prices to minimize the daily electricity bill.
- Interactive 24-hour input grid for household demand, solar generation, and grid price.
- Battery capacity (M) and max charge/discharge rate (Z) as tunable hardware constraints.
- Dynamic-programming optimizer on the backend that computes the lowest possible 24-hour bill and an hourly action plan (buy, sell, charge, discharge).
- Recharts visualizations: demand/solar/price profile, energy actions with state-of-charge (SOC) tracking, and a detailed action table.
- "Load Sample" button to populate a realistic 24-hour scenario in one click.
| Layer | Tech |
|---|---|
| Backend | Python, FastAPI, Pydantic, Uvicorn |
| Frontend | React 19, Vite, Tailwind CSS v4, Recharts, Lucide |
| Tests | pytest + FastAPI TestClient |
| CI | GitHub Actions (pytest, ESLint, Vite build, gitleaks) |
| Hosting | Render (API), Vercel (UI) |
flowchart LR
U[User] --> UI[React dashboard<br/>Vercel]
UI -->|POST /api/optimize| API[FastAPI optimizer<br/>Render]
API --> DP[Dynamic programming<br/>24h battery scheduler]
DP --> API
API -->|schedule + total cost| UI
The optimizer (main.py) runs a backward dynamic program over 24 hourly states
(battery level 0..M). For each hour it evaluates every charge/discharge rate in
[-Z, Z], computes the net grid exchange D - X + Δ, prices it at the hourly
rate, and picks the path with the minimum total cost. The recovered policy is
returned as an hourly action plan.
These commands were executed from a clean clone.
git clone https://github.com/AkashNaickar/flux.git
cd flux
# backend
python -m venv .venv
.venv\Scripts\activate # Windows (source .venv/bin/activate on macOS/Linux)
pip install -r requirements.txt
uvicorn main:app --reload # http://127.0.0.1:8000
# frontend (second terminal)
cd energy-ui
npm install
npm run dev # http://localhost:5173Open the dashboard, click Load Sample, then Run Optimization.
| Variable | Required | Description |
|---|---|---|
VITE_API_URL |
no | Backend base URL for the frontend (default http://localhost:8000) |
ALLOWED_ORIGINS |
no | Comma-separated extra CORS origins allowed by the API (the deployed frontend is preconfigured on Render) |
pip install -r requirements-dev.txt
pytest -q7 tests cover the optimizer's core logic (battery constraints, bookkeeping,
no-battery baseline, surplus selling) and the /api/optimize endpoint.
- API: Render web service
flux-energy-api— Python runtime,pip install -r requirements.txt,uvicorn main:app --host 0.0.0.0 --port $PORT. https://flux-energy-api.onrender.com - UI: Vercel project
flux-energy-ui— Vite build fromenergy-ui/withVITE_API_URLset. https://flux-energy-ui.vercel.app
- Battery efficiency losses and degradation cost in the model
- Export/import of forecast scenarios (CSV/JSON)
- Tariff presets (TOU, flat, dynamic)
Issues and PRs welcome.
MIT — see LICENSE.
