# einsd Operator Guide

> Operator guide for einsd, the EEG/KWKG feed-in settlement daemon: plant registry, §51 Negativpreisregel, §52 Pflichtzahlungen, 20 MCP tools, eeg-agent.

Source: https://hupe1980.github.io/mako/docs/services/einsd/

`einsd` is the **Einspeiser registry and EEG/KWKG settlement daemon** for the
Netzbetreiber, on port **`:9180`**.

It registers feed-in plants under every EEG (2000–2023) and CHP plants under the
KWKG, settles them monthly under **12 settlement models** on the ten formula
schemes of
[`eeg-billing`](https://github.com/hupe1980/mako/tree/main/crates/eeg-billing)
(pure, `Decimal` only, no I/O), and issues the § 14 UStG Gutschrift each payment
rests on.

**Einspeisevergütung** is the fixed tariff the NB pays for fed-in electricity;
in **Direktvermarktung** the operator sells on the market and the NB pays a
**Marktprämie**. Which applies is the plant's **Veräußerungsform** (§ 21b EEG
2023).

```mermaid
graph TB
    Operator["NB operator / ERP"]
    edmd["edmd :8380<br/>¼h Einspeisung"]
    einsd["einsd :9180"]
    eeg_billing["eeg-billing<br/>settlement schemes, §§ 51–54, no I/O"]
    db[("PostgreSQL")]
    erp["ERP webhook"]
    accountingd["accountingd :9380"]
    agentd["agentd :9580<br/>eeg-agent"]

    Operator -->|"REST"| einsd
    einsd --> eeg_billing
    einsd <-->|"GET /api/v1/energy/{malo_id}?direction=EINSPEISUNG"| edmd
    einsd --> db
    einsd -->|"de.mako.eeg.*"| erp
    einsd -->|"de.mako.eeg.verguetung.berechnet · de.mako.eeg.marktpraemie.berechnet"| accountingd
    einsd -->|"de.mako.eeg.*"| agentd
```

---

## EEG versions

`eeg_anlagen.eeg_gesetz` (stored as 0, 2000, 2004, 2009, 2012, 2017, 2021 or
2023; `from_db_year()` maps intermediate years, e.g. 2018 → 2017) selects the
law-year rules — the § 52 regime and the § 100 Übergangsbestimmungen — through
the `EegGesetz` enum (`Kwkg`, `Eeg2000` … `Eeg2023`).

**§ 51 is not one of them.** The Solarspitzengesetz rewrote § 51 on 25 February
2025, inside the EEG 2023 range, so § 51 is keyed on the **Inbetriebnahmedatum**
by `NegativpreisRegime::fuer_inbetriebnahme` — see [§ 51](#negativpreisregel).

Bestandsschutz follows § 100 EEG (§ 100 Abs. 1 Satz 4 EEG 2017, § 100 Abs. 2
Nr. 13 EEG 2021, § 100 Abs. 1 EEG 2023).

For a plant under a specific § 100 provision, supply
`tariff_source = Transitional(rule)`; `SettleInput::effective_eeg_gesetz()` and
`SettleInput::negativpreis_regime()` then derive both from the rule rather than
from the plant record:

| `Paragraph100Rule` | Effective regime | Source |
|---|---|---|
| `Pre2016Bestandsschutz` | § 51 never applies | § 100 Abs. 1 Satz 4 EEG 2017 |
| `Eeg2017Negativpreis6h` | ≥ 6 h, 3 MW/500 kW | § 100 Abs. 2 Nr. 13 EEG 2021 |
| `BiomassOldFuelClassContinuation` | EEG 2017 — old §§ 42–44 fuel rules | § 100 Abs. 6 EEG 2023 |
| `SmallBiomassBelow150kw` | EEG 2017 — small biomass FiT | § 100 Abs. 11 EEG 2023 |
| `OldPlantBeforeEeg2023` | ≥ 4 h, 500 kW (all types) | § 100 Abs. 1 EEG 2023 |
| any other | the plant's own commissioning date | — |

### § 53 Vergütungsabzug and the rate table

The Einspeisevergütung deducts a flat amount from the gross anzulegender Wert
(AW): **−0,4 ct/kWh** for solar and wind, **−0,2 ct/kWh** for biomass, hydro and
the gases. `verguetungssatz_ct` always stores the **net** rate
(`eeg_billing::rates::sect53_deduction(ErzeugungsArt)`). § 53 does not apply to
Direktvermarktung, `POST_EEG_SPOT` or KWKG. There is no additive
Managementprämie: marketing costs are folded into the AW.

`eeg_verguetungssaetze` is generated from the Startwerte as enacted, stepped
down by each statute's Absenkung, and stored net:

| Erzeugungsart | § EEG 2023 | Shape |
|---|---|---|
| Wasserkraft | § 40 Abs. 1 | seven tiers, 12,03 → 3,37 ct |
| Deponie-, Klär-, Grubengas | § 41 Abs. 1 / 2 / 3 | one ladder each |
| Biomasse | § 42 Satz 1 | 12,67 ct ≤ 150 kW; above that, tender |
| Bioabfall- / Güllevergärung | § 43 / § 44 | separate, higher claims |
| Geothermie | § 45 Abs. 1 | flat 25,20 ct |
| Solar | § 48 | in the version § 101 Abs. 1 Satz 2 keeps in force |

There is no wind-onshore row: § 22 Abs. 2 makes the claim depend on a BNetzA
Zuschlag and § 36h derives the value from it, so an awarded value is imported
per plant. `eeg_billing::seed::verguetungssatz_rows()` projects
`eeg_billing::rates` into the seed and `tests/it/verguetungssaetze_seed_guard.rs`
compares the migration row for row.

---

## Generator types and settlement models

| `erzeugungsart` | Technology | Legal basis |
|---|---|---|
| `SOLAR_AUFDACH` | On a Gebäude or Lärmschutzwand (zweites Segment, § 3 Nr. 41b) | § 48 Abs. 2 / 2a EEG 2023 |
| `SOLAR_FREIFLAECHE` | Freiflächenanlage (erstes Segment, § 3 Nr. 41a) | § 48 Abs. 1 / 1a EEG 2023 |
| `SOLAR_AGRIPV` | Agri-PV, a besondere Solaranlage | § 48 Abs. 1 S. 1 Nr. 5 lit. a + Abs. 1b EEG 2023 |
| `SOLAR_MIETERSTROM` | Building community solar | § 21 Abs. 3 + § 48a EEG 2023 |
| `SOLAR_STECKER` | Steckersolargerät ≤ 2 kW and ≤ 800 VA | § 8 Abs. 5a EEG 2023 |
| `WIND_ONSHORE` | Wind an Land | § 46 (AW) · § 36 (Gebote) EEG 2023 |
| `WIND_OFFSHORE` | Wind auf See | Windenergie-auf-See-Gesetz (§ 22 Abs. 1) |
| `BIOMASSE` / `BIOMASSE_HOLZ` | Solid biomass | § 42 EEG 2023 |
| `BIOGAS` / `BIOMETHAN` | Fermentation / upgraded gas | § 42 (Biomethan excluded by Satz 2) · § 43 · § 44 |
| `KLAERGAS` / `GRUBENGAS` / `DEPONIEGAS` | Sewage / mine / landfill gas | § 41 Abs. 2 / 3 / 1 EEG 2023 |
| `WASSERKRAFT` / `GEZEITEN` | Hydro, tidal (§ 3 Nr. 21 lit. a) | § 40 EEG 2023 |
| `GEOTHERMIE` | Geothermal | § 45 EEG 2023 |
| `KWKG` | Combined heat & power | § 7 KWKG |

There is no generic `SOLAR`: the § 48 rate depends on the Bauform. Every plant
also carries a `verguetungsform` (`UEBERSCHUSS` · `VOLLEINSPEISUNG` ·
`KWK_ZUSCHLAG`) — Überschuss and Volleinspeisung differ by the § 48 Abs. 2a
bonus (8,11 vs 12,87 ct/kWh net for a ≤ 10 kWp roof plant in the 1 February
2024 window).

One token per model in `eeg_anlagen.settlement_model` and on every receipt; the
schema `CHECK` and `einsd::models::ALL` are pinned equal by
`tests/it/schema_code_guard.rs`.

| `settlement_model` | Regulation | Formula | CloudEvent |
|---|---|---|---|
| `VERGUETUNG` | § 21 Abs. 1 EEG 2023 | `kwh × verguetungssatz_ct / 100` | `de.mako.eeg.verguetung.berechnet` |
| `AUSFALLVERGUETUNG` | § 21 Abs. 1 Satz 1 Nr. 3 | same, reduced 20 % (§ 53 Abs. 3) | `de.mako.eeg.verguetung.berechnet` |
| `UNENTGELTLICHE_ABNAHME` | § 21 Abs. 1 Satz 1 Nr. 2 | EUR 0 — the claim „verringert sich … auf null“ | `de.mako.eeg.verguetung.berechnet` |
| `MIETERSTROM` | § 21 Abs. 3 | `kwh × (verguetung + mieter_zuschlag) / 100` | `de.mako.eeg.verguetung.berechnet` |
| `GGV` | § 42b EnWG | § 21 rate on the grid feed-in at the GGV MaLo | `de.mako.eeg.verguetung.berechnet` |
| `DIREKTVERMARKTUNG` | § 20 | Anlage 1 gleitende Marktprämie | `de.mako.eeg.marktpraemie.berechnet` |
| `AUSSCHREIBUNG` | § 22 | the same, AW from the BNetzA tender | `de.mako.eeg.marktpraemie.berechnet` |
| `SONSTIGE_DIREKTVERMARKTUNG` | § 21a | EUR 0 | — |
| `POST_EEG_SPOT` | after the Förderdauer | `kwh × Marktwert_ct / 100` (configurable floor) | `de.mako.eeg.verguetung.berechnet` |
| `EIGENVERBRAUCH` | no grid feed-in | EUR 0 | — |
| `KWKG_ZUSCHLAG` | § 7 KWKG | `eligible_kwh × rate / 100`, hour-capped | `de.mako.eeg.verguetung.berechnet` |
| `FLEXIBILITAET` | § 50b | `kwh × (verguetung + flex_praemie) / 100` | `de.mako.eeg.verguetung.berechnet` |
| `FLEXIBILITAET_ZUSCHLAG` | § 50a | `kw × rate_eur_per_kw / 12` | `de.mako.eeg.verguetung.berechnet` |

Every result carries `positions` with `Σ positions[*].eur = settlement_eur`;
rounding follows
[Quantities and money on the wire](https://hupe1980.github.io/mako/docs/architecture/domain-model/#quantities-and-money-on-the-wire).

### Anlage 1 — die gleitende Marktprämie

```
Marktprämie = max(0, AW − MW) × kwh / 100
```

**The Marktwert series is the plant's vintage.** Anlage 1 Nr. 2 sends plants
commissioned **or bezuschlagt** before 01.01.2023 to the
energieträgerspezifische **Monatsmarktwert** (Nr. 3) and newer ones to the
**Jahresmarktwert** (Nr. 4);

Satz 3 moves a Satz-1 plant onto the Jahresmarktwert once it claims under the §
19 Abs. 3b/3c Abgrenzungs- or Pauschaloption (`speicher_option`). A 2024 plant
on a 2022 award stays on the Monatsmarktwert. A settlement without an
Inbetriebnahme is refused.

**A `PAUSCHAL` plant is refused (`422`).** MiSpeL (BNetzA, Az. 618-25-02) Tz. 9 b)
applies the Pauschaloption „frühestens für Netzeinspeisung ab dem ersten
Kalendertag des Kalendermonats …, der auf die beihilferechtliche Genehmigung der
Europäischen Kommission zu § 19 Abs. 3c EEG … folgt". No approval exists.
`ABGRENZUNG` is unaffected.

`marktwert_preise` holds both series (`art`). A Wind an Land, Wind auf See or
Solar plant reads only its Energieträger's row — `WIND_ONSHORE`, `WIND_OFFSHORE`,
`SOLAR` (one figure for every Bauform; a `SOLAR_*` key is refused) — because
Anlage 1 Nr. 3.3 and 4.3 EEG 2023 make its Marktwert the generation-weighted
value, not the spot mean. A Nr. 3.2 / 4.2 plant (Wasserkraft, Gase, Biomasse,
Geothermie) reads its technology row → `DEFAULT` → for the Monatsmarktwert only,
the EPEX monthly average. Otherwise the period is `price_missing`, retried by
the monthly worker; one series never substitutes for the other.

A Jahresmarktwert may be `vorlaeufig`; the receipt records it, and `GET
/api/v1/marktwert/{year}/nachbewertung` lists the months to recompute through
the [correction](#corrections) once the binding figure is published.

```http
PUT /api/v1/marktwert/2026/monat/SOLAR
{ "billing_month": 6, "avg_ct_kwh": "3.1400", "source": "netztransparenz.de" }

PUT /api/v1/marktwert/2026/jahr/SOLAR
{ "avg_ct_kwh": "4.8100", "vorlaeufig": true, "source": "netztransparenz.de" }
```

When the Marktwert exceeds the AW the premium is zero. `AUSSCHREIBUNG` is the
same formula with `TariffSource::Auction`; award validity, reductions and
revocation are resolved before the library sees the AW.

### KWKG

§ 7 Abs. 1 Satz 1 prices the KWK-Zuschlag **per Leistungsanteil**:
`eeg_billing::kwkg::zuschlag_ct_kwh` blends the bands the KWK-Leistung spans and
`zuschlag_leistungsanteile` itemises them.

| Leistungsanteil | Rate | Nummer |
|---|---|---|
| ≤ 50 kW | 8,0 ct/kWh | Nr. 1 |
| > 50 – 100 kW | 6,0 ct/kWh | Nr. 2 |
| > 100 – 250 kW | 5,0 ct/kWh | Nr. 3 |
| > 250 kW – 2 MW | 4,4 ct/kWh | Nr. 4 |
| > 2 MW | 3,4 (neu / modernisiert) · 3,1 (nachgerüstet) ct/kWh | Nr. 5 lit. a–c |

A 2 MW new plant is `(50×8 + 50×6 + 150×5 + 1750×4,4) / 2000` = **4,575
ct/kWh**. § 7 Abs. 1 Satz 2 adds 0,5 ct on Nr. 5 lit. a for plants in
Dauerbetrieb from 01.01.2023 (§ 35 Abs. 18), only once the BMWK Feststellung is
published (`kwk_bmwk_feststellung`).

§ 7 Abs. 2 has lower ladders for KWK-Strom not fed into a Netz der allgemeinen
Versorgung (`kwk_verwendung`: `NETZ_DER_ALLGEMEINEN_VERSORGUNG` and four
`NICHT_EINGESPEIST_*` values). § 7 Abs. 3a replaces the ladder with a flat 16 ct
(eingespeist) or 8 ct for a new plant up to 50 kW.

**Förderdauer in Vollbenutzungsstunden (§ 8):**

| Anlagenart | Condition | Vollbenutzungsstunden |
|---|---|---|
| neu (Abs. 1) | — | 30 000 |
| modernisiert (Abs. 2 Nr. 1) | ≥ 10 % Kostenanteil, 2 Jahre Karenz, Dampfsammelschiene > 50 MW | 6 000 |
| modernisiert (Abs. 2 Nr. 2) | ≥ 25 %, 5 Jahre Karenz | 15 000 |
| modernisiert (Abs. 2 Nr. 3) | ≥ 50 %, 10 Jahre Karenz | 30 000 |
| nachgerüstet (Abs. 3 Nr. 1) | ≥ 10 % und < 25 % | 10 000 |
| nachgerüstet (Abs. 3 Nr. 2) | ≥ 25 % und < 50 % | 15 000 |
| nachgerüstet (Abs. 3 Nr. 3) | ≥ 50 % | 30 000 |

A Modernisierung meeting no Nummer has none (`foerderdauer_vollbenutzungsstunden`
→ `None`). § 8 Abs. 4 caps each calendar year: 5 000 h in 2021/22, 4 000 h in
2023/24, 3 500 h in 2025, 3 300 h in 2026, then 3 100 · 2 900 · 2 700 and 2 500 h
from 2030. Exhausting the year's cap is `jahreskontingent_erschoepft`, not the
end of the Förderung.

---

## Beihilfevorbehalt from 01.01.2027

The Commission's state-aid approval of the EEG 2023 „bis zum 31. Dezember 2026
befristet ist" (BT-Drs. 21/7867, Begründung zu § 104 EEG 2027); the decision
itself — C(2022) 9900 final, SA.102084, recital (211) — has the measures apply
„between 1 January 2023 and 31 December 2026". The Entwurf's § 104 Abs. 1 lets
the Bestimmungen des Teils 3 „erst nach der beihilferechtlichen Genehmigung
durch die Europäische Kommission und nur nach Maßgabe dieser Genehmigung" be
applied; Abs. 2 has the BMWE announce it in the Bundesanzeiger. Every EEG
payment for a supply period from **01.01.2027** — including a Marktprämie for
an existing plant — therefore has no approval behind it until one is recorded.
KWKG plants are outside it.

The gate answers each supply period with one of four states
(`eeg_billing::Beihilfevorbehalt`), keyed on the period, not the invoice date:

| State | When | Fassung of the period |
|---|---|---|
| `Eeg2023Genehmigt` | supply period up to 31.12.2026 | EEG 2023 |
| `Eeg2023Verlaengert` | a recorded `regelung = "eeg2023_verlaengerung"` covers it | EEG 2023, to the extension's `gilt_bis` |
| `Eeg2027Genehmigt` | a recorded `regelung = "eeg2027"` covers it | none tabled |
| `Offen` | nothing covers it, the period is unknown, or records of both schemes claim it | none — `[policy] beihilfe_politik` decides |

No extension of the EEG 2023 approval is published. A recorded one settles
the periods it covers under the EEG 2023 rather than a statute not in force.

### `[policy] sect21c_ohne_zuordnung` {#policy-sect21c-ohne-zuordnung}

A plant registered without a `settlement_model` has its Veräußerungsform
decided by this reading. § 21c Abs. 1 Satz 3 EEG 2023 deems a plant below
200 kW „für die der Anlagenbetreiber keine andere Zuordnung getroffen hat"
assigned to the unentgeltliche Abnahme, whose claim „verringert sich … auf
null" (§ 21 Abs. 1 Satz 1 Nr. 2); whether a commissioning notice already is the
Zuordnung to the Einspeisevergütung is the Netzbetreiber's reading.

| `sect21c_ohne_zuordnung` | Effect |
|---|---|
| `angabe_verlangen` (default) | Refused with `422` and code `veraeusserungsform_missing`; nothing is paid on a guess |
| `einspeiseverguetung` | Registered as `VERGUETUNG` (§ 21c Abs. 1 Satz 5) |
| `unentgeltliche_abnahme` | Below 200 kW registered as `UNENTGELTLICHE_ABNAHME` and settled at 0 ct; from 200 kW refused like `angabe_verlangen` |

A registration that names its `settlement_model` is never touched by this
setting.

### `[policy] beihilfe_politik` {#policy-beihilfe-politik}

What einsd does with an uncovered payment is the operator's reading; none of
the three is a legal outcome mako asserts. Each option rests on the same
source (BT-Drs. 21/7867 S. 248, Zu § 104).

| `beihilfe_politik` | Effect |
|---|---|
| `verweigern` (default) | Refused with `422` naming the reservation and the setting; no receipt is written and the sweep retries the month |
| `unter_vorbehalt` | Settled and paid; the receipt and the Gutschrift carry a zero-euro position stating the reservation |
| `halten` | Stored with status `gehalten`, no Gutschrift number, no payout CloudEvent; the auto-settle worker re-settles and pays every held month once a recorded approval covers it |

A receipt paid under reservation or held carries `policy_json` — the
`{key, value, quelle}` of the reading — and the settlement result returns it
as `policy`. The batch endpoint counts held plants under `gehalten`. The
setting changes only by editing `einsd.toml` and restarting;
`[beihilfevorbehalt] politik` is refused at startup, naming this one.

A recorded approval opens the supply periods it covers under every policy. It
names its scheme — the two are never read for each other, because each selects
a different statute for the same month:

```toml
[policy]
beihilfe_politik = "verweigern"

[[beihilfevorbehalt.genehmigungen]]
regelung       = "eeg2027"    # or "eeg2023_verlaengerung"
eingang        = "2027-…"     # Eingang bei der Bundesregierung
gilt_ab        = "2027-01-01"
# gilt_bis     = "…"           # when the decision is limited; required for an extension
bundesanzeiger = "BAnz AT …"  # for an extension without a notice: SA number and „C(…) final"
```

einsd refuses to start on an extension without `gilt_bis`, a `gilt_bis` before
`gilt_ab`, or an extension and an EEG 2027 approval covering the same day.

**Reductions follow the Fassung of the payment period.** §§ 53b–54 reduce the AW
under the EEG Fassung of the supply period (`eeg_billing::Fassung::fuer_periode`),
not the plant's vintage — the EEG 2027 Entwurf renumbers the § 53c Stromsteuer
reduction as § 53b. Only the EEG 2023 is tabled: for supply periods 01.01.2023
to 31.12.2026, and beyond that to the end of a recorded extension of its
approval, where a reduction is labelled „§53c EEG 2023". A period
outside it with a recorded reduction — including one an EEG 2027 approval
opens — settles as `fassung_nicht_tabelliert`: nothing paid, retried by the
sweep.

**A plant keeps the Fassung of its commissioning.** A plant commissioned on or
before 31.12.2026 settles every later period under its own Fassung. For one
commissioned later no Fassung is tabled — the EEG 2027 (BT-Drs. 21/7867) is not
verkündet — so its settlement is `fassung_nicht_tabelliert` too, even under a
recorded Genehmigung, rather than computed on EEG 2023 arithmetic.

---

## Plant lifecycle

```mermaid
stateDiagram-v2
    [*] --> aktiv : POST /anlagen
    aktiv --> aktiv : POST /repowering
    aktiv --> foerderung_beendet : KWKG lifetime cap (§ 8 Abs. 1–3) or lapsed Zuschlag
    aktiv --> abgemeldet : DELETE /anlagen · § 24 Zusammenlegung
```

| Status | Meaning |
|---|---|
| `aktiv` | Registered and settling — also while MaStR is missing (§ 52 EEG 2023 charges alongside) and past an EEG Förderende |
| `foerderung_beendet` | § 8 KWKG lifetime hours used up, or an Ausschreibungs-Zuschlag lapsed (§§ 36e / 37e / 39e EEG 2023) |
| `abgemeldet` | Decommissioned, or merged into a parent under § 24 |

A KWK plant whose **annual** contingent runs out stays `aktiv`; its receipts
carry `jahreskontingent_erschoepft` until January. A correction that removes kWh
can move a `foerderung_beendet` KWK plant back to `aktiv`.

`settlement_state` tracks the billing position, and
`settlement_state_transitions` logs each change with its reason
(`MastrRegistered`, `Sect52ViolationDetected`, `FoerderungExpired`, …):

| `settlement_state` | Meaning |
|---|---|
| `active` | Full Vergütung |
| `reduced` | § 52 EEG 2023 Pflichtzahlung running; Vergütung unchanged |
| `suspended` | § 52 EEG ≤ 2021 `VerguetungAufNull` |
| `interrupted` | No meter data or price |
| `post_eeg` | Förderdauer over (EEG only) |
| `ended` | Decommissioned |

### Registering a plant

Register the Anlagenbetreiber first, then the plant; confirm MaStR when it is
done.

```http
POST /api/v1/anlagen
Content-Type: application/json

{
  "tr_id":              "DE0123456789012345678901234567890",
  "malo_id":            "51238696012",
  "eeg_gesetz":         2023,
  "inbetriebnahme":     "2024-06-01",
  "leistung_kwp":       "9.8",
  "erzeugungsart":      "SOLAR_AUFDACH",
  "verguetungssatz_ct": "8.11",
  "settlement_model":   "VERGUETUNG",
  "mastr_registriert":  true,
  "mastr_nummer":       "SEE900000012345",
  "einspeiser_id":      "EB-4711"
}
```

`verguetungssatz_ct` is net: for a ≤ 10 kWp roof plant in the 1 February 2024
window, 8,60 ct × 0,99 = 8,51 ct gross AW − 0,4 ct = **8,11 ct**.
`POST /api/v1/verguetungssatz-lookup` returns the gross AW.

`foerderendedatum` is derived for an **EEG** plant: 31 December of year + 20 for
statutory plants (§ 25 Abs. 1 Satz 2 EEG; 2024-06-01 → `2044-12-31`), the exact
anniversary for an Ausschreibungsanlage (`ausschreibungs_zuschlag_id` set;
`2044-06-01`). A **KWKG plant has none** — `foerderendedatum` is `NULL`; it ends
on `kwk_foerderdauer_h`, given directly or derived from `kwk_anlagenart` (+
`kwk_kostenanteil`). Every reader must handle `NULL`.

```http
POST /api/v1/anlagen/{tr_id}/mastr-registrierung
{ "mastr_nummer": "SEE900000012345", "mastr_datum": "2024-06-15" }
```

This clears the § 52 Abs. 1 Nr. 11 clock and emits
`de.mako.eeg.anlage.mastr-registriert`.

**Validation** (`validate::check`) refuses, naming the field:

| Rejected | Why |
|---|---|
| `DIREKTVERMARKTUNG` without a positive `direktverm_aw_ct` | Every month would settle to EUR 0 as `calculated` |
| `AUSSCHREIBUNG` without an AW or `ausschreibungs_zuschlag_id` | The same, and an award value without an award cannot be audited |
| `leistung_kwp ≤ 0` | It drives the § 9 band, the § 52 charge, the § 44b quota and the § 51 size test |
| `MIETERSTROM` without `mieter_zuschlag_ct` | It would settle as plain Einspeisevergütung |
| `KWKG_ZUSCHLAG` with neither `kwk_foerderdauer_h` nor `kwk_anlagenart` (a `MODERNISIERT`/`NACHGERUESTET` plant also needs `kwk_kostenanteil`) | The Zuschlag would never end |
| Both `kwk_bimschg_genehmigung` and `kwk_verbindliche_bestellung` | § 6 Abs. 1 Satz 1 Nr. 1 lit. c bb KWKG applies only where no BImSchG-Genehmigung is required |
| Technology and statute disagreeing | A KWK plant with `eeg_gesetz ≠ 0`, an EEG plant with `0`, solar on the KWKG model, a `verguetungsform` of the other statute |

A KWKG plant is settled only on a § 6 Abs. 1 Satz 1 Nr. 1 KWKG claim:
Dauerbetrieb (`inbetriebnahme`) by 31.12.2026 (lit. a); later, a KWKAusV award
in `ausschreibungs_zuschlag_id` (lit. b), or a `kwk_bimschg_genehmigung` /
`kwk_verbindliche_bestellung` dated by 31.12.2026 with Dauerbetrieb by the end
of the fourth year after it (lit. c). Anything else is refused by name until a
Novelle of the KWKG is promulgated.

A tender plant may carry its AW in either column; `zuschlagswert_ct` wins. The
engine independently treats a Marktprämie without an AW as `PriceMissing`.

### Einspeiser (Anlagenbetreiber)

`einspeiser`, keyed by an operator-assigned `einspeiser_id`, is a party record,
not a Vertrag — § 7 Abs. 1 EEG 2023 („Gesetzliches Schuldverhältnis") forbids
making the NB's obligations conditional on one. `eeg_anlagen.einspeiser_id` is
mandatory.

| Field | Meaning |
|---|---|
| `ust_status` | `KLEINUNTERNEHMER` (§ 19 UStG → 0 %, EN 16931 category `E`) or `REGELBESTEUERUNG` (19 %, `S`; default) |
| `bank_iban` / `bank_bic` / `zahlungsempfaenger` | Payout account, forwarded in the settlement event for accountingd's pain.001 |
| `zahlungsempfaenger_anschrift` | The payee's postal address, the pain.001's `Cdtr/PstlAdr`: `town`, `country` (ISO 3166-1 alpha-2), `street`, `building_number`, `post_code`, `country_subdivision`. Given, town and country are required and the address replaces the stored one whole; omitted keeps it |
| `mastr_akteur_id` | MaStR Marktakteursnummer (`SEE…`/`ABR…`) |

```http
PUT /api/v1/einspeiser/EB-4711
Content-Type: application/json

{
  "name":               "Max Mustermann",
  "mastr_akteur_id":    "ABR900000012345",
  "ust_status":         "KLEINUNTERNEHMER",
  "bank_iban":          "DE89370400440532013000",
  "bank_bic":           "COBADEFFXXX",
  "zahlungsempfaenger": "Max Mustermann",
  "zahlungsempfaenger_anschrift": {
    "street":          "Sonnenweg",
    "building_number": "7",
    "post_code":       "80331",
    "town":            "München",
    "country":         "DE"
  }
}
```

An address is checked by the `sepa` crate's `PstlAdr` rules — the ones the
pain.001 applies — before anything is stored: without town or country it is
refused `422 incomplete_postal_address`, with a country that is not an ISO
3166-1 alpha-2 country `422 invalid_country_code`. The country is stored
upper-cased and blank parts as absent.

An unknown `ust_status` aborts the settlement. § 12 Abs. 3 UStG (0 % on PV
hardware) is not a feed-in category.

---

## § 9 / § 52 — Steuerbarkeit und Pflichtzahlungen

§ 52 Abs. 1 lists **thirteen** Pflichtverstöße (Nr. 1–12 plus Nr. 9a). Each
charges 10 €/kW per calendar month (Abs. 2), some drop to 2 € (Abs. 3), four run
past the breach (Abs. 4), the total is capped at 10 €/kW per month (Abs. 5), and
the claim may be netted against the Vergütung (Abs. 6).
`sect52::derive_pflichtverstoesse` merges two sources:

| `SanktionsTyp` | Nr. | Rate | Abs. 3 cure → 2 € | Source |
|---|---|---|---|---|
| `FernsteuerbarkeitFehlend` | 1 | 10 € | yes | derived — routes × capacity × Veräußerungsform |
| `SpeicherAnforderungNichtErfuellt` | 2 | 10 € | no | recorded |
| `IMssAnforderungNichtErfuellt` | 3 | 10 € | yes | recorded |
| `Sect10bVorgabenVerletzt` | 4 | 10 € | yes | recorded |
| `AusfallverguetungHoechstdauerUeberschritten` | 5 | 10 € | no | derived — from receipts |
| `EinspeiseverguetungUnzulaessigeNutzung` | 6 | 10 € | no | recorded |
| `VeraeusserungsformWechselUngueltig` | 7 | 10 € | no | recorded |
| `VeraeusserungsformNachweispflichtVerletzt` | 8 | 10 € | no | recorded |
| `ZuordnungsWechselNichtGemeldet` | 9 | 10 € | no | derived — `veraeusserungsform_notification_sent_at` |
| `InbetriebnahmeVorgabeVerletzt` | 9a | **2 € always** | n/a | recorded |
| `VolleinspeisungspflichtVerletzt` | 10 | **2 € always** | n/a | recorded |
| `MastrNichtRegistriert` | 11 | 10 € | yes | derived — `mastr_registriert`, clock `mastr_violation_start` |
| `DoppelvermarktungsverbotVerletzt` | 12 | 10 € | no | recorded |

The recorded ones are findings (a site visit, a § 10b Nachweis), filed in the
register:

```http
POST /api/v1/anlagen/{tr_id}/pflichtverstoesse
{ "typ": "I_MSS_ANFORDERUNG_NICHT_ERFUELLT", "beginn": "2026-01-01",
  "technischer_defekt": false, "notiz": "Vor-Ort-Prüfung 12.01.2026" }

PUT  /api/v1/anlagen/{tr_id}/pflichtverstoesse/I_MSS_ANFORDERUNG_NICHT_ERFUELLT/behoben
{ "behoben_am": "2026-06-20" }
```

`409` when one of that Nummer is already open; an unknown `typ` is `400` listing
the vocabulary (`SanktionsTyp::ALL`, pinned to the SQL `CHECK`).

| Field | Effect |
|---|---|
| `beginn` | § 52 Abs. 2 charges every month „in dem ganz oder zeitweise ein Pflichtverstoß … vorliegt"; without it, one month |
| `behoben_am` | § 52 Abs. 3 Satz 1 Nr. 1 drops the rate to 2 €/kW „zurück bis zum Beginn" — Nr. 1, 3, 4 and 11 only |
| `technischer_defekt` | § 52 Abs. 3 Satz 2 waives the defect month and the next for Nr. 1/3/4/8 (breaches after 31.12.2023); the burden of proof is the operator's |

A cure makes months already settled at 10 € an overcharge — correct them (the
response says so). A record never creates a breach for Nr. 1, 5, 9 or 11, where
the plant record decides; a § 10b record against a plant on the
Einspeisevergütung charges nothing (§ 10b Abs. 1 binds a direct-marketing plant
over 25 kW).

**§ 52 Abs. 4**, applied by `SanktionsTyp::abs4_monate`: Nr. 7 + 3 months, Nr. 9
+ 1 month, Nr. 10 the whole calendar year (a replacement), Nr. 12 + 6 months.
Nr. 5 is not named and gets nothing.

**At settlement** `run_settlement` re-reads the register in its own transaction;
`monate_des_verstosses` counts inclusive months from `beginn` to the earlier of
the billing month and `behoben_am`, plus the Abs. 4 tail. `mastr_violation_start`
is set to `heute()` (Europe/Berlin) when a plant registers unconfirmed and
cleared on MaStR confirmation.

**One month, one increment.** The receipt's `pflichtzahlung_eur` is the running
claim since the breach began; `eeg_sect52_monate` records what each month adds
to the last settled month's claim (`monat_eur` — negative where an Abs. 3 cure
reduces it, owed back), so a re-settle reaches the same increment and no month
is charged twice. The settlement result and the CloudEvent carry it as
`sect52 { anspruch_kumuliert_eur, monat_eur, aufgerechnet_eur, rest_eur }`.

### `[policy] sect52_aufrechnung` {#policy-sect52-aufrechnung}

§ 52 Abs. 6 Satz 2 EEG 2023 permits setting the claim off against the plant's
§ 19 Abs. 1 claim („können … aufgerechnet werden"); § 27 Abs. 1 Satz 1 bars it
otherwise. The election is the Netzbetreiber's:

| `sect52_aufrechnung` | Effect |
|---|---|
| `gesondert` (default) | The Vergütung is paid whole; the month's increment is `rest_eur`, a separate claim due on the 15th of the following month (Abs. 6 Satz 1) |
| `aufrechnen` | The increment is set off against the month's Marktprämie, Einspeisevergütung or Mieterstromzuschlag (`aufgerechnet_eur`; not `GGV`, `KWKG_ZUSCHLAG` or the § 50 claims), stopping at the claim; the rest stays `rest_eur` |

`settlement_eur` and the Gutschrift always state the whole § 19 Abs. 1 claim.
accountingd records `aufgerechnet_eur` as an `EEG_52_PFLICHTZAHLUNG`
Aufrechnung on the receipt chain and pays the remainder.

**EEG ≤ 2021 plants** (via § 100) use `SanktionAlt` — the breach cuts the
Vergütung, no separate Pflichtzahlung: `VerguetungAufNull` (Abs. 1 — EUR 0),
`VerguetungAufMarktwert` (Abs. 2 — the Monatsmarktwert),
`VerguetungReduziert20Prozent` (Abs. 3 — × 0,80).

### § 9 is staged by capacity and Veräußerungsform

| Installed capacity | Ferngesteuerte Reduzierung | 60 % Wirkleistungsbegrenzung | Basis |
|---|---|---|---|
| Steckersolargerät ≤ 2 kW **und** ≤ 800 VA | – | – | § 9 Abs. 2 Satz 4 |
| < 25 kW | – | geförderte Anlagen and KWK-Anlagen | § 9 Abs. 2 Satz 1 Nr. 3 |
| 25 kW – < 100 kW | ja | geförderte Anlagen | § 9 Abs. 2 Satz 1 Nr. 2 lit. a **und** lit. b |
| ≥ 100 kW | ja | – | § 9 Abs. 2 Satz 1 Nr. 1 |

„Geförderte Anlagen" are those „der Einspeisevergütung oder dem
Mieterstromzuschlag nach § 19 Absatz 1 Nummer 2 oder Nummer 3 zugeordnet".
Record both routes — `{ "sect9_fernsteuerbarkeit": true, "sect9_begrenzung_60": true }`
— and `wechselrichterleistung_va` for the Steckersolar carve-out (unset keeps it
shut). Missing a required route is a § 52 Abs. 1 Nr. 1 breach; carrying more is
never one.

---

## § 51 — Negativpreisregel {#negativpreisregel}

During negative EPEX periods the AW falls to zero. The version is keyed on the
**Inbetriebnahmedatum** (Solarspitzengesetz, in force 25 February 2025):

| Inbetriebnahme | Trigger | Exemption | § 51a extension |
|---|---|---|---|
| ≤ 2015-12-31 | never (§ 100 Abs. 1 Satz 4 EEG 2017) | — | — |
| 2016-01-01 – 2020-12-31 | ≥ **6** consecutive hours | Wind < 3 MW · other < 500 kW | none |
| 2021-01-01 – 2022-12-31 | ≥ **4** consecutive hours | < 500 kW | ausschreibungspflichtige only |
| 2023-01-01 – 2025-02-24 | staged **4-3-2-1 h** (4 h for IBN 2023, 3 h from IBN 2024) | < **400 kW** | ausschreibungspflichtige only |
| ≥ 2025-02-25 | first negative quarter-hour | < 100 kW until iMSys · < 2 kW until the § 85 Abs. 2 Nr. 12 Festlegung | all plants |

Pilotwindenergieanlagen (§ 3 Nr. 37 EEG 2023) are exempt under every version
(`ist_pilotwindanlage: true`).

**§ 100 opt-in.** An older plant may declare in Textform that §§ 51 and 51a apply;
it runs at the earliest from the end of the calendar year in which the plant got
an iMSys, and from then the plant is paid 0,6 ct/kWh more on its AW outside
negative prices. Record `sect51_optin_erklaert_am` and `imesys_rollout_datum`;
einsd picks the regime per period. § 100 Abs. 47 EEG 2023 is reserved by § 101
Abs. 1 Satz 1 until „der beihilferechtlichen Genehmigung durch die Europäische
Kommission" (Arbeitsausgabe 23.12.2025, p. 218), and no approval date is
recorded (`eeg_billing::SECT100_ABS47_GENEHMIGT_AB` is `None`): until it is, an
effective declaration earns no uplift and the plant keeps its own Fassung's
negative-price rule.

**Inputs.** The settle request may carry `kwh_during_negative_epex` (§ 51) and
`negative_price_quarter_hours` (§ 51a):

```http
POST /api/v1/anlagen/{tr_id}/settle/2026/7
Content-Type: application/json

{ "einspeisemenge_kwh": "1000", "kwh_during_negative_epex": "80", "negative_price_quarter_hours": 16 }
```

Result: `effective_kwh = 920`. **Or omit both**: einsd overlays the plant's ¼h
feed-in from edmd on the stored day-ahead prices for the Europe/Berlin billing
month and applies the regime in `eeg-billing::negativpreis`.

```http
PUT /api/v1/epex-spot
Content-Type: application/json

{ "source": "epex-day-ahead",
  "prices": [ { "delivery_start": "2026-07-01T12:00:00Z", "resolution_min": 15, "price_ct_kwh": "-1.5" }, … ] }
```

The derivation is skipped (and logged) when edmd reports coverage below 95 % or
any non-billable interval — § 40a Abs. 2 EnWG Satz 3 permits no undisclosed
estimate; supply the figure or backfill edmd. A month with no qualifying
quarter-hour derives as zero, recorded as such. Explicit request values win.
`edmd_api_key` must be registered in edmd's `[[oidc.service_keys]]`.

Applies to `VERGUETUNG`, `AUSFALLVERGUETUNG`, `MIETERSTROM`, `GGV`,
`DIREKTVERMARKTUNG`, `AUSSCHREIBUNG`, `FLEXIBILITAET`; not to `POST_EEG_SPOT`,
`KWKG_ZUSCHLAG`, `EIGENVERBRAUCH`, `SONSTIGE_DIREKTVERMARKTUNG`,
`FLEXIBILITAET_ZUSCHLAG`.

**§ 51a — Verlängerung.** einsd accrues the raw lost quarter-hours
(`negative_price_qh_gesamt`) and rounds **once over the total**: solar × 0,5
into Volllastviertelstunden drawn against the § 51a Abs. 2 monthly table (73 in
December, 508 in June); others rounded up to whole days (96 QH/day, Abs. 1 Satz
2).

`foerderendedatum` stays statutory; `effektives_foerderende` derives the
extension. KWKG plants have none to extend. A correction without § 51 figures
leaves the period's accrual unchanged.

**§ 51 Abs. 3 — reporting duty on the Ausfallvergütung.** Where the quantity fed
in during continuously negative prices cannot be established, the claim falls
5 % per calendar day with such a period (20 days extinguish it). einsd counts the
days in Europe/Berlin from the EPEX store; a figure derived from edmd counts as
established. § 53 Abs. 3 cuts the AW first, then § 51 Abs. 3 the claim.

**§ 51b — biogas tender plants.** For a biogas (not biomethane)
Ausschreibungsanlage (`is_biogas_sect51b: true`), an EPEX average ≤ 2 ct/kWh sets
the AW to zero; §§ 51/51a do not apply (§ 51b Satz 2). § 51b applies only from
**18 September 2025** (§ 101 Abs. 2 Satz 1); `eeg_billing::version::sect51b_anwendbar`
keys on the supply period, and a period straddling that day must be billed as
two.

---

## Other settlement rules

### Ausfallvergütung (§ 21 Abs. 1 Satz 1 Nr. 3)

For a plant whose Direktvermarkter drops out: the AW is reduced **20 %** (§ 53
Abs. 3; register the ordinary rate), at most **three consecutive** and **six per
calendar year** months — exceeding either is § 52 Abs. 1 Nr. 5, counted from the
receipts, and the month is still paid.

### Direktvermarktungspflicht (§ 21 Abs. 1 Satz 1 Nr. 1)

The Einspeisevergütung mit gesetzlich bestimmtem AW exists only „für Strom aus
Anlagen mit einer installierten Leistung von bis zu 100 Kilowatt". A larger
plant on `VERGUETUNG` is **unpaid**, not penalised: it settles `kein_anspruch`
with a EUR 0 position, and `check_einspeiseverguetung_anspruch` lists such
plants.

It is not a § 52 Abs. 1 Nr. 4 case — that is a § 10b breach by a plant in
Direktvermarktung. Plants commissioned before 2016-01-01 fall under the EEG 2014
staging, which mako does not carry: `direktvermarktungspflicht` answers `None`,
the plant is paid, and the MCP tool lists it under `ungeklaert`.

### Ausschreibungspflicht (§ 22 Abs. 2–5)

Exempt „bis einschließlich":

| Technology | Exempt up to | Source |
|---|---|---|
| Solar, erstes Segment (§ 3 Nr. 41a) | 1 MW | § 22 Abs. 3 Satz 2 Nr. 1 |
| Solar, zweites Segment (§ 3 Nr. 41b) | 750 kW | § 22 Abs. 3 Satz 2 Nr. 1a |
| Wind an Land | 1 MW | § 22 Abs. 2 Satz 2 Nr. 1 |
| Biomasse | 150 kW (bestehende Anlagen nach § 39g always need a Zuschlag) | § 22 Abs. 4 Satz 2 |
| Wasserkraft, Deponie-, Klär-, Grubengas, Geothermie | any size | § 22 Abs. 5 Satz 2 |
| Wind auf See | nothing — WindSeeG | § 22 Abs. 1 |

`eeg_billing::direktverm::requires_ausschreibung` does not apply the
Pilotwind cohort (§ 22 Abs. 2 Satz 2 Nr. 2) or Bürgerenergiegesellschaften
(Wind ≤ 18 MW, Solar ≤ 6 MW, § 22b) — neither is a capacity test. Agri-PV is
erstes Segment and takes 1 MW.

### Veräußerungsformwechsel (§ 21b)

`POST /api/v1/anlagen/{tr_id}/switch-veraeusserungsform` accepts the four models
that name a Veräußerungsform (§ 21b Abs. 1 Satz 1): `VERGUETUNG`,
`AUSFALLVERGUETUNG`, `DIREKTVERMARKTUNG` (Nr. 1) and
`SONSTIGE_DIREKTVERMARKTUNG` (Nr. 4). `AUSSCHREIBUNG` is not one.
`eeg_billing::direktverm::validate_wechsel` decides; a refusal is `422` naming
the rule.

| Rule | Source |
|---|---|
| Effective only on the first of a month | § 21b Abs. 1 Satz 2 |
| Mitteilung before the preceding month begins — earliest the 1st of the month after next | § 21c Abs. 1 Satz 1 |
| Over 100 kW: no Einspeisevergütung mit gesetzlich bestimmtem Wert (the Ausfallvergütung stays open) | § 21 Abs. 1 Satz 1 Nr. 1 |
| No Ausfallvergütung within 24 months of an unentgeltliche Abnahme | § 21b Abs. 1 Satz 4 |

```http
POST /api/v1/anlagen/{tr_id}/switch-veraeusserungsform
Content-Type: application/json

{
  "new_model": "DIREKTVERMARKTUNG",
  "effective_date": "2026-08-01",
  "direktvermarkter_mp_id": "9910000000001",
  "direktverm_aw_ct": "6.28"
}
```

The § 21c Abs. 1 Satz 2 fünftletzter-Werktag variant is not applied. A success
updates `last_veraeusserungsform_switch` and emits
`de.mako.eeg.veraeusserungsform.gewechselt` in the same transaction.
`GET /api/v1/anlagen/by-malo/{malo_id}/veraeusserungsform` gives processd the
form in force as its `SG10 CCI+Z22` DE 7037 code, an `ausfallverguetung` flag
(`Z90` covers both the Einspeisevergütung and the Ausfallvergütung) and the `E_0623`
Prüfschritt 540 Direktvermarktungspflicht.

### §§ 53b–54 — reductions of the AW

These cut the **AW** before any formula runs: a deduction after the
`max(0, AW − Marktwert)` floor would drive a settlement negative. Each is
recorded as a zero-euro audit position. Only triggering facts are stored; every
amount but § 53c's is statutory.

| § | Trigger | Amount | Table |
|---|---|---|---|
| 53b | A Regionalnachweis (§ 79a) issued, **and** the AW is gesetzlich bestimmt | −0,1 ct/kWh | `eeg_regionalnachweise` |
| 53c | Grid-transited electricity exempt from Stromsteuer | −the granted exemption, capped at the § 3 StromStG rate 2,05 ct/kWh | `eeg_stromsteuerbefreiungen` |
| 54 | Solar erstes Segment tender: Zahlungsberechtigung after 18 months (Abs. 1), Flurstück mismatch (Abs. 2), missing Agri-PV Nutzungsnachweis (Abs. 3), § 37c Abs. 2 Landesverordnung breach (Abs. 4) | −0,3 / −0,3 / −2,5 ct/kWh; Abs. 4 AW → 0 | `eeg_sect54_solar_defekte` |

```http
POST /api/v1/anlagen/{tr_id}/aw-reduktionen/regionalnachweis
{ "nachweis_ref": "HKNR-RN-2026-0001", "effective_from": "2026-01-01" }

POST /api/v1/anlagen/{tr_id}/aw-reduktionen/stromsteuerbefreiung
{ "befreiung_ct_kwh": "2.05", "rechtsgrundlage": "§9 Abs. 1 Nr. 1 StromStG", "effective_from": "2026-01-01" }

POST /api/v1/anlagen/{tr_id}/aw-reduktionen/sect54-defekt
{ "zahlungsberechtigung_nach_18_monaten": true, "effective_from": "2026-01-01" }

POST /api/v1/anlagen/{tr_id}/aw-reduktionen/sect54-defekt/{id}/nachweis-erbracht
{ "effective_until": "2026-07-31" }

GET  /api/v1/anlagen/{tr_id}/aw-reduktionen?on=2026-07-01
```

The § 53c figure is one per plant and day: `POST …/stromsteuerbefreiung`
answers `200` with the row on file for a retry, closes the row in force the day
before a later one starts (`geschlossen`), and refuses (`422`) a second figure
on the same day or one overlapping a later row; the schema backs it with a
unique key and a `btree_gist` exclusion. A settlement reads the figure over the
whole month and refuses (`422`) a month in which it starts, ends or changes.

§ 53b turns on how the AW was determined, not on the marketing: a
statutory-AW plant in Direktvermarktung is in scope, a tender plant is not.
§ 53c is narrow in practice — § 9 Abs. 1 Nr. 1 and Nr. 3 StromStG involve no grid
transit. § 54 Abs. 3 Satz 2/3 lapse the deduction once the Nachweis arrives:
close the row's period, never delete it. A § 54 request setting no defect is
refused.

### § 101 Abs. 2 and § 100 Abs. 37 — the Fassung of 24.02.2025

§ 101 Abs. 2 Satz 2 EEG 2023 applies § 44b Abs. 1 Satz 3 and § 50a Abs. 1
Satz 1, Abs. 2 „in der am 24. Februar 2025 geltenden Fassung" until the
Commission's approval. The Commission approved the provisions of BGBl. 2025 I
Nr. 52 (the Biomassepaket) by decision of 18.09.2025 (state aid case
SA.118542; Bundesnetzagentur, Ausschreibung Biomasse, Gebotstermin 1. Oktober
2025), recorded as `eeg_billing::BIOMASSEPAKET_GENEHMIGT_AB`. So, by supply
period:

| | Before 18.09.2025 | From 18.09.2025 |
|---|---|---|
| § 44b 45 %-Quote spares | a § 44 Güllekleinanlage (≥ 80 % Gülle, ≤ 150 kW) | that, and a Biogasanlage with a „Zuschlag nach § 39" |
| § 50a Flexibilitätszuschlag | 65 EUR/kW/Jahr (a higher stored rate is refused, `422`) | 100 EUR/kW/Jahr |
| § 51b | not applied | applied |

A month the approval falls inside (September 2025) is refused (`422`) for a
plant whose rules the approval changes — § 44b, § 50a, and a § 51b plant, which
the engine itself answers `GenehmigungImZeitraum` — never settled under one
Fassung; every other plant settles it as usual. The settlement and
`check_sect44b_quote` share one predicate.

§ 100 Abs. 37 keeps a plant whose AW was set in a Gebotstermin after 31.12.2022
and before 24.02.2025 on the old Fassung for good and never applies § 51b to
it. The test is the **Gebotstermin**, registered as `gebotstermin`; a § 51b
plant without one is refused for periods from 18.09.2025.

**§ 39i Abs. 1 Satz 1** caps a tendered Biogasanlage's Getreidekorn-und-Mais
share by the award year (Nr. 1: 2023 → 40 %, Nr. 4: 2026–2028 → 25 %) or the
Gebotstermin (Nr. 2: after 31.12.2023 and before 25.02.2025 → 35 %, Nr. 3:
after 25.02.2025 and before 01.01.2026 → 30 %); a § 100 Abs. 37 plant takes
the award-year ladder of 24.02.2025 (40 / 35 / 30 %). A tendered biogas plant
needs both `gebotstermin` and `zuschlag_datum`; without them, or named by two
Nummern at different shares, the period is refused (`422`).

### § 36h Abs. 2 — wind Standortgüte re-evaluation

The Gütefaktor is re-evaluated from the start of operating years 6, 11 and 16
against the preceding five years:

```http
POST /api/v1/anlagen/{tr_id}/wind-reevaluation
{ "wirksam_ab_jahr": 6, "guetefaktor": "0.95" }
```

`build_settle_input` picks the Korrekturfaktor in force. `reconciliation_required`
flags a deviation over 2 percentage points (§ 36h Abs. 2 Satz 2): settle the
reviewed period's difference as a correction (interest EURIBOR-12M + 1 pp,
Satz 3).

### § 13a EnWG — curtailment compensation

`einspeisemanagement_kwh` adds a separate § 13a EnWG position at the AW rate; § 51
does not touch these kWh (§ 51 Abs. 1 EEG 2023 excludes them).

```http
POST /api/v1/anlagen/{tr_id}/settle/2024/6
{ "einspeisemenge_kwh": "850", "einspeisemanagement_kwh": "150" }
```

### § 49 solar degression

Solar AW fall **1 %** every six months (1 February and 1 August, from
01.02.2024), compounding on the unrounded value and rounded kaufmännisch per
step. The window bounds the **Inbetriebnahmedatum**; a plant keeps its window's
value. Base ladder (§ 48 Abs. 2 / 2a), gross, for IBN 01.01.2023 – 31.01.2024:

| Capacity | Überschuss | Volleinspeisung |
|---|---|---|
| ≤ 10 kWp | 8.60 ct/kWh | 13.40 ct/kWh |
| ≤ 40 kWp | 7.50 ct/kWh | 11.30 ct/kWh |
| ≤ 100 kWp | 6.20 ct/kWh | 11.30 ct/kWh |
| ≤ 400 kWp | 6.20 ct/kWh | 9.40 ct/kWh |
| ≤ 1 MWp | 6.20 ct/kWh | 8.10 ct/kWh |

These are not the Solarpaket-I figures (8,51 / 7,43 / 7,64): § 101 Abs. 1 Satz 1
holds § 48 Abs. 2 back pending EU state-aid approval, and Satz 2 applies the
version in force on 15 May 2024 until then — the series the Bundesnetzagentur
publishes. Seeded net Überschuss rates:

| Inbetriebnahme window | ≤ 10 kWp | > 10–40 kWp | > 40–1000 kWp |
|---|---|---|---|
| 2023-01-01 – 2024-01-31 | 8.20 ct | 7.10 ct | 5.80 ct |
| 2024-02-01 – 2024-07-31 | 8.11 ct | 7.03 ct | 5.74 ct |
| 2024-08-01 – 2025-01-31 | 8.03 ct | 6.95 ct | 5.68 ct |
| 2025-02-01 – 2025-07-31 | 7.94 ct | 6.88 ct | 5.62 ct |
| 2026-02-01 – 2026-07-31 | 7.78 ct | 6.73 ct | 5.50 ct |

The seed runs to 2030; `eeg_billing::rates::aw_ct_bei_inbetriebnahme` computes
any window. Use `lookup_statutory_rate` or `POST /api/v1/verguetungssatz-lookup`.
See [BNetzA Einspeisevergütungen](https://www.bundesnetzagentur.de/DE/Fachthemen/ElektrizitaetundGas/ErneuerbareEnergien/EEG_Foerderung/artikel.html#doc899816bodyText2).

### Metering

einsd settles on the **aggregated Einspeisemenge** edmd returns from
`GET /api/v1/energy/{malo_id}?direction=EINSPEISUNG`; the Messkonzept (Überschuss
split, § 42b EnWG GGV allocation `CCI+ZG6` / `Z74`) is computed in edmd with the
[`metering`](https://github.com/hupe1980/metering) crate. It does not read
`/api/v1/billing-period/{malo_id}`, whose `arbeitsmenge_kwh` is the Bezug and
reads `0 kWh` on an Erzeugungs-MaLo.

---

## Settlement

```http
POST /api/v1/anlagen/DE0123456789.../settle/2024/6
Content-Type: application/json

{
  "einspeisemenge_kwh": "312.5",
  "kwh_during_negative_epex": "0",
  "negative_price_quarter_hours": 0,
  "einspeisemanagement_kwh": "0",
  "billing_days_fraction": null
}
```

```json
{
  "id": "3fa85f64-...", "billing_year": 2024, "billing_month": 6,
  "settlement_eur": "23.22", "faelligkeitsdatum": "2024-07-15", "status": "calculated",
  "positions": [
    { "description": "Einspeisevergütung §21 EEG 2023", "legal_basis": "§21 EEG 2023",
      "kwh": "312.5", "rate_ct_kwh": "7.43", "eur": "23.22" }
  ]
}
```

`faelligkeitsdatum` is the 15th of the following month (§ 26 Abs. 1 EEG 2023).
Re-running overwrites the initial receipt (after snapshotting it to
`settlement_receipt_history`).

| Status | Meaning |
|---|---|
| `calculated` | Computed |
| `no_data` | No `einspeisemenge_kwh` |
| `price_missing` | No Marktwert (`PUT /api/v1/marktwert/…`) or EPEX average (`PUT /api/v1/epex-monthly/…`); retried |
| `foerderung_beendet` | EEG Förderende passed, KWKG lifetime hours used up, or Zuschlag lapsed; prorated |
| `jahreskontingent_erschoepft` | § 8 Abs. 4 KWKG annual hours used up; resumes in January |
| `sanctioned` | § 52 Abs. 1 EEG ≤ 2021 — EUR 0 |
| `kein_anspruch` | No § 19 Abs. 1 claim: § 21 Abs. 1 Satz 1 Nr. 1 (> 100 kW on the Einspeisevergütung) or § 39i Abs. 1 (biogas over its Getreide-/Mais-Höchstanteil). Terminal on the same facts |
| `fassung_nicht_tabelliert` | A recorded reduction under an EEG Fassung not tabled, or a plant commissioned after 31.12.2026, for which no Fassung is tabled; retried |
| `gehalten` | `[policy] beihilfe_politik = "halten"`: computed, not paid, until an approval covers the period |

The column's `CHECK` lists exactly these (plus `unknown` for a status the
library adds later), pinned both ways to `pg::RECEIPT_STATUSES`. No status says
a Gutschrift was paid: the payout is accountingd's, read from its
`GET /api/v1/eeg/payouts?tr_id=` (MCP `list_eeg_payouts`).

**Partial months (§ 25).** `billing_days_fraction` is derived when `null`: from a
mid-month commissioning `(days_in_month − day + 1) / days_in_month`, to a
mid-month Förderende `day / days_in_month`. It scales `settlement_eur` and the
positions, not `pflichtzahlung_eur`.

**Batch.** `POST /api/v1/settle/{year}/{month}` with `{ "dry_run": false }`
returns `total_plants`, `settled` (`calculated` + `foerderung_beendet`),
`skipped_no_data`, `skipped_price_missing`, `errors`, `total_settlement_eur` and
up to 100 `results_sample` rows.

**Auto-settle worker.** Wakes about every 23 h and settles the previous month
from `auto_settle_from_day` (default the 7th — the ÜNB publishes the Marktwert
around the 5th), revisiting `auto_settle_catchup_months` back (default 3,
clamped 1–24).

**Jahresabrechnung.** `POST /api/v1/anlagen/{tr_id}/jahresabrechnung/{year}`
sums each month's **latest** receipt (the correction where one exists).
`missing_months` is bounded by commissioning and Förderende.

### Corrections

```http
POST /api/v1/anlagen/{tr_id}/settlements/{year}/{month}/correction
Content-Type: application/json

{
  "einspeisemenge_kwh": "340.5",
  "reason": "MeterDataCorrected",
  "reason_detail": "Corrected reading after Zählernachlesung on 2024-07-20"
}
```

A correction is a **new** receipt (`is_correction = true`,
`correction_of = <original>`) beside the original, which stays unchanged (§ 147
AO / GoBD). `reason` is one of `MeterDataCorrected`, `TariffCorrected`,
`MastrRegistrationConfirmed`, `CapacityCorrected`, `RegulatoryReprocessing`,
`FoerderendedatumCorrected`, `Other`. „The receipt for a month" is the latest
row (`ORDER BY is_correction DESC, settled_at DESC`).
The correction's event names the receipt it supersedes (`korrektur_von`) and
states the corrected amount; accountingd pays only the difference to what the
period already received, and records an overpayment as owed back.

### Repowering and Zusammenlegung

`POST /api/v1/anlagen/{tr_id}/repowering` with
`{ "repowering_datum": "2026-05-01", "leistung_kwp_neu": "6.2" }` models the
**full-repowering** case: the Förderdauer restarts (31 December of year + 20,
§ 25 Abs. 1 Satz 2), `eeg_gesetz` and `verguetungssatz_ct` move to current law,
and `ursprungs_inbetriebnahme` keeps the original date. Partial repowering is not
modelled.

`POST /api/v1/anlagen/{tr_id}/zusammenlegen` evaluates **§ 24 Abs. 1** and
refuses with `422` naming the rule when the pair does not fuse. Satz 1 needs all
four: same site or unmittelbare räumliche Nähe (`standort_id`, or
`unmittelbare_raeumliche_naehe` on the request), gleichartige Energien
(`erzeugungsart`), a size-dependent § 19 Abs. 1 claim, and commissioning within
twelve consecutive calendar months. Then:

| Satz | Rule |
|---|---|
| 2 | Biogas from the **same** Biogaserzeugungsanlage fuses regardless (`biogaserzeugungsanlage_id`) |
| 3 | Freiflächenanlagen never fuse with building or Lärmschutzwand solar (`solar_montage`) |
| 4 | Building solar behind different Netzverknüpfungspunkte is not one plant (`netzverknuepfungspunkt`) |
| 5 | Steckersolargeräte ≤ 2 kW / ≤ 800 VA behind a Letztverbraucher are disregarded |

Satz 1 opens „unabhängig von den Eigentumsverhältnissen" — ownership is no test.

```http
POST /api/v1/anlagen/{tr_id}/zusammenlegen
{ "parent_tr_id": "DE_PARENT_MAIN", "combined_leistung_kwp": "19.0", "unmittelbare_raeumliche_naehe": false }
```

On success the child becomes `abgemeldet`, the parent's `foerderendedatum` is
unchanged, and settlements run on the parent; update `verguetungssatz_ct` if a
band boundary is crossed. A fused plant keeps a rate per block
(`capacity_blocks`); the metered kWh (and the § 51 kWh) are split by installed
capacity by **largest remainder**, so the blocks sum to the reading exactly. A
block past its Förderdauer is allocated and then dropped.

---

## § 14 UStG Gutschrift

EEG feed-in is settled by **Gutschrift** (§ 14 Abs. 2 Satz 2 UStG). For every
billable settlement `run_settlement` builds one (`settlement_to_gutschrift`, VAT
from `einspeiser.ust_status`), stores it as a BO4E `rubo4e::current::Rechnung`
in `settlement_receipts.rechnung_json` with `gutschrift_nummer`
(`GS-EEG-<tr>-<year>-<month>`), and passes it through the BO4E outbound gate
first.

One that fails the gate is dropped with a warning and the settlement is stored
without a document. Non-billable statuses issue none.

---

## EnFG Belastungsausgleich

The Netzbetreiber that pays a plant is reimbursed by its ÜNB: § 13 Abs. 1
Satz 1 EnFG reimburses „die … geleisteten Zahlungen" under § 19 and § 50 EEG
(Nr. 1), Abschnitt 2 KWKG (Nr. 2) and earlier Fassungen (Nr. 3), and § 13
Abs. 1 Satz 2 counts a Forderung „die durch Aufrechnung erloschen" ist as
paid. einsd keeps that figure in `enfg_ledger`, per tenant, ÜNB, billing month
and head, and derives the § 50 Nr. 1 EnFG Mitteilung from it.

**Paid, not computed.** `POST /api/v1/enfg/ledger/{year}/{month}` reads the
month's payments from accountingd (`GET /api/v1/eeg/enfg-zahlungen`: payouts
whose pain.002 status is `ACSC`, recorded Aufrechnungen, and the operators'
Rückzahlungen as negative amounts — § 13 Abs. 1 Satz 1 Nr. 1 EnFG reimburses
the payments „abzüglich der Rückzahlungen nach § 26 Absatz 1 Satz 3" EEG 2023,
under which „zu hohe … Abschläge" are refunded). A settled receipt
with no such payment contributes nothing; the receipt only says which head a
payment belongs to. The cents a plant was paid in the month must equal one of
its decided receipts (`calculated`, `foerderung_beendet`, `sanctioned`,
`kein_anspruch`, `jahreskontingent_erschoepft`) rounded kaufmännisch to the
cent; any other amount is refused with the plant, the cents and the receipts.

| Head (`posten`) | Settlement models | Provision · Mitteilung item |
|---|---|---|
| `EEG_19_ABS1` | `VERGUETUNG`, `AUSFALLVERGUETUNG`, `DIREKTVERMARKTUNG`, `AUSSCHREIBUNG`, `MIETERSTROM`, the § 19 part of `FLEXIBILITAET` | § 13 Abs. 1 Satz 1 Nr. 1, 3 EnFG · § 50 Nr. 1 Buchst. a aa |
| `EEG_50` | `FLEXIBILITAET_ZUSCHLAG`, the Flexibilitätsprämie position of `FLEXIBILITAET` | § 13 Abs. 1 Satz 1 Nr. 1 EnFG · § 50 Nr. 1 Buchst. a bb |
| `KWKG_STROM` | `KWKG_ZUSCHLAG` | § 13 Abs. 1 Satz 1 Nr. 2, 3 EnFG · § 50 Nr. 1 Buchst. a cc |
| `SECT14_EEG52` | a § 52 Pflichtzahlung set off against the Vergütung (§ 52 Abs. 6 Satz 2 EEG 2023) | § 14 Satz 1 Nr. 3 EnFG · § 50 Nr. 1 Buchst. e |

`EIGENVERBRAUCH` and `SONSTIGE_DIREKTVERMARKTUNG` carry no Netzbetreiber
payment, so a payment for one is refused. `POST_EEG_SPOT` and `GGV` refuse too:
the first settles on the monthly EPEX average, which is not shown to be the
§ 23b / § 53 Abs. 4 EEG 2023 Einspeisevergütung of an ausgeförderte Anlage, and
the GGV (§ 42b EnWG) is no § 21b Abs. 1 Veräußerungsform. The mapping is
`eeg_billing::enfg::zuordnung`, an exhaustive `match`.

**The ÜNB.** § 50 EnFG addresses „ihrem vorgelagerten
Übertragungsnetzbetreiber" without saying whether that is decided per plant or
per Verteilernetzbetreiber. einsd attributes a month only where both readings
agree: every paid plant's Messlokation carries one Regelzone in marktd. A plant
without a MeLo or Regelzone refuses the month naming its `tr_id`, and plants in
two Regelzonen refuse it naming both. The Regelzone is stored on each row; a
rebuild adds payments made since and never moves a booked row.

**The Mitteilung.** `GET /api/v1/enfg/mitteilung/{year}/{month}` lists every
§ 50 Nr. 1 Buchst. a–g item with `bestand` `gehalten`, `teilweise` or
`nicht_gehalten`; an item mako does not hold carries no figure and is named in
`nicht_gehalten` — the KWKG-Boni, the vermiedene Netzentgelte (§ 13 Abs. 2),
the KWK-Strom Verwertung, the umlagenpflichtige Netzentnahmen, the § 52
payments not collected by set-off and § 55b, and Buchst. g.

Within it, § 72 Abs. 1, 2 EEG 2023: each plant's § 21b Abs. 1 Veräußerungsform, a switch in
the month, the § 72 Abs. 1 Nr. 2 facts on a switch into the Ausfallvergütung,
and the Spannungsebene (marktd's `netzebene_messung`); a plant without one is
named. einsd does not read the ÜNB's Formularvorlage (§ 54 Satz 2 EnFG); the
Mitteilung is mako's JSON shape.

---

## Endpoints

| Method | Path | Description |
|---|---|---|
| `GET` | `/api/v1/einspeiser` · `/{einspeiser_id}` | Anlagenbetreiber |
| `PUT` | `/api/v1/einspeiser/{einspeiser_id}` | Register or update one |
| `POST` | `/api/v1/anlagen` | Register a plant |
| `GET` | `/api/v1/anlagen` | List (`?malo_id=&erzeugungsart=&status=`) |
| `GET/PUT/DELETE` | `/api/v1/anlagen/{tr_id}` | Fetch, update, decommission |
| `POST` | `/api/v1/anlagen/{tr_id}/mastr-registrierung` | Confirm MaStR |
| `POST` | `/api/v1/anlagen/{tr_id}/repowering` | Full repowering |
| `POST` | `/api/v1/anlagen/{tr_id}/zusammenlegen` | § 24 merge, or `422` |
| `GET/POST` | `/api/v1/anlagen/{tr_id}/pflichtverstoesse` | § 52 register; `409` on a second open entry |
| `PUT` | `/api/v1/anlagen/{tr_id}/pflichtverstoesse/{typ}/behoben` | Cure date |
| `GET` | `/api/v1/anlagen/{tr_id}/aw-reduktionen` | AW cuts in force on `?on=` |
| `POST` | `/api/v1/anlagen/{tr_id}/aw-reduktionen/regionalnachweis` · `stromsteuerbefreiung` · `sect54-defekt` | §§ 53b, 53c, 54 |
| `POST` | `/api/v1/anlagen/{tr_id}/aw-reduktionen/sect54-defekt/{id}/nachweis-erbracht` | Close a § 54 period |
| `GET` | `/api/v1/anlagen/by-malo/{malo_id}/veraeusserungsform` | Form in force, for processd |
| `POST` | `/api/v1/anlagen/{tr_id}/switch-veraeusserungsform` | § 21b switch |
| `POST` | `/api/v1/anlagen/{tr_id}/wind-reevaluation` | § 36h Abs. 2 |
| `GET` | `/api/v1/anlagen/foerderung-auslaufend` | Förderende within `?days=` (`AuslaufendeAnlagen`) |
| `GET` | `/api/v1/anlagen/ohne-mastr` | Active plants not in the MaStR, with the § 52 Pflichtzahlung (`AnlagenOhneMastr`) |
| `GET` | `/api/v1/anlagen/unabgerechnet/{year}/{month}` | Active plants with no receipt for the month (`UnabgerechneteAnlagen`) |
| `POST` | `/api/v1/anlagen/{tr_id}/settle/{year}/{month}` | Monthly settlement |
| `POST` | `/api/v1/anlagen/{tr_id}/settlements/{year}/{month}/correction` | Correction receipt |
| `GET` | `/api/v1/anlagen/{tr_id}/settlements` | History as `Abrechnungen` (`?year=&month=&limit=`; unknown parameters are `400`) |
| `GET` | `/api/v1/anlagen/{tr_id}/settlements/{year}/{month}/erklaerung` | The month's receipt with its positions and legal bases (`AbrechnungsErklaerung`) |
| `POST` | `/api/v1/settle/{year}/{month}` | Batch settle |
| `POST` | `/api/v1/anlagen/{tr_id}/jahresabrechnung/{year}` | Annual reconciliation |
| `POST/GET` | `/api/v1/enfg/ledger/{year}/{month}` | Book / read the EnFG ledger from accountingd's payments |
| `GET` | `/api/v1/enfg/mitteilung/{year}/{month}` | § 50 Nr. 1 EnFG Mitteilung with the § 72 EEG 2023 items |
| `PUT/GET` | `/api/v1/epex-monthly/{year}/{month}` | EPEX monthly average (`DIREKTVERMARKTUNG`, `POST_EEG_SPOT` fallback) |
| `PUT` | `/api/v1/epex-spot` | Day-ahead spot prices |
| `PUT/GET` | `/api/v1/marktwert/{year}/{art}/{erzeugungsart}` | Anlage 1 Marktwert, `art` = `monat` \| `jahr` |
| `GET` | `/api/v1/marktwert/{year}/nachbewertung` | Months on a provisional Jahresmarktwert |
| `POST` | `/api/v1/verguetungssatz-lookup` | Rate lookup |
| `GET` | `/api/v1/openapi.json` | OpenAPI 3.1 document of every `/api/v1` route above |
| `GET` | `/api/v1/policy` | Operator policy report (`read-policy`) |
| `GET` | `/admin/einrichtung` | Configuration findings and policy (`read-config`) |
| `POST` | `/mcp` | MCP (Streamable HTTP, revisions 2026-07-28 and 2025-11-25, no session) |
| `GET` | `/health/live` · `/health/ready` | Liveness; readiness |

---

## Authentication and authorization

einsd refuses to boot without `[oidc]` unless `allow_insecure_no_auth = true`.
`policies/einsd.cedar` states **15 actions** in four grants; every handler checks
one before touching the database, and a refusal is `403` with the Cedar decision
in `error`. Context: `principal_tenant` / `principal_roles` from `mako_tenant` /
`mako_roles`, `resource_tenant` from the row's owner.

| Grant | Actions | Requires |
|---|---|---|
| Reads | `read-anlage`, `read-einspeiser`, `read-settlement`, `read-marktdaten`, `use-mcp`, `read-policy`, `read-config` | matching tenant |
| Writes | `write-anlage`, `write-einspeiser`, `run-settlement`, `manage-lifecycle`, `write-marktdaten` | `NB`, `LF` or `UENB` |
| Corrections | `correct-settlement` | `NB` or `UENB` |
| EnFG | `read-enfg`, `build-enfg-ledger` | `NB` |

| Action | Guards |
|---|---|
| `read-anlage` | Plant reads, `foerderung-auslaufend`, `by-malo/…/veraeusserungsform`, the `pflichtverstoesse` and `aw-reduktionen` reads |
| `write-anlage` | `POST`/`PUT`/`DELETE` on plants |
| `read-einspeiser` / `write-einspeiser` | `/einspeiser` |
| `read-settlement` | `GET …/settlements` |
| `run-settlement` | Single and batch settle, Jahresabrechnung |
| `correct-settlement` | `…/correction` |
| `manage-lifecycle` | Repowering, merge, MaStR, Veräußerungsform switch, the § 52 register, §§ 53b–54, § 36h |
| `read-marktdaten` | EPEX and Marktwert reads, `nachbewertung`, `verguetungssatz-lookup` |
| `write-marktdaten` | EPEX and Marktwert writes |
| `use-mcp` | `/mcp` |
| `read-policy` | `GET /api/v1/policy` |
| `read-enfg` | `GET /api/v1/enfg/ledger/…`, `GET /api/v1/enfg/mitteilung/…` |
| `build-enfg-ledger` | `POST /api/v1/enfg/ledger/…` |

---

## Configuration

| Key | Default | Description |
|---|---|---|
| `[database] url` | — (required) | PostgreSQL (`env:…` supported) |
| `[http] addr` | `0.0.0.0:9180` | Listen address |
| `tenant` | — (required) | Tenant identifier — data-isolation key written to every database row. Typically the operator's BDEW- or DVGW-Codenummer, but any stable unique string is valid |
| `erp_webhook_url` · `erp_hmac_secret` | — | ERP webhook and its signing secret |
| `edmd_url` · `edmd_api_key` | — | Feed-in from edmd |
| `accountingd_url` · `accountingd_api_key` | — | The payments made, for the EnFG ledger; without it the ledger is `503` |
| `marktd_url` · `marktd_api_key` | — | MeLo Regelzone and Netzebene for the EnFG ledger and Mitteilung; without it both are `503` |
| `alert_interval_secs` | `21600` | Förderende alert interval |
| `jahresmarktwert_url` | — | ÜNB source for the **monthly** Marktwert import; the Jahresmarktwert is imported by hand |
| `jahresmarktwert_import_interval_secs` | `86400` | Poll interval; also runs 60 s after start |
| `auto_settle_from_day` | `7` | First day the worker settles the previous month |
| `auto_settle_catchup_months` | `3` | Months revisited per sweep (1–24) |
| `[mcp]` | — | MCP API key (`api_key = "env:EINSD_MCP_API_KEY"`) |
| `[oidc]` | — (required) | REST token verification |
| `allow_insecure_no_auth` | `false` | Development only |
| `[beihilfevorbehalt]` | no approvals | Recorded state-aid approvals; see [Beihilfevorbehalt](#beihilfevorbehalt-from-01-01-2027) |
| `[policy] beihilfe_politik` | `verweigern` | See [`beihilfe_politik`](#policy-beihilfe-politik); every operator setting is listed in [Operator policy](https://hupe1980.github.io/mako/docs/reference/operator-policy/) |
| `[policy] sect21c_ohne_zuordnung` | `angabe_verlangen` | See [`sect21c_ohne_zuordnung`](#policy-sect21c-ohne-zuordnung) |
| `[policy] sect52_aufrechnung` | `gesondert` | See [`sect52_aufrechnung`](#policy-sect52-aufrechnung) |

```toml
tenant   = "stadtwerke-musterstadt"
edmd_url = "http://edmd:8380"

[http]
addr = "0.0.0.0:9180"

[database]
url = "postgresql://einsd:secret@db:5432/einsd"
```

---

## Database

`services/einsd/migrations/0001_schema.sql`.

**`eeg_anlagen`** — one row per Technische Ressource, PK `(tr_id, tenant)`, with
the `malo_id` it feeds
([Identifier Formats](https://hupe1980.github.io/mako/docs/architecture/domain-model/#identifier-formats)).

| Group | Columns |
|---|---|
| Identity and status | `einspeiser_id` (FK, not null), `status`, `settlement_state`, `inbetriebnahme_typ`, `foerderendedatum` (nullable), `foerderung_alert_sent_at` |
| Rate | `settlement_model`, `verguetungsform`, `verguetungssatz_ct` (`CHECK >= 0`), `direktverm_aw_ct`, `zuschlagswert_ct`, `mieter_zuschlag_ct`, `leistung_kwp` (`CHECK > 0`), `capacity_blocks` |
| Tender | `ausschreibungs_zuschlag_id`, `zuschlag_datum`, `gebotstermin` (§ 100 Abs. 37 cohort), `zuschlag_erloeschen_datum` (§§ 36e / 37e / 39e; expiry derived per period, distinct from § 35a Entwertung), `is_biogas_sect51b` |
| § 9 / § 52 | `sect9_fernsteuerbarkeit`, `sect9_begrenzung_60`, `wechselrichterleistung_va`, `fernsteuerbarkeit_datum`, `mastr_*`, `mastr_violation_start`, `last_veraeusserungsform_switch` |
| § 51 | `negative_price_qh_gesamt`, `ist_pilotwindanlage`, `sect51_optin_erklaert_am` |
| Wind | `wind_guetegrad`, `wind_korrekturfaktor`, `wind_guetefaktor_reevaluations` |
| KWKG and storage | `kwk_anlagenart`, `kwk_verwendung`, `kwk_bmwk_feststellung`, `speicher_option` (`KEINE` · `ABGRENZUNG` · `PAUSCHAL`) |
| § 24 | `standort_id`, `solar_montage`, `netzverknuepfungspunkt`, `biogaserzeugungsanlage_id` |

`direktvermarktung` is a request flag: `true` forces `DIREKTVERMARKTUNG`, and
nothing sets it from capacity.

| Table | Purpose |
|---|---|
| `einspeiser` | Anlagenbetreiber |
| `settlement_receipts` | One initial receipt per period (partial unique index `WHERE is_correction = false` — upserts must repeat the predicate) plus corrections; `pflichtzahlung_eur`, `marktwert_vorlaeufig`, `rechnung_json`, `gutschrift_nummer`, `faelligkeitsdatum`, `verlaengerungsanspruch_qh`, `billing_days_fraction`, `positions_json`, `is_correction`, `correction_of`, `ketten_folge` (unique per period) |
| `settlement_receipt_history` | Snapshot of an initial receipt before a re-settle overwrites it |
| `settlement_state_transitions` | `from_state`, `to_state`, `effective_from`, `reason` |
| `eeg_pflichtverstoesse` | § 52 register; partial unique index `ep_offen` — one open entry per Nummer |
| `eeg_regionalnachweise` · `eeg_stromsteuerbefreiungen` · `eeg_sect54_solar_defekte` | §§ 53b, 53c, 54 facts; a § 53c figure is unique per plant and day (unique key + `btree_gist` exclusion) |
| `eeg_verguetungssaetze` | Seeded statutory rates |
| `marktwert_preise` | Both Anlage 1 series; `billing_month` NULL for a Jahresmarktwert |
| `epex_monthly_prices` · `epex_spot_prices` | EPEX monthly averages and day-ahead prices |
| `settlement_period_accruals` | Each period's absolute contribution to the § 51a, § 44b and KWKG counters, so a re-settle applies only the difference |
| `eeg_sect52_monate` | Per plant and month: the running § 52 claim, the month's increment, and how much of it was set off (`aufgerechnet_eur`) or stays owed (`rest_eur`) |
| `jahresabrechnungen` | Annual reconciliations |
| `enfg_ledger` | Payments made per ÜNB (`uenb_regelzone`), month and head; unique per payment and head; `receipt_id` the receipt it reconciles to |

---

## CloudEvents

| Type | When | Payload |
|---|---|---|
| `de.mako.eeg.verguetung.berechnet` | Einspeisevergütung, KWKG or post-EEG period decided | `receipt_id`, `ketten_folge`, `korrektur_von` (the receipt a correction supersedes, else null), `tr_id`, `malo_id`, `billing_year/month`, `settlement_model`, `einspeisemenge_kwh`, `settlement_eur` (net), `status`, `pflichtzahlung_kumuliert_eur` (the running § 52 claim), `gutschrift_nummer`, `gutschrift_steuer_eur`, `gutschrift_brutto_eur`, `bank_iban`, `bank_bic`, `zahlungsempfaenger`, `zahlungsempfaenger_anschrift` (the payee's structured address, else null) |
| `de.mako.eeg.marktpraemie.berechnet` | Marktprämie period decided | the same payload |
| `de.mako.eeg.anlage.mastr-registriert` | MaStR confirmed | `tr_id`, `mastr_nummer` |
| `de.mako.eeg.anlage.foerderung-auslaufend` | EEG Förderende within 180 days, once per plant (worker every 6 h; never for KWKG); enqueued with the mark that it was sent | `tr_id`, `foerderendedatum`, `days_remaining` |
| `de.mako.eeg.veraeusserungsform.gewechselt` | § 21b switch accepted | `tr_id`, new model, effective date |
| `de.mako.eeg.settlement.batch-due` | Monthly batch due | `billing_year`, `billing_month` |

The period — `tr_id`, `billing_year`, `billing_month` — is the receipt chain:
the initial receipt and each correction state the period's whole amount.
Every write of a receipt, a re-settle included, takes the chain's next
`ketten_folge` under a per-chain lock (trigger
`settlement_receipts_ketten_folge`), and that number — not the event `time` —
orders the chain. accountingd books and pays the difference to what the chain
already holds, so a correction is never paid in full a second time.

Every decided period is announced, a zero included: a re-settle or correction
ending at `kein_anspruch`, `foerderung_beendet`, `sanctioned` or
`jahreskontingent_erschoepft` tells accountingd the new amount, so what it
already paid becomes owed back. `no_data`, `price_missing`,
`fassung_nicht_tabelliert` and `gehalten` state no amount and announce nothing;
a decided receipt without `settlement_eur` rolls the settlement back.

The bank fields and the payee's address come from `einspeiser` so accountingd
can build the pain.001; they are null for `EIGENVERBRAUCH`. Deliveries are
`application/cloudevents+json` with a Standard Webhooks signature, source
`urn:mako:einsd:tenant:{tenant}`.

```json
{
  "specversion": "1.0",
  "type":        "de.mako.eeg.verguetung.berechnet",
  "source":      "urn:mako:einsd:tenant:9910000000002",
  "id":          "a1b2c3d4-...",
  "subject":     "TR-SOLAR-001",
  "time":        "2026-08-03T06:00:00Z",
  "data": {
    "receipt_id":      "0f6b2c1e-4d5a-4f7e-9a3b-2c1d0e9f8a7b",
    "ketten_folge":    1,
    "korrektur_von":   null,
    "tr_id":           "TR-SOLAR-001",
    "malo_id":         "51238696012",
    "billing_year":    2026,
    "billing_month":   7,
    "settlement_model": "VERGUETUNG",
    "einspeisemenge_kwh": "280.500",
    "settlement_eur":  "22.736",
    "status":          "calculated",
    "gutschrift_nummer":    "GS-EEG-TR-SOLAR-001-2026-07",
    "gutschrift_steuer_eur": "4.31984",
    "gutschrift_brutto_eur": "27.05584",
    "bank_iban":       "DE89370400440532013000",
    "bank_bic":        "COBADEFFXXX",
    "zahlungsempfaenger": "Franz Huber",
    "zahlungsempfaenger_anschrift": {
      "town": "Rosenheim", "country": "DE", "street": "Am Bach",
      "building_number": "3", "post_code": "83022", "country_subdivision": null
    }
  }
}
```

---

## MCP server

At `/mcp` (Streamable HTTP, revisions 2026-07-28 and 2025-11-25, no session), authenticated by `[mcp]`.

Seventeen tools read; three write — `trigger_settle`, `import_marktwert` and
`import_epex_monthly_price`. Money crosses the surface as exact decimals.

**20 tools:**
`get_policy` · `list_plants` · `get_plant` · `list_expiring` · `list_settlements` ·
`lookup_verguetungssatz` · `lookup_statutory_rate` · `trigger_settle` ·
`list_unsettled_plants` · `get_epex_monthly_price` · `import_epex_monthly_price` ·
`get_compliance_status` · `list_plants_without_mastr` ·
`check_einspeiseverguetung_anspruch` · `check_sect44b_quota` ·
`import_marktwert` · `get_marktwert` ·
`get_settlement_state_history` · `explain_settlement` · `get_aw_reduktionen`

Six reads are shared with a documented REST route: the tool and the route
call one function, answer one type — the tool's `outputSchema` (pinned in
`services/einsd/mcp.snapshot.json`) and the route's response in
`/api/v1/openapi.json` (committed as `services/einsd/openapi.json`) — and
authorize with the same Cedar action, so the tool admits exactly the callers
the route does:

| Tool | `GET` | Cedar | Answer |
|---|---|---|---|
| `get_plant` | `/api/v1/anlagen/{tr_id}` | `read-anlage` | `AnlageRow` |
| `list_expiring` | `/api/v1/anlagen/foerderung-auslaufend` | `read-anlage` | `AuslaufendeAnlagen` |
| `list_plants_without_mastr` | `/api/v1/anlagen/ohne-mastr` | `read-anlage` | `AnlagenOhneMastr` |
| `list_settlements` | `/api/v1/anlagen/{tr_id}/settlements` | `read-settlement` | `Abrechnungen` — each receipt with `status`, `error_detail`, `faelligkeitsdatum` and the correction chain |
| `explain_settlement` | `/api/v1/anlagen/{tr_id}/settlements/{year}/{month}/erklaerung` | `read-settlement` | `AbrechnungsErklaerung`; a month without a receipt is `settlement_not_found` |
| `list_unsettled_plants` | `/api/v1/anlagen/unabgerechnet/{year}/{month}` | `read-settlement` | `UnabgerechneteAnlagen` |

Decimals are strings (`format: decimal`), dates `YYYY-MM-DD`, instants
RFC 3339. A refusal is the route's `4xx` and the tool's error result
`<code>: <message>`.

`check_einspeiseverguetung_anspruch` lists active plants over 100 kW on the
Einspeisevergütung (they settle `kein_anspruch`). `check_sect44b_quota` reports
the § 44b EEG 2023 biogas cap, YTD kWh and remaining quota, warning at 75 % and
critical at 90 % (plants > 100 kW).

**6 prompts:**
`register-eeg-plant` · `settle-monthly` · `check-foerderung-expiry` ·
`ausschreibung-workflow` · `post-eeg-transition` · `anlagenerweiterung`

In agentd, `eeg-agent` handles `de.mako.eeg.*` and
`de.mako.messwert.reading.direct.stored` (an iMSys push lifts the < 100 kW § 51
exemption); `eeg-compliance-agent` runs the § 52 / § 44b / § 21 checks;
`einsd-batch-agent` drives the monthly batch. See the
[agentd guide](https://hupe1980.github.io/mako/docs/services/agentd/).

---

## Testing

```bash
cargo test -p eeg-billing -p einsd --all-features
```

`eeg-billing` carries the formula tests, `prop_tests` (proptest invariants:
FeedInTariff exactness, Marktprämie non-negativity, § 51 bounds, post-EEG floor),
`regulatory_showcase` and doctests. einsd's `tests/it/` holds the
schema/code guards, the seed guard, the authorization guard and the settlement
integration suite.
