Skip to content

fix(history): count the battery-storage tax figure in proportion - #1958

Merged
frahlg merged 1 commit into
masterfrom
simple-battery-return
Nov 3, 2026
Merged

frahlg merged 1 commit into
masterfrom
simple-battery-return

Conversation

@frahlg

@frahlg frahlg commented Nov 3, 2026

Copy link
Copy Markdown
Member

Why

Fredrik, 3 Nov 2026: the figure for Skatteverket's energy tax refund after battery storage (11 kap. 13 § LSE) gave nothing, and it should be simple to work out. The strict order from #1953 counted what the house took from a battery as grid energy first and the export as other energy first. With solar in the battery that leaves almost nothing. The home box shows 0 kWh for 2026.

The law and Skatteverket name no method. The owner must be able to show how the figure was reached, and the hourly CSV still does that.

What

  • Each battery's account follows what it holds and how much came from the grid. Whatever leaves, to the house or the grid, carries the grid's share of what the battery held.
  • Energy enters after the battery's efficiency over the year (what came out over what went in, at most 1), so losses are never refunded. This replaces the least efficiency per run of readings.
  • The account never holds more than a full battery; above that both parts shrink in proportion.
  • Within an hour the charge mixes in before the discharge, since the ledger does not say which came first.
  • Unchanged: the hourly bounds (solar, a discharging car and other batteries count first), the complete-hour rules, one account per battery, the start and resets full of other energy, the size check.
  • Web: the tile says the battery "gave back N % of its charge" instead of "at least".

Evidence (this Mac)

  • make verify: vet, tests and build clean. npm test: 900 pass.
  • go/internal/batteryreturn tests rewritten for the new rule: an emptied battery filled from the grid returns all it sends (9 + 9 kWh); what leaves carries the grid share (5 kWh at ⅓ → 1.67 kWh); the in-hour order (4/9 share → 2.22 kWh); half the export means half the return; a half-size battery returns half; a gap forgets only that battery's account. Stored solar sent out and grid energy used at home still return 0.
  • The home box's 2026 hourly CSV (7,358 hours, 2,289 complete, from July) replayed through the new account: 42.4 kWh (old 0). In the same hours the battery took 332 kWh from the grid and sent at most 85 kWh to it.
  • 2025 from Home Assistant (Sungrow counters, Jan–Nov; the box has no 2025 hours): the same rule gives about 7.5 kWh, about 3 kr.
  • Browser: web/ served locally, read-only proxy to the home box. The tile renders "Counted with a 9.6 kWh battery that gave back 73 % of its charge." The figure there is still the box's old code.

Note

#1956 (planner, open, not recommended for merge) starts from the strict order's account. If it goes ahead, it should follow this rule instead.

🤖 Generated with Claude Code

The strict order counted the house's use of a battery as grid energy first
and its export as other energy first, so a battery with solar almost never
got a figure: the home box gave 0 for 2026. Now whatever leaves a battery,
to the house or the grid, carries the grid's share of what it held, and
energy enters after the battery's efficiency over the year, so losses are
never refunded. Within an hour the charge mixes in before the discharge.
The hourly bounds, complete-hour rules and per-battery accounts stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T14:11:01.364513Z b01283b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit be11e36 into master Nov 3, 2026
22 checks passed
@frahlg
frahlg deleted the simple-battery-return branch November 3, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant