Skip to content

feat(tariff): Phase 4 – PR 4-C Tarif-Adapter, Preisformel und Preisdienst - #27

Open
PXLJAKE wants to merge 5 commits into
phase-4/b-storagefrom
phase-4/c-tariff
Open

PXLJAKE wants to merge 5 commits into
phase-4/b-storagefrom
phase-4/c-tariff

Conversation

@PXLJAKE

@PXLJAKE PXLJAKE commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Gestapelt auf #26 (PR 4-B), das wiederum auf #25 (PR 4-A) aufbaut. Die Basis wird nach dem Merge der Vorgänger umgestellt.

Was

WP4 aus docs/plans/phase-4.md, Paket suncore/tariff/:

  • Vorlagengesteuerter Preisadapter (engine.py, parse.py):
    • Quelle ist eine Aktion oder ein Attribut, als Liste oder als Zuordnung.
    • Preise je MWh werden durch 1000 geteilt.
    • Das Raster kommt aus end − start oder aus dem Abstand der Zeitstempel; gemischte 15/60-Minuten-Raster werden zu Segmenten.
    • Lücken bleiben None; Sommer- und Winterzeit (23/25 h) sind abgedeckt.
    • Mehrere Häuser oder Gebiete werden nie vermischt (series_key).
    • Abgelehnt werden: falsche kWh/MWh-Einheit und eine andere Währung als die der Region.
  • Vorlagen (Quellen aus der Recherche, unverified-Listen, Conformance-Szenarien):
    • tibber.price (aktualisiert), nordpool.price, entsoe.price und entsoe.price_mwh
    • epex_spot.total_price und epex_spot.market_price, octopus_energy.rates, generic.price_list
  • Fester Preis und HT/NT (sources.py).
  • Preisformel nur auf reinen Börsenpreisen (spot_only), nie auf Endpreisen.
  • Einspeisung fest, gestaffelt (anteilig nach kWp) oder keine.
  • Negativpreis-Regel der Region: Bei de ist die Einspeisevergütung 0 in Slots mit negativem Preis.
  • TariffService:
    • Aktualisierung stündlich und bei Entity-Änderung; ab 13:00 Ortszeit alle 15 min, bis die Preise für morgen da sind.
    • Back-off nach Fehlern; gedrosselte Aufrufe zählen nicht als Fehler.
    • Gute Daten werden nie durch leere oder fehlerhafte Abrufe ersetzt; unbekannte Slots werden aus den alten Daten übernommen und gemeldet.
    • Preise werden in timeseries.db gespeichert.
  • API GET /api/v1/prices?hours=48 (1–72 h) mit Quelle, Aktualität, Qualität, price_includes und formula_missing.
  • Systemcheck-Warnung, wenn ein reiner Börsenpreis ohne Preisformel konfiguriert ist. PUT /config/tariff prüft Pflichtparameter der Vorlage (z. B. Nord Pool config_entry).
  • Nord Pool: date ist der CET-Liefertag (aus dem HA- und pynordpool-Quelltext abgeleitet, belegt in docs/research/integrations.md). Neues additives Vorlagenfeld date_tz.
  • Demo/Simulator: Der Fake beantwortet tibber.get_prices über denselben Vorlagenpfad; neues Szenario negative_prices.
  • Korrektur an 4-A-Code (core/series.py): Eine Lücke direkt vor dem letzten Punkt wird nicht mehr mit dem Nachbarwert gefüllt.

Warum

Der Planer (4-F) braucht für 24–48 h verlässliche Import- und Exportpreise im 15-Minuten-Raster, aus den Integrationen, die der Nutzer schon hat.

Wie getestet

  • ./scripts/check.sh nach dem Zusammenführen mit 4-B: ruff und mypy grün. pytest: 3522 bestanden, 1 Fehler in tests/sim/test_fake_prices.py; der Test ist korrigiert (siehe unten) und einzeln wieder grün, check.sh lief danach nicht noch einmal komplett. Frontend 219 Tests; markdownlint ohne Fehler.
  • Fixtures aus den in der Recherche dokumentierten Formen, jeweils mit Zeilenverweis.
  • Tests je Adapter: fehlende und teilweise Daten, gemischte Raster, Sommer-/Winterzeit, MWh-Umrechnung, Formel, HT/NT, Staffelung, Negativpreis-Regel, Ratenbegrenzung, Aktualisierungslogik mit injizierter Zeit, API.
  • Regressionstests zu den Review-Befunden:
    • Back-off bei fehlerhafter Attribut-Quelle.
    • Ein Abruf nur mit None behält die alten Daten.
    • Alter Stunden-Rest und neue 15-Minuten-Werte überlappen nicht.
    • Nord Pool für eine Anlage in London.
    • Abweichende Währung wird abgelehnt.
  • Nach dem Zusammenführen mit 4-B nutzt der Simulator-Preistest Unterschlüssel des Ratenbegrenzers, denn der Fake ist jetzt wie die echte Verbindung begrenzt.

Risiken

  • Preise fließen noch in keinen Schreibpfad. Erst der Planer (4-F) nutzt sie, und der muss reine Börsenpreise ohne Formel ablehnen (steht in STATUS).
  • Die Vorlagen-Schemaänderungen sind additiv: end_field, date_field, params, date_tz, response_path mit *. Neu sind die optionalen Felder role_entities, action_params, series_key und price_includes in tariff.import. Alte Dokumente laden unverändert.
  • nordpool.get_prices_for_date steht neu auf der Read-only-Allowlist. Am HA-Quelltext geprüft: SupportsResponse.ONLY, kein Zustandswechsel.

Safety-Review

n/a laut Reviewer: kein Geräte-Schreibpfad. Die Grenzregeln sind erweitert und grün; das Paket tariff importiert nur core und templates, und Aktionen ruft nur suncore.app.adapters auf. Der Tarif-Task wird beim Stoppen wie die Speicher-Tasks erst nach der Freigabe der Geräte abgewartet.

Checkliste

  • Tests für neues Verhalten, Lint/Typen/Tests grün
  • Keine hardcodierten UI-Strings; neue Keys in en und de
  • Doku aktualisiert (DOCS.md: Experten-Umgebungsvariablen tariff_*; architecture.md)
  • docs/STATUS.md aktualisiert
  • Nichts erfunden: Feldnamen aus docs/research/integrations.md, Offenes als UNVERIFIED

Offene Fragen an den Maintainer

  1. Negative Preise bei Tibber: Tibber liefert nur den Endpreis. SunCore erkennt deshalb nur Slots, in denen der Endpreis negativ ist. Das sind weniger als die echten negativen Börsenstunden. Soll später zusätzlich eine Börsenpreis-Quelle angebunden werden können?
  2. §51 EEG: Die Regel hängt vom Inbetriebnahmedatum ab. SunCore wendet die Regel für Neuanlagen an, das ist für den Planer die sichere Seite. Sollen Bestandsanlagen später (Phase 5) abschalten können?
  3. Preise für morgen: Annahme 13:00, danach alle 15 min, sonst stündlich. Bitte an deinem Tibber beobachten.
  4. Nord Pool config_entry: Reicht die manuelle Eingabe in Phase 4, oder soll SunCore sie aus der Registry lesen?
  5. Neue optionale Felder in tariff.import (role_entities, action_params, series_key, price_includes): einverstanden?
  6. UNVERIFIED:
    • Entity-IDs und Translation-Keys der Preissensoren von Nord Pool, ENTSO-E, EPEX und Octopus
    • ob tibber.get_prices ISO-Zeiten mit Offset live annimmt
    • Nord Pool date als CET-Liefertag live
    • Veröffentlichungszeit der Preise für morgen

Generated by Claude Code

…e (WP4)

Template-driven price adapter (action or attribute source, list or mapping shape, per-MWh
conversion, native 15/60-minute grid from the data, gaps as None, DST safe), templates for Tibber,
Nord Pool, ENTSO-E, EPEX Spot, Octopus Energy and a generic price list, fixed and HT/NT sources,
the price formula on spot-only sources, export fixed/tiered/none, the region's negative-price
rule, and a TariffService that keeps the prices fresh, stores them in timeseries.db and serves
them on GET /api/v1/prices. The simulator answers tibber.get_prices through the same template
path; new scenario negative_prices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHXsfH6PkT62o9idByAd6e
…es (review M1-M3)

M1: a failed fetch consumes the dirty flag and a change triggers at most one attribute fetch per
30 s, so a failing attribute source no longer refetches on every poll.
M2: a fetch without any known price is a failure; unknown slots of a fetch are filled from the
earlier data and reported as quality.carried_slots.
M3: the old tail starts at the next whole old slot (no overlap when the grids differ); the
series assembly for storing runs inside the try block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHXsfH6PkT62o9idByAd6e
… list-end gaps (review M4, m2, m4)

M4: pynordpool/HA source show that `date` is the CET delivery day (deliveryDateCET); the template
gets the additive `date_tz` field (schema changelog), request dates are computed in that zone and
the "tomorrow covered" test uses the market's end of day, so it terminates west of CET too.
Research note with repo@sha paths in docs/research/integrations.md.
m2: a source in another currency than the region (sensor unit, template unit, `currency` action
field) raises CurrencyMismatchError (en/de key).
m4: core/series.py segments_from_points (4-A code): at the end of a list a gap that is a multiple
of the running step is a gap (None), not a resolution change; the rhythm needs a confirming
distance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHXsfH6PkT62o9idByAd6e
…its (review m1, m3, m5, n1-n5)

m1: system check warns about a spot-only import price without a price formula; PriceReport
carries price_includes and formula_missing; PUT /config/tariff rejects a missing required
request field of the template (422, en/de key); STATUS records that the 4-F planner must refuse
spot_only prices without a formula.
m3: the three tariff settings are documented as expert environment variables in both app
DOCS.md files (no app options); plan question wording fixed.
m5: plan question on the per-plant opt-out of the section 51 EEG rule (commissioning date).
n1: architecture table and diagram: tariff no longer depends on ha. n2: EPEX market template
text. n3: ambiguous-series names are joined before ICU. n4: adapters docstring. n5: tests use
end_price, apply is marked as a deprecated alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHXsfH6PkT62o9idByAd6e
Resolves runtime.stop (tariff task joins the storage tasks that are awaited after the
devices are released) and STATUS; the fake-price test uses rate-limit sub-keys now that
the fake is rate limited like the real connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHXsfH6PkT62o9idByAd6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants