Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ledger-hourly-four-years.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

The energy ledger keeps hourly totals for four years instead of two, then daily totals. Skatteverket's refund of energy tax after battery storage is worked out hour by hour for a calendar year and may be claimed until three years after the year ends; with two years of hours, the start of an older year had only daily totals and counted as incomplete.
7 changes: 5 additions & 2 deletions go/internal/state/energy_ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ const (
// Keep recent ledger detail aligned with the legacy history hot tier.
// Older energy is additive, so hourly totals preserve its contract while
// bounding history growth. Daily totals remain after the hourly horizon.
// Skatteverket's battery refund is worked out hour by hour for a
// calendar year and may be claimed until three years after it ends, so
// the hours of a whole year must last four.
EnergyLedgerDetailedRetention = 30 * 24 * time.Hour
EnergyLedgerRetention = 2 * 365 * 24 * time.Hour
EnergyLedgerRetention = 4 * 366 * 24 * time.Hour
EnergyLedgerRollupBucketMS = int64(time.Hour / time.Millisecond)
EnergyLedgerDailyBucketMS = 24 * EnergyLedgerRollupBucketMS
)
Expand Down Expand Up @@ -505,7 +508,7 @@ func (s *Store) LoadEnergyHistoryContext(ctx context.Context, q EnergyHistoryQue
}

// PruneEnergyLedger keeps five-minute detail for 30 days, hourly totals for
// two years and daily totals thereafter. Energy and its source/quality remain
// four years and daily totals thereafter. Energy and its source/quality remain
// intact. Each completed hour or day commits before the next begins.
func (s *Store) PruneEnergyLedger(ctx context.Context, now time.Time) (hourly, daily int64, err error) {
for _, tier := range []struct {
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ <h3>What stands out</h3>
<tbody id="battery-return-rows"></tbody>
</table>
</section>
<p class="energy-history-note">The figure is grid electricity that the battery stored and later sent back to the grid. Where the readings cannot tell where energy went, FTW counts low: solar counts first in every hour, what the house takes from the battery counts as grid energy first and what goes to the grid as other energy first, losses count as other energy, and an hour counts only when every meter read all of it. The figure assumes FTW reads every solar inverter, battery and car charger on the site, and it uses the battery size set today. You can apply within three years after the year ends, but FTW keeps hourly readings for two, so download the CSV soon after the year ends and keep it with your application. <a href="https://www.skatteverket.se/privat/skatter/skattpabransleochel/aterbetalningavskattpaelefterbatterilagring.4.5fb2fa71a0b0adb74a23d8.html" target="_blank" rel="noopener">Skatteverket's rules</a></p>
<p class="energy-history-note">The figure is grid electricity that the battery stored and later sent back to the grid. Where the readings cannot tell where energy went, FTW counts low: solar counts first in every hour, what the house takes from the battery counts as grid energy first and what goes to the grid as other energy first, losses count as other energy, and an hour counts only when every meter read all of it. The figure assumes FTW reads every solar inverter, battery and car charger on the site, and it uses the battery size set today. You can apply within three years after the year ends, and FTW keeps the hourly readings that long. Keep the CSV with your application. <a href="https://www.skatteverket.se/privat/skatter/skattpabransleochel/aterbetalningavskattpaelefterbatterilagring.4.5fb2fa71a0b0adb74a23d8.html" target="_blank" rel="noopener">Skatteverket's rules</a></p>
</div>
</details>

Expand Down
Loading