-
-
Notifications
You must be signed in to change notification settings - Fork 6
energy accounting
This document defines the physical energy flow model used by the HSEM planner. Every equation here corresponds to a constraint enforced in the SoC simulation, the cost function, and the MILP solver.
For every planning slot, energy balance must hold:
When EV integration is disabled,
Positive
The battery and grid flows must satisfy:
Where
Key invariant: The cost function prices
$grid\_to\_battery[t]$ , not$battery\_charge\_stored[t]$ . This ensures conversion losses are included in the import cost.
Where
The battery energy removed to supply a target house load:
For each slot:
Where:
When None (unlimited), the per-slot cap is
relaxed to
The EV charger draws from the AC bus — it never draws from the house battery:
Where
| Field | Formula | Meaning |
|---|---|---|
ev_planned_load_kwh |
Sum of EV AC loads NOT in house load | Added to net consumption |
ev_accounted_load_kwh |
Sum of EV AC loads already in house load | NOT added to net consumption |
ev_total_planned_load_kwh |
ev_planned + ev_accounted |
Total EV activity (diagnostics) |
The EV planner selects slots using net consumption after house load:
Where
Before PR #406, the EV planner incorrectly used estimated_net_consumption which
was 0.0 at EV planning time (net consumption had not been populated yet). This
meant every slot appeared to have zero surplus, so the EV was always scheduled
as grid-import.
PR #397 fixed this by deriving surplus directly from raw PV and house load
fields. PR #406 improved it further by running populate_net_consumption
before EV planning so that PV confidence decay is automatically applied.
With 97 % charge and 97 % discharge efficiency:
Charging 10 kWh from the grid:
- Grid draws:
$10 / 0.97 = 10.31$ kWh - Battery stores: 10 kWh
- Discharging 10 kWh battery energy:
- House receives:
$10 \cdot 0.97 = 9.7$ kWh - Net round-trip: 10.31 kWh grid → 9.7 kWh house = 5.91 % loss
For multi-day horizons, PV estimates are discounted:
| Day offset | Decay factor |
|---|---|
| 0 (today) | 1.00 |
| 1 (tomorrow) | 0.90 |
| 2 (day after) | 0.80 |
Prices are not decayed because spot-market prices are typically firm by mid-day.
| Conversion | Formula |
|---|---|
| W → kW | |
| Wh → kWh | |
| Power → energy | |
| Accumulated energy |
All internal planner calculations use kWh for energy and kW for power. Power limits from Huawei Solar are received in Watts and converted at the planner boundary.
- Home — User-facing overview: features, FAQ, working modes, battery schedules, excess export, consumption sensors
- Battery Charging Economics — How to calculate the minimum charging price for a battery schedule
- Architecture Overview — System context, layered architecture, module map, planning pipeline
- Planner Specification — Normative — all planner invariants, rules, and constraints
- Planner Technical Guide — How the planner works with worked examples
- Cost Function Math — Complete mathematical formulation of the 8-term cost function
- Energy Accounting — Physical energy flow model, SoC simulation, efficiency math
- Candidate Generation — How candidates are generated, assumptions, partial-SoC
- MILP Optimization — Full LP formulation, variable layout, constraints, and solver pipeline
- Consumption Prediction — Weighted-average model, IQR outlier detection, spike suppression
- Safety Modes — Degraded mode, read-only gate, write-verify applier, runtime resolver
- Price Scaling — EDS price scaling, eds_share conversion factor
- Services Reference — All 4 HSEM services with examples
- Sensors Reference — Complete entity reference: all sensor, select, switch, number, and time entities
- Dashboard Setup — Step-by-step ApexCharts dashboard with full YAML, layout reference, and troubleshooting
- Config Flow Reference — Every config/options flow step and field
- EV Charge Plan Setup — EV planned load configuration guide
- EV Surplus Charging Automation — Wire your physical EV charger (go-e, Easee, Zaptec) to follow HSEM surplus recommendations
- EV Optimal Charging Template — Legacy Home Assistant template sensor for cost-optimal EV charging
- Forecast Accuracy Tracking — Forecast vs actual tracking system
- Huawei Entities — Canonical HA entity ID reference
- Troubleshooting Guide — Diagnose and fix common problems: missing data, wrong prices, write failures, battery behaviour
- Quality Checks — Static quality tools and CI configuration