Solar Forecast LangGraph
LangGraph workflow for solar forecasting with:
- Weather data agent — OpenMeteo API (free, no key required)
- Historical generation loader — From inverter-monitoring webhook
- Panel configuration schema — Azimuth, tilt, capacity, losses
- Forecast model — Physical (clear-sky + clouds) + Statistical (ML) + LLM reasoning
- Inverter-control integration — Pre-charge battery before cloudy periods
- Accuracy tracking — Feedback loop for continuous improvement
Architecture
graph TD
A[User Request] --> B[LangGraph Workflow]
B --> C[Fetch Weather<br/>OpenMeteo API]
B --> D[Fetch History<br/>inverter-monitoring]
C --> E[Train Statistical Model]
D --> E
E --> F[Generate Forecast<br/>Physical + Statistical Ensemble]
F --> G[LLM Enhancement<br/>Weather pattern analysis]
G --> H[Inverter-Control Hook<br/>Pre-charge decision]
H --> I[Final Forecast Output]
I --> J[Accuracy Tracking<br/>Feedback Loop]
J -.-> K[Model Retraining - Scheduler]
subgraph "Data Sources"
C
D
end
subgraph "Models"
E
F
G
end
subgraph "Integrations"
H
end
Installation
# From PyPI (when published)
pip install solar-forecast-langgraph
# From source
git clone git@github.com:4alvit/solar-forecast-langgraph.git
cd solar-forecast-langgraph
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pre-commit install
Quick Start
# Copy example config and customize
cp site_config.example.py site_config.local.py
# Edit site_config.local.py with your panel details
# Run forecast (48h horizon, 30 days history)
solar-forecast --config site_config.local.py --horizon 48 --output forecast.json
Output example:
Forecast Summary:
Site: my-solar-site
Panel: south-roof
Method: ensemble
Horizon: 48 hours
Total Energy: 42500 Wh
Generated: 2024-01-15T10:30:00+00:00
Next 12 hours:
2024-01-15 11:00: 1200W (1200Wh) [960-1440]
2024-01-15 12:00: 2800W (2800Wh) [2240-3360]
2024-01-15 13:00: 3500W (3500Wh) [2800-4200]
Configuration
Panel Configuration
from solar_forecast.config import PanelConfig, SiteConfig
panel = PanelConfig(
name="South Roof",
panel_id="south-roof",
azimuth=180, # 0=N, 90=E, 180=S, 270=W
tilt=35, # Degrees from horizontal
capacity_kw=5.0, # DC capacity
module_count=14,
latitude=52.37,
longitude=4.90,
# Optional losses
shading_loss=0.0,
soiling_loss=0.02,
wiring_loss=0.01,
module_efficiency=0.20,
temperature_coefficient=-0.0035,
inverter_efficiency=0.96,
dc_ac_ratio=1.2,
)
site = SiteConfig(
site_name="my-site",
latitude=52.37,
longitude=4.90,
timezone="Europe/Amsterdam",
panels=[panel],
)
See site_config.example.py for full example.
Forecast Methods
| Method | Description | Use Case |
|---|---|---|
physical |
Clear-sky model + cloud adjustment | No historical data |
statistical |
ML model on historical data | Sufficient history (30+ days) |
ensemble |
Weighted: 60% physical + 40% statistical | Default, best accuracy |
llm_enhanced |
LLM analyzes weather patterns | Future: complex weather |
Inverter-Control Integration
The workflow includes a hook for pre-charging batteries before forecasted cloudy periods:
sequenceDiagram
participant WF as LangGraph Workflow
participant FC as Forecast
participant IC as Inverter-Control
WF->>FC: Generate 48h forecast
FC->>WF: Forecast points with confidence
WF->>WF: Analyze next 6h total energy
alt Low generation (< 5kWh in 6h)
WF->>IC: POST /api/v1/pre-charge
IC->>IC: Increase battery target SoC
IC-->>WF: Pre-charge initiated
end
Enable in config:
# In site_config.local.py
INVERTER_CONTROL_URL = "http://inverter-control:8081"
INVERTER_CONTROL_API_KEY = "your-key"
Accuracy Tracking
Feedback loop for continuous improvement:
graph LR
A[Forecast] --> B[Actual Generation]
B --> C[Error Metrics]
C --> D{Error > Threshold?}
D -->|Yes| E[Flag for Review]
D -->|No| F[Update Training Data]
F --> G[Retrain Model]
E --> H[Human Analysis]
H --> G
Metrics tracked per panel:
- MAE (Mean Absolute Error)
- RMSE (Root Mean Square Error)
- MAPE (Mean Absolute Percentage Error)
- Bias (Systematic over/under prediction)
Development
Run Tests
pytest tests/ -v --cov=solar_forecast
Lint & Format
ruff check .
ruff format .
Type Check
mypy solar_forecast/
Project Structure
solar-forecast-langgraph/
├── solar_forecast/
│ ├── __init__.py # Public exports
│ ├── config.py # Panel/Site configuration schemas
│ ├── weather.py # OpenMeteo client
│ ├── history.py # Historical data loaders
│ ├── model.py # Physical/Statistical/LLM models
│ ├── workflow.py # LangGraph workflow
│ └── main.py # CLI entry point
├── tests/
│ ├── test_config.py
│ ├── test_weather.py
│ ├── test_model.py
│ └── test_workflow.py
├── .github/workflows/ci.yml # CI/CD pipeline
├── pyproject.toml # Package config
├── site_config.example.py # Example configuration
└── README.md
Roadmap
- LLM-enhanced forecasting (weather pattern analysis)
- Automated model retraining scheduler
- Prometheus metrics export
- Grafana dashboard template
- Multi-site support in single workflow
- Battery SoC optimization (not just pre-charge)
- Shadow modeling from 3D terrain
Related Projects
- inverter-monitoring — Generation data webhook
- inverter-control — Grid-zero feed-in control
License
MIT License — see LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solar_forecast_langgraph-0.1.0.tar.gz.
File metadata
- Download URL: solar_forecast_langgraph-0.1.0.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7dbe3e5a69b42e94b55381a7ebae89e17221bd14c13bc0039d5857050727653
|
|
| MD5 |
6117cc57736632eacbaa705b2cc199d0
|
|
| BLAKE2b-256 |
1015c333f45e28380973f50310212134a0494c3bf1da9fd03b5a8e3111bfaaeb
|
Provenance
The following attestation bundles were made for solar_forecast_langgraph-0.1.0.tar.gz:
Publisher:
ci.yml on 4alvit/solar-forecast-langgraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
solar_forecast_langgraph-0.1.0.tar.gz -
Subject digest:
d7dbe3e5a69b42e94b55381a7ebae89e17221bd14c13bc0039d5857050727653 - Sigstore transparency entry: 2413873321
- Sigstore integration time:
-
Permalink:
4alvit/solar-forecast-langgraph@a7485ad053f518eeb41112674036833cf7fba6f9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/4alvit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@a7485ad053f518eeb41112674036833cf7fba6f9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file solar_forecast_langgraph-0.1.0-py3-none-any.whl.
File metadata
- Download URL: solar_forecast_langgraph-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65d267b227f410786bf4d2fba6dcc533724ada0731b2a7b2dfb37829b57d4184
|
|
| MD5 |
e06545dc6c97af4b8acab3f8bbebf72f
|
|
| BLAKE2b-256 |
db152f936b8be50cc12c6c280a7f9fb8d51aabb74393c9fccf85264282a3d54b
|
Provenance
The following attestation bundles were made for solar_forecast_langgraph-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on 4alvit/solar-forecast-langgraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
solar_forecast_langgraph-0.1.0-py3-none-any.whl -
Subject digest:
65d267b227f410786bf4d2fba6dcc533724ada0731b2a7b2dfb37829b57d4184 - Sigstore transparency entry: 2413873568
- Sigstore integration time:
-
Permalink:
4alvit/solar-forecast-langgraph@a7485ad053f518eeb41112674036833cf7fba6f9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/4alvit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@a7485ad053f518eeb41112674036833cf7fba6f9 -
Trigger Event:
push
-
Statement type: