Skip to main content

Solar Forecast LangGraph

CI Coverage PyPI Python License

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 (recommended)

# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# Install from PyPI
pip install solar-forecast-langgraph

After installing, check the CLI is available:

solar-forecast --help

From source (for development)

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


License

MIT License — see LICENSE for details.

Metadata

Release files for solar-forecast-langgraph 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for solar-forecast-langgraph 0.1.2
File Size Uploaded
solar_forecast_langgraph-0.1.2.tar.gz 24.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for solar-forecast-langgraph 0.1.2
File Interpreter ABI Platform
solar_forecast_langgraph-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 45.4 kB

Release files / solar_forecast_langgraph-0.1.2.tar.gz

Download URL solar_forecast_langgraph-0.1.2.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3d9437c035d0489dda274dbc46d4af1deb754acc2c1590080c509cce8c3022da
BLAKE2b-256 checksum
How to use checksums
2f9ac85b13639ffbe82f1cbd6c47fc03d6e95c037878835dff8b207ca82dc6a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.

Transparency log

Release files / solar_forecast_langgraph-0.1.2-py3-none-any.whl

Download URL solar_forecast_langgraph-0.1.2-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6928e4a9eddfeabde9ccb10dc38e19a3b98af104492efd3990ad031986cc83c6
BLAKE2b-256 checksum
How to use checksums
ae7275cbbc1cd55f5d81d69e35558bd66cc5bd1be5bbaee8ca985fd897e65495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page