Repository navigation
Settlement and savings stats: hourly-netted import/export, deposit credit, payback - #55
Merged
Merged
Conversation
…edit, savings vs no PV/battery New daily_settlement table in data.db, recomputed after each new hourly_summary hour, a back-fill script, and a /stats page with monthly and yearly totals, a daily table, a CSV download and a payback chart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… profit The battery's grid part grows with charge the PV surplus didn't cover (90 % round trip), is used by the house before stored PV, carries over between days and is capped at the energy in the battery (hourly max SoC). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… page) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
We had no long-running record of what the grid operator settles or what PV and the battery save.
_calculate_income.pyprints one day to the terminal and stores nothing, and the HA recorder keeps only 35 days. Comparing with the bill and tracking the investment return meant redoing the sums by hand.Change
New
settlement.pywith adaily_settlementtable indata.db. Each row is one local day, computed fromhourly_summaryper hour:PV_EXTRA_LOAD_FACTOR(default 0.10) of the PV used in the house. That part is load PV made cheap, e.g. DHW boost or AC.Import prices that changed over time come from a tariff history (
TARIFF_HISTORY_CONFIG). Each period is either a flat price or atariff_engineYAML; seetariff_examples/tariff_history.yaml. If it's not set,TARIFF_IMPORT_CONFIGprices every day.Load-shift columns (
grid_charge_kwh,shifted_kwh,shift_profit_pln). They show grid energy charged into the battery, how much the house used later, and the profit from it.pv_originrule.grid_pool_kwh/_plnhold the end-of-day state). It's capped at the energy in the battery:BATTERY_CAPACITY_KWH(default 7.1) × the hour's max SoC.Keeping it current. After each new
hourly_summaryhour, today's and yesterday's rows are recomputed, plus any older day still missing RCE prices. Errors are only logged and never break the hourly backfill.Back-fill.
_backfill_daily_settlement.pyfills past days. It fetches missing RCE days from PSE intorce_prices.db.Page.
/statsis linked as 💰 Savings on the dashboard. It has:INVESTMENT_NET_PLN), % paid back, last 12 months, and a payback date projected from that rate;/stats/daily.csvto download every day.The data cell turns orange for months with missing hours or days.
Not included. Fixed monthly fees, and tracking the deposit balance or its expiry. The deposit can pay only the sales part of a bill, and the tariff files hold total gross prices.
Tests
tests/test_settlement.pycovers:tests/test_main_stats_routes.pycovers the/statspage with and without data, the CSV, and checks that the update hook never raises.Back-filled on the real
hourly_summarydata from 2024-08-12 to 2026-11-25: 817 days, every RCE day found. It's deployed on the Pi.🤖 Generated with Claude Code