Skip to content

Site: drop stale battery grid charge limit without a dynamic tariff#29964

Closed
andig wants to merge 2 commits into
masterfrom
fix/battery-gridcharge-limit-stale
Closed

Site: drop stale battery grid charge limit without a dynamic tariff#29964
andig wants to merge 2 commits into
masterfrom
fix/battery-gridcharge-limit-stale

Conversation

@andig
Copy link
Copy Markdown
Member

@andig andig commented May 17, 2026

Fixes #29961

Problem

A user switched from a dynamic electricity tariff to a static one and could no longer remove the battery grid-charge price cap — it stayed visible with no way to clear it.

Root cause

Three settings depend on a dynamic tariff but are persisted and restored unconditionally at boot, while their UI editors are gated on smartCostAvailable / smartFeedInPriorityAvailable (= a dynamic tariff). After switching to a static tariff the editor — and its remove control — is hidden, leaving a stale limit that the user cannot clear:

Setting Requires
batteryGridChargeLimit (site) dynamic planner tariff
smartCostLimit (loadpoint) dynamic planner tariff
smartFeedInPriorityLimit (loadpoint) dynamic feed-in tariff

Beyond the UI, a stale batteryGridChargeLimit / smartCostLimit can still actively drive grid/loadpoint charging against a configured fixed price.

Fix

In the site's settings restore, once tariff availability is known:

  • only reapply the persisted batteryGridChargeLimit when the planner tariff is dynamic, otherwise clear the stale value;
  • clear stale loadpoint smartCostLimit / smartFeedInPriorityLimit when the respective tariff is not dynamic.

The loadpoint restore runs before the loadpoint has any tariff context, so the loadpoint limits are reconciled from the site.

Verification

  • go build ./core/..., go vet ./core/, go test ./core/, gofmt — all clean.

🤖 Generated with Claude Code

The battery grid charge price limit is a persisted setting. When a user
switches from a dynamic to a static tariff, the limit survives in the
database but the UI editor for it is hidden (it requires a dynamic
tariff), leaving the user unable to remove a cap that is still shown in
the energy flow. A stale limit could also still trigger grid charging
against a configured fixed price.

On restore, only reapply the persisted limit when the planner tariff is
dynamic; otherwise clear the stale value.

Fixes #29961

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • When clearing a stale BatteryGridChargeLimit, consider handling the error returned by settings.SetString so that a failure to clear the persisted value doesn’t silently leave an inconsistent state.
  • Instead of SetString(keys.BatteryGridChargeLimit, ""), consider using a dedicated delete/clear method (if available) so the storage semantics reflect that the limit is absent rather than an empty string.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When clearing a stale `BatteryGridChargeLimit`, consider handling the error returned by `settings.SetString` so that a failure to clear the persisted value doesn’t silently leave an inconsistent state.
- Instead of `SetString(keys.BatteryGridChargeLimit, "")`, consider using a dedicated delete/clear method (if available) so the storage semantics reflect that the limit is absent rather than an empty string.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@andig andig requested a review from naltatis May 17, 2026 08:30
@andig andig added the bug Something isn't working label May 17, 2026
…tariff

Same stale-state issue as the battery grid charge limit: the loadpoint
smartCostLimit and smartFeedInPriorityLimit are persisted and restored
unconditionally, but their UI editors require a dynamic tariff. After
switching away from a dynamic tariff the limits linger with no way to
remove them, and a stale smartCostLimit still drives charging.

The loadpoint restore runs before it has tariff context, so clear the
stale limits from the site once tariff availability is known.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@andig
Copy link
Copy Markdown
Member Author

andig commented May 17, 2026

@naltatis fixed two more occurrences of this kind- anything else you have in mind?

@naltatis
Copy link
Copy Markdown
Member

We already had a solution for this in place. We show a warning dialog with the option to remove the existing limit when we detect that there is an unusable limit. This can either by because the battery is not controllable any more or your tariffs have changed. The battery grid charge path was broken. See fix here: #30013

I'd prefer the manual way (UI) over the auto-cleanup way. Doing this on boot has the potential of deleting limits as an effect of a temporary tariff initialization error or reconfiguration for tariffs by the user (remove > add).

@andig andig closed this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the price cap for charging home battery

2 participants