SAFETY-135 round 2: the first guard stop in a period may restart once; tests and docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bdqr7PiaHcBnzPituu2yTC
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
66d8777b39
commit
4066624cce
@@ -1,74 +1,116 @@
|
||||
# SAFETY-135 - a young 15-minute period does not cost the night charge the whole period
|
||||
# SAFETY-135 - one guard stop does not cost the night charge the whole period
|
||||
|
||||
**Status: for review.** Code: `Controller._mode_roles()` and
|
||||
`Controller._give_falling()` (`app/ctl_trade.py`), `modetrade.decide(young=)`,
|
||||
`YOUNG_S`, `GAVE_S` (`app/modetrade.py`). Tests: `test_safety135.py`. Battery
|
||||
modes only. No option, no text change, no change to the peak guard.
|
||||
**Status: for review, round 2.** Code: `Controller._mode_roles()` and
|
||||
`Controller._give_falling()` (`app/ctl_trade.py`), `modetrade.decide(wait=)`,
|
||||
`RESTART_S`, `YOUNG_S`, `GAVE_S`, `WAIT_WORDS` (`app/modetrade.py`). Tests:
|
||||
`test_safety135.py`. Battery modes only. No option, no change to the peak
|
||||
guard.
|
||||
|
||||
**Problem.** In the first seconds of a period the guard's projection is almost
|
||||
only the last reading (`held_w`). Two cases seen on TEST-23:
|
||||
**Problem.** A grid charge the peak guard stops stays off to the period's end
|
||||
(the OPT-11 latch). Three cases seen on TEST-23:
|
||||
- *A spike at a period's start* (UX-77 I-1, x10): a 1-3 s spike, or a charge
|
||||
still at full power from the end of the last period, makes the guard project
|
||||
4.3-6.6 kW and cut the night charge. The cut is right. But a cut charge
|
||||
stays off to the period's end (the OPT-11 latch), so one 2 s spike cost 15
|
||||
4.3-6.6 kW and cut the charge. The cut is right, but one 2 s spike cost 15
|
||||
minutes of charge, about 0.16 kWh per trip on the rig.
|
||||
- *A start at the tariff edge* (SAFETY-136 rig F-4, x1): a give ends at 01:00
|
||||
and the cheap run starts. The battery reading drops at once, the meter
|
||||
reading a few seconds later. In between, grid + batteries reads the house
|
||||
too low, so the charge room is too big. The charge starts and the guard cuts
|
||||
it 4-61 s later, and the latch then holds it off for the period.
|
||||
- *A start at the tariff edge* (sim, 5 s meter): a give ends at 01:00 and the
|
||||
cheap run starts. The battery reading drops at once, the meter a few
|
||||
seconds later. In between, grid + batteries reads the house too low, the
|
||||
room too big: the charge starts and the guard cuts it within seconds.
|
||||
- *An oven cycling under a cheap-hours charge* (SAFETY-136 rig run C/s5b, x1):
|
||||
the charge started at 01:00:32 in an oven pause and the guard cut it at
|
||||
01:01:31 when the oven came back on (5.3 kW projected). The cut is right,
|
||||
but the charge stayed off to 01:15.
|
||||
|
||||
**Decision.** Two small rules, both only in a young period (its first
|
||||
`YOUNG_S` = 60 s):
|
||||
1. *A stop does not latch.* A charge the guard or a measured headroom stops in
|
||||
a young period may not start again until the period is 60 s old; then the
|
||||
normal start rule (guard clear, over `START_W` of headroom) decides. A stop
|
||||
after 60 s latches to the period's end as before, so there is at most one
|
||||
restart per period and the OPT-11 flip guard keeps its job.
|
||||
2. *No start while a give is still falling.* While the batteries give over
|
||||
`START_W` less than they did in the last `GAVE_S` = 15 s, no charge starts:
|
||||
the meter may not show that drop yet. 15 s covers a 5 s meter twice plus
|
||||
Home Assistant's own delay. A give that falls by `START_W` or less does not
|
||||
hold the start: the error it leaves is under the smallest charge worth
|
||||
starting.
|
||||
**Decision.**
|
||||
1. *The first guard stop in a period does not latch.* A charge the peak guard
|
||||
stops (or a measured headroom stops in the period's first `YOUNG_S` = 60 s)
|
||||
may start again `RESTART_S` = 60 s after that stop,
|
||||
under the normal start rule (guard clear, headroom over `START_W`), but not
|
||||
in the period's last 60 s: there the room is the deficit times 900/s left,
|
||||
and a restart overshot by 15 W in the owner-shape night (N=2, 01:00). A
|
||||
second stop latches to the period's end, so there is at most one restart
|
||||
per period and the OPT-11 flip guard keeps its job. A measured headroom
|
||||
stop later in the period latches at once, and an unmeasured headroom
|
||||
(OPT-15) on its second stop, as before. Why only guard stops later on: all
|
||||
three rig cases are guard stops, while a headroom that falls to 0 W mid
|
||||
period is the slow loss of room the OPT-11 latch was made for (the
|
||||
2026-09-09 flips), so freeing it buys no case and risks that flip.
|
||||
Three existing checks pinned "one start per period" and move with this:
|
||||
`test_modes_p3.py` (a house swinging 2.0/3.9 kW each minute: now at most
|
||||
two starts per period), `test_price_run_fixes.py` 1c (a 1-minute 3.7 kW
|
||||
load: one restart after 60 s), and the `n1_ch` digest in
|
||||
`test_modes_p4.py` (only the waiting reason word moved, "(peak)" for
|
||||
"(headroom)"; with this card off it is OPT-15's pin again).
|
||||
2. *No start while a give is still falling.* In a period's first `YOUNG_S`,
|
||||
while the batteries give over `START_W` less than they did in the
|
||||
last `GAVE_S` = 15 s, no charge starts: the meter may not show that drop
|
||||
yet. A smaller drop does not hold the start.
|
||||
|
||||
The guard itself is not touched: its claim, floor and projection are the same
|
||||
code, so a real over-aim load is cut on the same cycle as before. A running
|
||||
charge is never held by rule 2.
|
||||
The guard is not touched (claim, floor, projection), so a real over-aim load
|
||||
is cut on the same cycle as before, and a running charge is never held. While
|
||||
a start waits, the status row says "grid charge paused, it tries again in a
|
||||
minute" or "grid charge waits for the meter to catch up".
|
||||
|
||||
**Options weighed.**
|
||||
- *A minimum data window before the latch* (no latch in the first N s): this
|
||||
is rule 1. Alone it lets the edge start flap once more.
|
||||
- *No start in a young period within 60 s of a give or a guard action*: also
|
||||
stops the edge flap, but delays every run start that follows a give. In the owner-shape night sim it
|
||||
charged 0.018 kWh (N=1) and 0.003 kWh (N=2) less than base. Rule 2 holds the
|
||||
start only while the give is still falling, and charges the same as base.
|
||||
- *Cutting the young charge room by the recent give* (instead of holding the
|
||||
start): it double-counts once the meter catches up, cut a running charge 3 s
|
||||
after its start in the 1 s meter edge run, and so flapped where base did not.
|
||||
- *Round 1: only a stop in the first 60 s does not latch.* Missed the rig
|
||||
oven case, cut at 91 s (review M-1).
|
||||
- *Re-evaluation each cycle with no latch*: brings back the 13 flips in 4
|
||||
minutes the latch was made for (2026-09-09 replay).
|
||||
- *A hysteresis band on the start*: does not help at the edge. The error there
|
||||
is the readings' age, not a small room.
|
||||
- *Restart at once after the first stop*: two flips in 20 s with spikes at
|
||||
0/20 s (`test_safety135.py` part 5 fails on it).
|
||||
- *No start in a young period within 60 s of a give or a guard action*:
|
||||
0.018 kWh (N=1) and 0.003 kWh (N=2) less than base on the owner night.
|
||||
- *Cutting the young room by the recent give*: double-counts once the meter
|
||||
catches up and flapped on a 1 s meter where base did not.
|
||||
- *A hysteresis band*: the edge error is the readings' age, not a small room.
|
||||
|
||||
**Numbers** (`scratch/SAFETY-135/dev/s135_sim.py`, real `cycle()`, TEST-23-like
|
||||
lag, 1 s cycle, two 2.5 kW batteries, cap 3 500 W, aim 3 450 W; grid
|
||||
average over each period as the sim saw it):
|
||||
lag, 1 s cycle, two 2.5 kW batteries unless said, cap 3 500 W, aim 3 450 W;
|
||||
the sim's grid average per period):
|
||||
|
||||
| Scenario | Base: paused s, kWh, flaps, top period | Head |
|
||||
|---|---|---|
|
||||
| (a) 4 s spike at 01:30 and 01:45, house 2.8 kW | 1 197 s, 0.330 kWh, 1, 3 458 W | 135 s, 0.537 kWh, 0, 3 458 W |
|
||||
| (a) 4 s spike at 01:30 and 01:45, house 2.8 kW | 1 197 s, 0.330 kWh, 1, 3 458 W | 139 s, 0.537 kWh, 0, 3 458 W |
|
||||
| (b) 01:00 edge after a give, 5 s meter, house 3.0 kW | 882 s, 0.006 kWh, 1, 3 009 W | 21 s, 0.119 kWh, 0, 3 464 W |
|
||||
| (b) the same, house 2.4 kW | 0 s, 0.266 kWh, 0, 3 461 W | 11 s, 0.266 kWh, 0, 3 461 W |
|
||||
| Rig s5b (5 kW + 4.6 kW, oven), 1 s / 5 s meter | 838 / 886 s, 0.054 / 0.035 kWh, 2 224 / 2 123 W | 793 / 793 s, 0.075 / 0.084 kWh, 2 299 / 2 286 W |
|
||||
| (c) +4 kW for 5 min from 01:30:20 | cut 01:30:22, 0.387 kWh | cut 01:30:22, 0.492 kWh |
|
||||
| Owner-shape night, N=1 / N=2 | 5.510 / 6.048 kWh, top 3 454 / 3 453 W | 5.510 / 6.048 kWh, 3 454 / 3 453 W |
|
||||
| Owner-shape night, N=1 / N=2 | 5.510 / 6.048 kWh, top 3 454 / 3 453 W | 5.510 / 6.169 kWh, 3 454 / 3 453 W |
|
||||
| Owner-shape day, N=1 / N=2 | top 331 / 145 W | the same |
|
||||
|
||||
The add-on's own period averages in `test_safety135.py`: 3 450.0 W in the
|
||||
spike period (base 2 807.9 W, the charge lost), 3 450.0 W in the 01:00 period
|
||||
(base 2 996.5 W at 3.0 kW). Over the aim by a few watts in the sim's grid
|
||||
average is the landing error base has too (SAFETY-126).
|
||||
In s5b the restart at 01:02:32 is cut again by the oven at 01:03:17 and then
|
||||
latches: one restart, as designed. A +4 kW load from second 30, 57, 59, 60 or
|
||||
61 (N=1 and N=2) is cut on the same cycle as base, the charge restarts only
|
||||
after the load ends, and the period lands at 3 450.0 W (base 3 037-3 350 W).
|
||||
The add-on's own period averages in `test_safety135.py` are at or under the
|
||||
aim + 2 W in every part.
|
||||
|
||||
**Sensitivity** (one constant moved, the others as shipped; head):
|
||||
|
||||
| Constant | Spike (a): paused s, kWh | Edge (b) 5 s meter 3.0 kW: paused s, flaps | Rig s5b 1 s: kWh, period W | Owner night N=2: kWh, top W |
|
||||
|---|---|---|---|---|
|
||||
| `RESTART_S` 30 | 79, 0.541 | 21, 0 | 0.082, 2 321 | 6.206, **3 459** |
|
||||
| `RESTART_S` 60 (shipped) | 139, 0.537 | 21, 0 | 0.075, 2 299 | 6.169, 3 453 |
|
||||
| `RESTART_S` 90 | 199, 0.532 | 21, 0 | 0.061, 2 250 | 6.169, 3 453 |
|
||||
| `RESTART_S` 120 | 259, 0.528 | 21, 0 | 0.085, 2 338 | 6.169, 3 453 |
|
||||
| `GAVE_S` 5 | - | 75, **1** | 0.075, 2 299 | 6.170, 3 453 |
|
||||
| `GAVE_S` 10 | - | 15, 0 | 0.075, 2 299 | 6.169, 3 453 |
|
||||
| `GAVE_S` 15 (shipped) | - | 21, 0 | 0.075, 2 299 | 6.169, 3 453 |
|
||||
| `GAVE_S` 30 | - | 35, 0 | 0.073, 2 290 | 6.168, 3 453 |
|
||||
| `YOUNG_S` 30 / 90 | - | 21, 0 | 0.075, 2 299 | 6.169, 3 453 |
|
||||
|
||||
`RESTART_S` 30 restarts the owner night in a period's last 30 s and lands
|
||||
9 W over base's top period; 60 is the shortest value without that. In s5b
|
||||
the value only moves where the restart meets the oven cycle. `GAVE_S` 5 s is
|
||||
shorter than a 5 s meter's age and flaps again; 10-30 s only move the wait.
|
||||
`YOUNG_S` does not move these runs: the give falls in the first seconds.
|
||||
|
||||
On the synthetic night where the house alone is 950 W over the aim (N=1,
|
||||
heat pump 4.4 kW), head's top period is 4 403 W against base's 4 401 W: a
|
||||
charge restarted in the period before runs into the heat pump's start (the
|
||||
carry-over below). Base charges 1.142 kWh there, head 1.560 kWh.
|
||||
|
||||
**Not changed.** With battery modes off, `arbitrage.decide()` has no period
|
||||
latch and sizes the charge to the headroom each cycle (SAFETY-45). Nothing
|
||||
here touches it.
|
||||
latch and sizes the charge to the headroom each cycle (SAFETY-45). A charge at
|
||||
full power in a period's last seconds still runs into the next period (the
|
||||
charge side of SAFETY-124); with rule 1 that costs 60 s, not the period.
|
||||
|
||||
Reference in New Issue
Block a user