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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solar_forecast_langgraph-0.1.2.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solar_forecast_langgraph-0.1.2-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file solar_forecast_langgraph-0.1.2.tar.gz.

File metadata

  • Download URL: solar_forecast_langgraph-0.1.2.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for solar_forecast_langgraph-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3d9437c035d0489dda274dbc46d4af1deb754acc2c1590080c509cce8c3022da
MD5 71f22c017e2898f03bd36ade6c89d189
BLAKE2b-256 2f9ac85b13639ffbe82f1cbd6c47fc03d6e95c037878835dff8b207ca82dc6a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for solar_forecast_langgraph-0.1.2.tar.gz:

Publisher: ci.yml on 4alvit/solar-forecast-langgraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file solar_forecast_langgraph-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for solar_forecast_langgraph-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6928e4a9eddfeabde9ccb10dc38e19a3b98af104492efd3990ad031986cc83c6
MD5 1e943bd1090b7a49a0b25090afe6f33e
BLAKE2b-256 ae7275cbbc1cd55f5d81d69e35558bd66cc5bd1be5bbaee8ca985fd897e65495

See more details on using hashes here.

Provenance

The following attestation bundles were made for solar_forecast_langgraph-0.1.2-py3-none-any.whl:

Publisher: ci.yml on 4alvit/solar-forecast-langgraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page