Skip to content

feat(execute): write the low-power charge rate with an early-armed window where it is safe (#6190) - #6249

Open
upton68 wants to merge 2 commits into
springfall2008:mainfrom
upton68:feat/charge-rate-ahead-of-window
Open

upton68 wants to merge 2 commits into
springfall2008:mainfrom
upton68:feat/charge-rate-ahead-of-window

Conversation

@upton68

@upton68 upton68 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6190. The shape @springfall2008 asked for on #6211.

Problem

With low power on, a window armed set_window_minutes ahead opens at the inverter's maximum rate, because the rate is only worked out on the first cycle inside the window. On a Hanchu HESS-HY-S-10K that was ~9.8 kW for about a minute (#6190).

Fix

A new optional INVERTER_DEF capability, charge_rate_ahead_of_window (default False, in OPTIONAL_CAPABILITY_DEFAULTS): the inverter's charge rate does not throttle solar charging while no charge slot is running. Where it is set and low power is on, execute_plan() works out the rate with the same find_charge_rate() call the running window makes, taken at the window's start (current SoC, PV forecast over the whole window), and writes it with the early arm (charge_rate_ahead_of_window()). The window opens at that rate, and the running window re-solves it every cycle from the real SoC. The rate is written without claiming the fleet's direction: rate_owner stays "demand", so balance_inverters() doesn't treat batteries covering the house during the lead-in as cross-charging. Every other inverter type is unchanged: it keeps the early arm at max rate, so nothing loses the early arm and nothing has PV throttled before a window.

Why HanchuCloud qualifies

The fix only needs CHG_PWR_LMT not to throttle solar while no charge slot is running, which is the case during the lead-in (before charge_window_best[0]). A DC-coupled owner (panels on the Hanchu's own two strings, all slots 00:00–00:00, "Charging power maximum" 3,500 W) saw the battery charge at 4.88 kW from 5.23 kW of PV with 0.36 kW load and 0 kW grid. My AC-coupled unit behaves the same. The #6190 reporter saw solar held to the low-power rate inside a running slot, but without figures, so in-slot behaviour isn't relied on here.

Tests

  • charge_later_low_power_rate_ahead: a 2 h window 30 min ahead with the capability opens at 600 W (1 kWh per inverter in 120 − 10 min), with the rate owner left as "demand". Fails without the change (2000), and with a "charge" owner.
  • charge_later_low_power_no_rate_ahead / charge_later_rate_ahead_no_low_power: without the capability, or without low power, the early arm stays at max.
  • test_charge_rate_ahead_of_window_inverter_types: HanchuCloud only, and the flag reaches a real Inverter.
  • HANCHU_CAPABILITIES states it, and the Hanchu record/row check now also compares optional capabilities; the Growatt definition check excludes optional capabilities from its HanchuCloud reference.
  • ./run_all --quick passes.

Docs: a "Low power charging" bullet in the Hanchu ESS Cloud section of inverter-setup.md, a sentence under low power in customisation.md, and a debug journal entry (solar isn't throttled outside a slot; in-slot behaviour recorded as unsettled).

🤖 Generated with Claude Code

https://claude.ai/code/session_01K5medi1kA9icksXAqfi44v

…ndow where it is safe (springfall2008#6190)

With low power on, a window armed set_window_minutes ahead opened at the
inverter's maximum rate, as the rate is only worked out on the first cycle
inside the window: ~9.8 kW for about a minute on a Hanchu HESS-HY-S-10K.

New optional INVERTER_DEF capability charge_rate_ahead_of_window (default
False): the charge rate only limits charging while a charge slot is running,
not solar charging outside one. Where it is set, execute_plan() works out the
low-power rate with the same find_charge_rate() call the running window makes,
taken at the window's start (current SoC, PV over the whole window), and writes
it with the early arm, so the window opens at that rate. The running window
re-solves it every cycle.

HanchuCloud opts in: CHG_PWR_LMT held a DC-coupled 10K at ~0.6 kW of solar
inside a slot, while a DC-coupled unit with no slot set charged at 4.9 kW from
5.2 kW of PV with the limit at 3.5 kW. Every other type is unchanged, so none
loses the early arm and none has PV throttled before a window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K5medi1kA9icksXAqfi44v
@github-actions github-actions Bot added the BOT_REVIEW Trigger an autotriage label Nov 17, 2026

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated comment from the triage bot.

Reviewed head 7f088b85. Two findings, both posted inline; nothing in the body.

The shape is the one the maintainer asked for on #6190 (after declining #6211): an INVERTER_DEF capability gates writing the find_charge_rate() rate together with the early-armed window, and every other inverter type is untouched. The mechanism checks out on reading: the lead-in branch is only entered when minutes_now < minutes_start, so no charge slot is running when the rate is written; the find_charge_rate() call mirrors the running-window call (same curve, scaling, loss, PV-threshold and margin inputs, with minutes_now taken as the window start so the PV-over-window and minutes-left maths match); the tests cover capability+low-power, capability without low power, and low power without the capability, and the type test confirms the flag reaches a real Inverter and only HanchuCloud opts in. The two findings are a fleet-balancer side effect of the new owner claim, and a hardware-model contradiction between the new comment and the freeze rationale it cites.

Comment thread apps/predbat/execute.py Outdated
# charging is not held back, and the window opens at the low-power rate. The running
# window re-solves the rate every cycle from the real SoC.
charge_rate = self.charge_rate_ahead_of_window(inverter, window)
rate_owner = "charge"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated comment from the triage bot.

Claiming the rate as "charge" here also claims the fleet's direction, and during the lead-in that direction is wrong.

owner is read in exactly one place, balance_inverters() (utils.py, the claimed set just above fleet_should_discharge): if "charge" is in the owners, fleet_should_discharge is forced False and the meter-based fallback (during_discharge and spare_pv <= PV_SURPLUS_THRESHOLD) is skipped. When the cross-charge pass runs (balance_inverters_crosscharge, on by default once balance_inverters_enable is on), every inverter with power_enough_discharge (battery power >= 50 W) is treated as working against the fleet and its intent[id]["discharge_rate"] is zeroed, with a cross_charge hold published and logged.

Concrete failure: a two-inverter fleet (or a mixed fleet containing one HanchuCloud unit), switch.predbat_balance_inverters_enable on, low power on, and a charge window 30 minutes ahead. The batteries are covering the house at, say, 500 W each. This line sets the owner to "charge", so fleet_should_discharge becomes False, both inverters are held as cross-chargers, and their discharge rate goes to 0 for the whole lead-in (up to set_window_minutes, 30 by default) until the window actually opens — the batteries stop serving the house and the site imports. Before this change the owner stayed "demand" here, so the balancer inferred the direction from the meters and read the situation correctly. The rate is still written without an owner (apply_inverter_rates() uses charge_rate alone), so leaving rate_owner at its "demand" default — or adding a distinct owner the balancer treats as demand — avoids the flip. The PR's tests exercise a single inverter with balancing off, so they do not cover this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Fixed in fcf7e48: the rate written with the early arm leaves rate_owner at "demand" (apply_inverter_rates() writes charge_rate whatever the owner), so balance_inverters() keeps inferring direction from the meters during the lead-in. charge_later_low_power_rate_ahead now also asserts the owner stays "demand"; it fails with the "charge" claim restored.

Comment thread apps/predbat/hanchu.py Outdated
"target_soc_used_for_discharge": True,
# CHG_PWR_LMT only caps charging while a charge slot is running (the same reason as
# support_discharge_freeze above), so the low-power rate can go out with the early-armed window
# without holding back solar before it (batpred#6190).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated comment from the triage bot.

The new comment contradicts the rationale it points at, in the same dict. The support_discharge_freeze comment above says CHG_PWR_LMT "only limits charging from the grid, so a zero charge rate cannot stop solar filling the battery" — that is, it does not cap solar at all. This one says CHG_PWR_LMT "only caps charging while a charge slot is running", i.e. inside a slot it does cap solar (the new debug-journal bullet states it outright: "inside one it holds solar too"). Both cannot be true, and "the same reason as support_discharge_freeze above" is not the same reason.

If the new claim is the right one it has consequences beyond this comment: a hold/freeze is written as a charge slot at zero power (docs/inverter-setup.md, "Holds"), so a zero rate inside a running slot would stop solar charging — which is exactly what support_charge_freeze: True and support_discharge_freeze: False conclude it does not do (#5665). The same claim is repeated in the HanchuCloud row comment in config.py and in the journal bullet under the Hanchu section.

I could not confirm either reading from the code — this is hardware behaviour and I did not replay the #6190 logs. Whatever the device does, the comment should not assert it shares a reason with the freeze rationale when the two stated reasons differ: either update that rationale and the capability flags it justifies, or reword this to the weaker claim the fix actually relies on, that CHG_PWR_LMT does not throttle solar outside a running slot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point. Reworded in fcf7e48 to the weaker claim the fix relies on and the evidence shows: CHG_PWR_LMT does not throttle solar charging while no charge slot is running (DC-coupled unit, 4.88 kW from 5.23 kW of PV with the limit at 3.5 kW and no slot set). The same wording is now used in config.py, inverter.py and both docs. The in-slot report from #6190 has no figures and sits uneasily with support_discharge_freeze: False (#5665), so the journal now records it as unsettled rather than asserting it, and the freeze flags are untouched.

…solar claim the fix relies on (springfall2008#6190)

- The rate written with an early-armed window no longer claims rate_owner
  "charge". The fleet is not charging yet, and balance_inverters() reads a
  "charge" owner as the fleet's direction: batteries covering the house in
  the lead-in would be treated as cross-charging and have their discharge
  rate zeroed. apply_inverter_rates() writes charge_rate whatever the owner.
  The rate-ahead test now checks the owner stays "demand".
- Comments and docs now state only what the fix relies on and the evidence
  shows: CHG_PWR_LMT does not throttle solar charging while no charge slot is
  running. The in-slot observation is recorded as unsettled in the journal,
  as it sits uneasily with support_discharge_freeze: False (springfall2008#5665).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K5medi1kA9icksXAqfi44v

This branch has not been deployed

No deployments
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.

Hanchu: charging starts at maximum power before low-power rate takes effect

3 participants