An ML-powered system that predicts solar power generation and helps you manage home appliances intelligently through a digital twin interface.
Built with XGBoost, FastAPI, and a real-time web dashboard.
- Predicts solar power output based on weather and time conditions
- Simulates a digital twin of your home appliances
- Automatically manages appliance usage based on available solar power
- Provides a live dashboard to monitor, control, and optimize energy consumption
- Exposes a RESTful API for easy integration with other systems
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Weather Data │ │ Power Data │ │ ML Model │
│ (CSV Files) │───▶│ (Excel Files) │───▶│ (XGBoost) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ FastAPI │◀───│ Data │───▶│ Predictions │
│ Backend │ │ Processor │ │ & Analytics │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐
│ Web Frontend │◀───│ Digital Twin │
│ (HTML/JS) │ │ Controller │
└─────────────────┘ └─────────────────┘
1. Clone the repository
git clone https://github.com/Mayan10/final-solar.git
cd final-solar2. Install dependencies
pip install -r requirements.txt3. Run the system
python run.pyThe dashboard will be available at http://localhost:8000.
final-solar/
├── api.py # FastAPI backend
├── data_processor.py # Data loading and preprocessing
├── model_trainer.py # XGBoost model training
├── run.py # Main entry point
├── requirements.txt # Python dependencies
├── static/
│ └── index.html # Web frontend
├── data/ # Raw data files
└── models/ # Trained models
| Method | Endpoint | Description |
|---|---|---|
| POST | /predict/power |
Predict power for specific conditions |
| POST | /predict/daily |
Predict power for an entire day |
| POST | /train-model |
Train or retrain the model |
| Method | Endpoint | Description |
|---|---|---|
| GET | /digital-twin/status |
Get current system status |
| GET | /digital-twin/appliances |
List all appliances |
| POST | /digital-twin/control |
Control a specific appliance |
| POST | /digital-twin/optimize |
Optimize energy usage |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Web dashboard |
| GET | /health |
Health check |
| GET | /docs |
API documentation (Swagger UI) |
Single power prediction
import requests
response = requests.post("http://localhost:8000/predict/power", json={
"hour": 12,
"temperature": 25.5,
"global_irradiance": 800,
"direct_irradiance": 600,
"diffuse_irradiance": 200,
"month": 6
})
print(f"Predicted Power: {response.json()['power_kw']} kW")Control an appliance
# Turn on air conditioner
response = requests.post("http://localhost:8000/digital-twin/control", json={
"appliance_id": "ac_1",
"action": "on"
})
# Optimize for 5 kW of available solar
response = requests.post("http://localhost:8000/digital-twin/optimize", json=5.0)Full-day prediction
weather_forecast = [
{"hour": h, "temperature": 25, "global_irradiance": 800,
"direct_irradiance": 600, "diffuse_irradiance": 200, "month": 6}
for h in range(24)
]
response = requests.post("http://localhost:8000/predict/daily", json={
"prediction_date": "2024-06-15",
"weather_forecast": weather_forecast
})
print(f"Total Energy: {response.json()['total_power_kwh']} kWh")| Appliance | Power (kW) | Priority | Controllable |
|---|---|---|---|
| Air Conditioner 1 | 2.0 | High | Yes |
| Air Conditioner 2 | 2.0 | Medium | Yes |
| Water Heater | 1.5 | Medium | Yes |
| Washing Machine | 1.0 | Medium | Yes |
| TV | 0.2 | Low | Yes |
| LED Lights | 0.1 | Low | Yes |
| Refrigerator | 0.2 | High | No |
Input features:
- Time: Hour and month (cyclically encoded)
- Weather: Temperature, humidity, global/direct/diffuse irradiance
- Derived: Irradiance ratios, rolling averages, lag features
XGBoost parameters:
n_estimators=100
max_depth=6
learning_rate=0.1
subsample=0.8
colsample_bytree=0.8Typical performance:
- R² Score: 0.85 – 0.95
- RMSE: 50 – 150 W
- MAE: 30 – 100 W
- High-priority appliances (e.g., refrigerator, AC) are allocated power first
- Available solar power is distributed across remaining loads
- Non-essential appliances are switched off when supply is low
- All changes are tracked in real time through the dashboard
Model not trained
- Call
POST /train-modelto trigger training - Make sure data files are present in the
data/folder
API not responding
- Confirm the server is running on port 8000
- Check for firewall or port conflicts
Prediction errors
- Verify your input matches the expected schema
- Ensure the model has been loaded successfully
- Solar irradiance data from PVGIS (European Commission)
Mayan Sharma GitHub: @Mayan10
This project is licensed under the MIT License. See the LICENSE file for details.