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.1.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.1-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: solar_forecast_langgraph-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 fe61c252c39bcf0d3207cd5aaca780d1fb608daf7cee6321150d109d35465273
MD5 42386dee8d55fcf606b045bfb0b79f87
BLAKE2b-256 e96b0b21fc066c172d843b4a33f56c51c40f1c0d9307fd7e79027b834e2c441d

See more details on using hashes here.

Provenance

The following attestation bundles were made for solar_forecast_langgraph-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for solar_forecast_langgraph-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b46f114866b593902d139b59b9c1304bfe0887c868f947e0e0178c8e167bb495
MD5 605868dfb62fe2c26a6a4054a2c130cf
BLAKE2b-256 15251c6f73c53bc9aea9e5efd5ad3435d7a69f0c32d2c49a4649a3d57d7d0920

See more details on using hashes here.

Provenance

The following attestation bundles were made for solar_forecast_langgraph-0.1.1-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