fix(energy): report real kWh in the cost Summary instead of mislabelled money
frontend / frontend (push) Successful in 10m24s
pytest / test (push) Successful in 11m57s
docker-image / build-and-push (push) Successful in 1m37s

The Summary cards labelled `metered_import` / `metered_export` as "(kWh)", but
both fields are monetary totals (Σ import_cost / Σ export_revenue).  Today's
page therefore showed "Import 1.339 kWh" when the meter had actually imported
4.188 kWh — the 1.339 was EUR.  Cross-checked against the DSMR cumulative
registers and Home Assistant: our energy figures were correct all along, only
the label was wrong.

summarize() now also aggregates the metered energy, reusing the already-fetched
non-degraded rows so no extra query is issued:

  metered_import_kwh = Σ (d1_kwh + d2_kwh)
  metered_export_kwh = Σ (r1_kwh + r2_kwh)

The Import/Export cards show kWh as the headline figure and keep the monetary
equivalent as a sub-line, so the split between energy cost and standing
charges/credits behind total_payable stays visible.

The `_kwh` suffix is now the only thing separating energy from money in this
payload, so the docstrings on both summarize() and SummaryResponse call that
out explicitly.

app/integrations/expose.py reads only the money keys, so the HA outbound
sensors are unaffected by the additive fields.
This commit is contained in:
2026-08-06 22:20:56 +02:00
parent b405aea88b
commit 0958d9a2e9
9 changed files with 157 additions and 31 deletions
+16 -4
View File
@@ -4727,17 +4727,27 @@
"metered_import": {
"type": "number",
"title": "Metered Import",
"description": "Σ import_cost for non-degraded periods."
"description": "Σ import_cost for non-degraded periods (money, in `currency`)."
},
"metered_export": {
"type": "number",
"title": "Metered Export",
"description": "Σ export_revenue for non-degraded periods."
"description": "Σ export_revenue for non-degraded periods (money, in `currency`)."
},
"metered_net": {
"type": "number",
"title": "Metered Net",
"description": "Σ net_cost for non-degraded periods."
"description": "Σ net_cost for non-degraded periods (money, in `currency`)."
},
"metered_import_kwh": {
"type": "number",
"title": "Metered Import Kwh",
"description": "Σ (d1_kwh + d2_kwh) for non-degraded periods (energy imported, kWh)."
},
"metered_export_kwh": {
"type": "number",
"title": "Metered Export Kwh",
"description": "Σ (r1_kwh + r2_kwh) for non-degraded periods (energy exported, kWh)."
},
"fixed_costs": {
"type": "number",
@@ -4776,6 +4786,8 @@
"metered_import",
"metered_export",
"metered_net",
"metered_import_kwh",
"metered_export_kwh",
"fixed_costs",
"credits",
"total_payable",
@@ -4784,7 +4796,7 @@
"days"
],
"title": "SummaryResponse",
"description": "Response for GET /api/energy/costs/summary.\n\nAll monetary values are in ``currency``.\n\n``total_payable = metered_net + fixed_costs credits``"
"description": "Response for GET /api/energy/costs/summary.\n\nMonetary values are in ``currency``; the ``*_kwh`` fields are energy totals\nin kWh. ``metered_import``/``metered_export`` are **money**, not energy —\nonly the ``_kwh``-suffixed fields carry kWh.\n\n``total_payable = metered_net + fixed_costs credits``"
},
"TibberTestPriceSchema": {
"properties": {
+20 -4
View File
@@ -3659,15 +3659,25 @@ components:
metered_import:
type: number
title: Metered Import
description: Σ import_cost for non-degraded periods.
description: Σ import_cost for non-degraded periods (money, in `currency`).
metered_export:
type: number
title: Metered Export
description: Σ export_revenue for non-degraded periods.
description: Σ export_revenue for non-degraded periods (money, in `currency`).
metered_net:
type: number
title: Metered Net
description: Σ net_cost for non-degraded periods.
description: Σ net_cost for non-degraded periods (money, in `currency`).
metered_import_kwh:
type: number
title: Metered Import Kwh
description: Σ (d1_kwh + d2_kwh) for non-degraded periods (energy imported,
kWh).
metered_export_kwh:
type: number
title: Metered Export Kwh
description: Σ (r1_kwh + r2_kwh) for non-degraded periods (energy exported,
kWh).
fixed_costs:
type: number
title: Fixed Costs
@@ -3699,6 +3709,8 @@ components:
- metered_import
- metered_export
- metered_net
- metered_import_kwh
- metered_export_kwh
- fixed_costs
- credits
- total_payable
@@ -3709,7 +3721,11 @@ components:
description: 'Response for GET /api/energy/costs/summary.
All monetary values are in ``currency``.
Monetary values are in ``currency``; the ``*_kwh`` fields are energy totals
in kWh. ``metered_import``/``metered_export`` are **money**, not energy —
only the ``_kwh``-suffixed fields carry kWh.
``total_payable = metered_net + fixed_costs credits``'