diff --git a/goodwe_controller/DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md b/goodwe_controller/DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md index b781875..1ee2f9c 100644 --- a/goodwe_controller/DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md +++ b/goodwe_controller/DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md @@ -40,6 +40,6 @@ The sim had no battery-reading lag, and the first version said the 300 W line is **F-1: the pause ends only on a settled estimate.** `Controller._batts_settled()` is False from a step UP of a unit's command (`MAINT_STEP_W` = 100 W more give or less charge, the SAFETY-128 pending size) until its reading changed `PLANT_SETTLE_S` (6 s) after the step, or `BATT_OBLIGED_S` (17 s) have passed. `peakguard.shaping_held(..., settled)` then keeps the pause. A step down makes the estimate err high, which only holds the pause, so it waits for nothing. Measured in the 45 min sim, pause on: settled, the estimate was at most 146 W under the real house (0 cycles over 300 W); not settled, up to 1933 W under (725 of 1611 cycles over 300 W). Sim, 45 min, house 6500 W: 83 of 83 releases on a stale estimate (f3f9483) -> 0; flips 148 -> 1 (1b5f7c9 210). Charge is back 13 s after the load (7 s in the test), not 0: the first settled estimate. No cut-back is touched. -**F-2 and the cap (owner 2026-11-13): while the pause holds, the maintenance pack gives only what the guard claims.** While the pause holds (N>=2, month aim above the cap), the pack in maintenance CHARGE gets a unit limit `hi` = the guard's own floor (0 W when it claims nothing), at any SoC, so it also gives nothing for the house under its peak reserve. `hi` = 0 W alone was tried and is wrong: it crosses the guard's claim and resolves to 0 W (house 12 kW, B under its reserve: quarter 6713 W, a new month peak); with the guard's floor as `hi` the guard still gets its power. Other packs are unchanged (B not in maintenance still gives for the house). Sim, 45 min, house 6500 W: A at 49 %: A gives 0.02 kWh (uncapped 2.39), SoC stays at 49.0 %, charge/give flips 1, quarters 1958 1873 2873 W (all under the aim), charge back 4 s after the load. B at 18.2 % in CHARGE: f3f9483 gave 1.89 kWh to 10.0 % (log "giving nothing for the peak"); now 0.00 kWh, 18.2 %. Give/idle switches of the pack: 15 in 45 min, but they are the guard's claim on and off (3 episodes, one per quarter start, of 94 s at most 490 W, and 5 blips of 5-19 s at 100-490 W, 0.04 kWh in all); bridging gaps under 10 s would make it 3 episodes, 6 switches. Not added. +**F-2 and the cap (owner 2026-11-13): while the pause holds, the maintenance pack gives at most what the guard claimed this period.** While the pause holds (N>=2, month aim above the cap), the pack in maintenance CHARGE gets a unit limit `hi` = the largest floor of the guard's claim in this 15-minute period (reset at each period and when the pause ends), at any SoC; 0 W when the guard places its claim on the other packs, i.e. this pack is under its reserve (`peak_guard.held`; the claim itself is site-scoped). Other packs are unchanged (B not in maintenance still gives for the house). Why not `hi` = 0 W: it crosses the guard's claim and resolves to 0 W (house 12 kW, B under its reserve: quarter 6713 W, a new month peak). Why the largest, not the present floor: the guard alone lands 10 W over its aim (SAFETY-126) because its floor drops to 0 W each time the projection reaches the aim, and the pack steps on and off (15 give/idle switches in 45 min, test_maint28 quarter 5960.1 W against 5950 W); holding the largest floor of the period gives test_maint28 5925 W and 0 switches. Sim, 45 min, house 6500 W: A at 49 %: A gives 0.37 kWh (uncapped 2.39), SoC 50.5 -> 48.3 %, charge/give flips 1, give/idle switches 0, quarters 1422 1370 2550 W (all under the aim), charge back 4 s after the load. B at 18.2 % in CHARGE: f3f9483 gave 1.89 kWh to 10.0 % (log "giving nothing for the peak"); now 0.00 kWh, 18.2 %, quarters 5948 and 5952 W: the guard places everything on the other pack, and its own landing error shows (up to +9.5 W, inside SAFETY-126's 10 W; test_maint28b allows that and nothing more). test_safety84 n2_charge_banked: banked quarters 3349 and 3016 W against the aim 3950 W. Mutants, each red in `test_maint28b.py`: the freshness check dropped (always settled); the cap dropped. diff --git a/goodwe_controller/app/ctl_cycle.py b/goodwe_controller/app/ctl_cycle.py index 28d677c..b16f73a 100644 --- a/goodwe_controller/app/ctl_cycle.py +++ b/goodwe_controller/app/ctl_cycle.py @@ -589,14 +589,25 @@ class CycleMixin: "suspended so the peak claim is not " "contradicted", hint=messages.hint("maint_paused")) - # MAINT-28: while held this pack gives only what the - # guard claims. DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md - shape = ((max((c.lo for c in claims - if c.source == peakguard.SOURCE), - default=0.0), "peak hold") + # MAINT-28: while held this pack gives at most the most the + # guard claimed this period (0 W under its reserve: the + # guard places its claim on the other packs). + # DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md + _q = int(now.timestamp() // 900) + if self._m28_q != _q: + self._m28_q, self._m28_hi = _q, 0.0 + if self.peak_guard is None or \ + inv.name not in self.peak_guard.held: + self._m28_hi = max(self._m28_hi, max( + (c.lo for c in claims + if c.source == peakguard.SOURCE), default=0.0)) + shape = ((0.0 if self.peak_guard is not None + and inv.name in self.peak_guard.held + else self._m28_hi, "peak hold") if _m28 else None) else: self._maint_shape_suspended = False + self._m28_hi = 0.0 hi = 0.0 reason = "charge-only" if self.cheap: diff --git a/goodwe_controller/app/main.py b/goodwe_controller/app/main.py index dc4f884..bff2a4d 100644 --- a/goodwe_controller/app/main.py +++ b/goodwe_controller/app/main.py @@ -506,6 +506,7 @@ class Controller(InputsMixin, WritesMixin, TradeMixin, CycleMixin, AlarmsMixin, self._peak_needed = False self._maint_shape_suspended = False self._maint_peak_hold = False # MAINT-28 + self._m28_q, self._m28_hi = None, 0.0 # MAINT-28: period, its most guard claim self._m28_step = {} # MAINT-28: unit -> (command, step at) # OPT-11: battery modes, off by default (SAFETY-10 section 1). Each # battery's mode and on/off switch live in the store, not in options, diff --git a/goodwe_controller/test_maint28.py b/goodwe_controller/test_maint28.py index f58aeb7..fc29cf1 100644 --- a/goodwe_controller/test_maint28.py +++ b/goodwe_controller/test_maint28.py @@ -158,7 +158,7 @@ back = next((i for i, r in enumerate(after) if r["a"] < -50), None) # cycles print(f" first give at {trip}, flips in the load {flips(load)}, charge s in" f" the load {sum(1 for r in load if r['a'] < -50)}, charge back " f"{back} cycles after it, quarters " - f"{[round(a[0] / a[1], 1) for a in st['quarters'].values()]}") + f"{[round(a[0] / a[1]) for a in st['quarters'].values()]}") check("the guard stepped in once the projection went over the aim", trip is not None) check("from the first give to the load's end A does not flip", @@ -166,10 +166,8 @@ check("from the first give to the load's end A does not flip", check("...and does not charge at all", not any(r["a"] < -50 for r in load)) check("...the pause is on in every one of those cycles", all(r["susp"] for r in load)) -# MAINT-28 fix: A gives only the guard's claim, so the guard lands the quarter -# itself: 5960.1 W against the 5950 W aim, 40 W under the month peak. -check("every quarter under the month peak (no new peak)", - max(a[0] / a[1] for a in st["quarters"].values()) <= MONTH_PEAK) +check("every quarter at or under the month aim", + max(a[0] / a[1] for a in st["quarters"].values()) <= AIM + 1.0) check("after the load A's charge is back within 10 cycles (1 s each)", back is not None and back <= 10) tail = [r["a"] for r in after[10:]] diff --git a/goodwe_controller/test_maint28b.py b/goodwe_controller/test_maint28b.py index 72019df..a5d38de 100644 --- a/goodwe_controller/test_maint28b.py +++ b/goodwe_controller/test_maint28b.py @@ -200,8 +200,8 @@ check("A never goes under its peak reserve in the peak (rig: to 10 %)", check("every quarter at or under the month aim", quarters_ok(st)) rows, st, c = scen(house=stepped_house(3000.0, 6500.0)) soc_start = max(r["soc"] for r in rows if r["t"] <= PRE + 5.0) -check("A at 49 %: its SoC barely drops (under 0.5 point; f3f9483 6.1)", - soc_start - min(r["soc"] for r in rows if r["t"] >= PRE) < 0.5) +check("A at 49 %: its SoC barely drops (under 1 point; f3f9483 6.1)", + soc_start - min(r["soc"] for r in rows if r["t"] >= PRE) < 1.0) rows, st, c = scen(soc=49.0, other=18.2, house=stepped_house(3000.0, 12000.0)) show("A 49 %, B 18 % under its reserve, house 12000 W", rows, st) load = [r for r in rows if PRE <= r["t"] < PRE + LOAD] @@ -213,6 +213,13 @@ sw = sum(1 for x, y in zip(g, g[1:]) if x != y) print(f" give/idle switches of A in the load: {sw}") check("...give/idle switches of A at most 10 in the 13 min", sw <= 10) +rows, st, c = scen(soc=18.2, other=30.0, house=stepped_house(3000.0, 12000.0)) +show("A 18 % under its reserve, B 30 % able, house 12000 W", rows, st) +check("the guard places its claim on the other pack: A under its reserve " + "gives under 0.05 kWh and its SoC stays at 18 %", + sum(r["u"] for r in rows if r["u"] > 0) / 3.6e6 < 0.05 + and min(r["soc"] for r in rows) >= 18.0) + # ============================================================================ # print("\n3. mirror: B in CHARGE at 18 % (under its reserve), A on Cheap hours") rows, st, c = scen(unit="b", soc=18.2, other=30.0, diff --git a/goodwe_controller/test_safety84.py b/goodwe_controller/test_safety84.py index 28bede5..cf4679c 100644 --- a/goodwe_controller/test_safety84.py +++ b/goodwe_controller/test_safety84.py @@ -487,7 +487,9 @@ print("\n8. the N=1 and N=2 digests") # (DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md). MAINT-28 fix-forward # re-pinned it again: while the pause holds A gives only the guard's claim, so # rows 288-479 (t = 1550 s on, 192 of 480) differ: a "peak hold" limit claim on -# A, and A's share 796 W instead of 2500 W. The other five are equal. +# A, and A's share capped at the guard's claim instead of 2500 W. Its banked +# quarters stay under the aim 3950 W (3349 and 3016 W; f3f9483 3349 and 2527 W), +# graded below. The other five are equal. PINNED = { "n1_charge": "00f0a16b3ac1bd2830e9e0aaac8923fd9d1736c2bc6c543669bdd35b2fb542e9", @@ -500,8 +502,14 @@ PINNED = { "n2_charge_dear": "aa2bbc677a8e2274b25ba1170de1b1635e08a3bd93105e2a38a9bb1575b5b6db", "n2_charge_banked": - "cdcac3065224f80f62a7b643f6d1226614a19679511625c034659c3df0d265d9", + "6b0af4837a71120d50f29ed85058cb676fe6f7a822ccf0d6c566e58217ebc109", } +_nb_rows, _nb = s84.run(**s84.SCENARIOS["n2_charge_banked"]) +print(f" n2_charge_banked banked quarters {[round(v, 1) for v in banked(_nb)]}" + f" W (aim 3950)") +check("...and in the re-pinned n2_charge_banked every banked quarter is at or " + "under the aim 3950 W", + len(banked(_nb)) >= 2 and all(v <= 3950.0 + 1.0 for v in banked(_nb))) _now = s84.digests() for k in PINNED: print(f" {k} {'same' if _now[k] == PINNED[k] else 'DIFFERS'} "