Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
8ad6aaa
fix(control): one log of FTW's own EV offers
frahlg Oct 27, 2026
a840def
fix(control): battery fuse guard reads each phase with its direction
frahlg Oct 27, 2026
0af26e0
fix(control): battery waits only for a declared charger response time
frahlg Oct 27, 2026
2f793d8
fix(control): fuse guard reads phases after the hold caps the targets
frahlg Oct 27, 2026
ae50212
fix(control): car and battery-beside-car work to the fuse rating less…
frahlg Oct 27, 2026
3860ee1
fix(control): keep covered offers whole and leave battery relief out …
frahlg Oct 27, 2026
784d0ba
fix(control): battery fuse guard reads each phase with its direction
frahlg Oct 27, 2026
7e453c0
fix(control): fuse guard reads phases after the hold caps the targets
frahlg Oct 27, 2026
a11706b
fix(control): battery relieves to the fuse less safety_margin_a
frahlg Oct 27, 2026
c311760
test(control): re-record golden records at the fuse less safety_margin_a
frahlg Oct 27, 2026
3efb3ed
fix(control): battery fuse cut lands on the line, not half a margin b…
frahlg Oct 27, 2026
f93b81f
docs(changeset): name the limit the battery cut lands on
frahlg Oct 27, 2026
fab8f6f
fix(config): fuse safety_margin_a defaults to 0
frahlg Oct 27, 2026
94f19b3
docs(changeset): say what the default change moves on its own
frahlg Oct 27, 2026
d8737e0
Merge origin/master into b-ev-fuse-line-at-rating
frahlg Oct 27, 2026
0e48dc5
fix(control): a restart seeds the fuse heat at most at the working limit
frahlg Oct 27, 2026
1d44a63
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 27, 2026
8a7c2be
test(control): relief stays at the line after a PV drop (C3, seed 207…
frahlg Oct 27, 2026
610e2a1
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 27, 2026
4493e94
Merge origin/master into b-ev-fuse-line-at-rating
frahlg Oct 27, 2026
e3d426b
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 27, 2026
b19d30d
test(control): phase relief reads each battery live, in the decision'…
frahlg Oct 27, 2026
fd07863
fix(control): battery relief holds when the battery's reading lags th…
frahlg Oct 27, 2026
bb9703e
fix(control): a landed EV cut covers nothing later; a raise that no l…
frahlg Oct 27, 2026
ad1f994
fix(control): a one-phase house move is not the car's cut landing
frahlg Oct 27, 2026
43d38ff
fix(control): a battery charge rise fits each phase before it is sent
frahlg Oct 27, 2026
c94fa56
fix(control): battery rise check counts slow batteries and direction-…
frahlg Oct 27, 2026
a6bdd9e
fix(control): the car comes before battery charge
frahlg Oct 27, 2026
eb553dd
fix(control): peak shaving drops a running charge for the car
frahlg Oct 27, 2026
ef7ca51
fix(control): after a restart the battery credits the car the meter s…
frahlg Oct 27, 2026
e53aa4b
fix(control): credit a found car only from a current charger sample
frahlg Oct 27, 2026
1a75e9a
Merge ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
bbb5f1b
test(control): run the site sim at the new 0 A default margin
frahlg Oct 28, 2026
3cf26fd
docs(changeset): say what margin 0 moves once the fuse stack lands
frahlg Oct 28, 2026
427697e
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 28, 2026
2ee5b71
Merge c-battery-fuse-no-buffer into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
e2faf1e
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
17dc7c2
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
8c1dfce
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
021273a
Merge ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
4ecebfd
test(control): keep the load-balancer bug as a known line above the line
frahlg Oct 28, 2026
97eb612
fix(control): EV room reads battery relief through live telemetry
frahlg Oct 28, 2026
a6da34d
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
8150b45
fix(control): an offline battery's fuse relief ends after evSettle
frahlg Oct 28, 2026
ddab122
fix(control): each offline battery's fuse relief ends after evSettle
frahlg Oct 28, 2026
2c1f827
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
6a5a5f5
fix(control): battery phase relief neither pins mixed phases nor wind…
frahlg Oct 28, 2026
c066892
fix(control): battery phase anti-windup stops only when the meter can…
frahlg Oct 28, 2026
8c3ae3c
fix(control): battery off the worst phase goes back, and a stale refe…
frahlg Oct 28, 2026
b36e951
test(control): the drift test also wants no verdict on the load change
frahlg Oct 28, 2026
3c9ceb7
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 28, 2026
7d59c5f
Merge c-battery-fuse-no-buffer into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
27561de
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
0fbe100
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
281f9f6
test(control): our battery order's move is not the car's cut landing
frahlg Oct 28, 2026
074f197
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
f29e96c
test(control): the car-first discharge stop has its own test
frahlg Oct 28, 2026
255577e
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
c9b52c3
fix(control): the battery rise check reads only live battery power
frahlg Oct 28, 2026
2928990
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
ab02710
fix(control): judge a raise's landing from the meter's rise
frahlg Oct 28, 2026
53b8aa3
fix(control): a car not yet seen may take a raise on one phase
frahlg Oct 28, 2026
8a10b27
fix(control): judge a one-phase landing reading by reading
frahlg Oct 28, 2026
c0a5274
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
5babe51
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
f294e14
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
6b10baa
fix(control): restart credit keeps room for the car's rise to its max
frahlg Oct 28, 2026
19d8a29
test(control): Charge now landing shown before Core logs its offer
frahlg Oct 28, 2026
3623603
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
caacc8d
fix(control): restart credit counts no sample newer than the meter
frahlg Oct 28, 2026
b152e84
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
551febd
fix(control): restart credit holds against a charger clock behind Core's
frahlg Oct 28, 2026
b621bab
Merge origin/ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
a5cdeae
docs(control): the fuse margin is opt-in, and only the fuse ceilings …
frahlg Oct 28, 2026
358da3b
test(control): battery beside a minimum-step car holds the fuse line …
frahlg Oct 28, 2026
fdfbfec
test(config): an unset fuse margin reaches Core as 0
frahlg Oct 28, 2026
a059b6a
Merge branch 'c-battery-fuse-no-buffer' into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
48fb649
Merge branch 'ev-cut-landed-and-unshown' into battery-rise-per-phase-cap
frahlg Oct 28, 2026
5c9c336
Merge branch 'battery-rise-per-phase-cap' into car-before-battery-charge
frahlg Oct 28, 2026
b82e44d
Merge branch 'car-before-battery-charge' into ev-base-after-restart
frahlg Oct 28, 2026
0befc58
Merge branch 'ev-base-after-restart' into d-fuse-margin-default-0
frahlg Oct 28, 2026
dbc4332
test(site): s18 judges own commands apart from the house's step
frahlg Oct 28, 2026
7bfa634
Merge origin/master into b-ev-fuse-line-at-rating
frahlg Oct 28, 2026
a67aa46
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
dbc3a07
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 28, 2026
fb0b70e
Merge c-battery-fuse-no-buffer into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
dcf4982
fix(control): no cut of an unseen car, no landing from a 1p house move
frahlg Oct 28, 2026
a0a56b7
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
7d7b450
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
9793adf
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
040ebb1
fix(control): judge a restart sample by its arrival, not its stamp
frahlg Oct 28, 2026
1422d70
Merge ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
2b30933
test(site): judge overages at the fuse rating, not fuse - 1 A
frahlg Oct 28, 2026
62f1180
Merge pull request #1914 from srcfl/d-fuse-margin-default-0
frahlg Oct 28, 2026
a3f9a7b
Merge pull request #1926 from srcfl/ev-base-after-restart
frahlg Oct 28, 2026
773c4ed
Merge pull request #1925 from srcfl/car-before-battery-charge
frahlg Oct 28, 2026
3260c43
Merge pull request #1924 from srcfl/battery-rise-per-phase-cap
frahlg Oct 28, 2026
49f9699
Merge pull request #1923 from srcfl/ev-cut-landed-and-unshown
frahlg Oct 28, 2026
abd6b23
Merge pull request #1913 from srcfl/c-battery-fuse-no-buffer
frahlg Oct 28, 2026
9867c72
Merge pull request #1891 from srcfl/a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
53d1088
Merge master into the fuse stack
frahlg Oct 28, 2026
3ac1300
Merge the fuse stack into heat-filter-cold-start
frahlg Oct 28, 2026
f9d6df8
Merge master into heat-filter-cold-start
frahlg Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/c8-heat-filter-cold-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

After a restart, one high site reading no longer holds an idle car back for close to a minute. The fuse heat model used to start at the first reading's current, as if that overload had lasted. In seed 207539 one reading of 27.94 A on a 20 A fuse delayed the car's start by about 43 s. The model now starts at the first reading's current, at most the working limit. A sustained overload after a restart is still cut on the next reading, and readings above 1.2 × the fuse rating are still cut at once.
4 changes: 3 additions & 1 deletion go/internal/control/ev_battery_priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func issue1868Site(t *testing.T) (*telemetry.Store, *State, []loadpoint.State, [
a, n := st.offerPhaseA(4140, 3)
st.evLimit.offers = map[string]chargerOffers{"rav4": {log: commandLog{{at: st.now().Add(-evUnknownSettle - time.Second), w: 4140, a: a, n: n}}}}
sent(st, "battery", 4000)
lastingFuseHeat(tel, st) // The overage has lasted, as in the field.
points := []loadpoint.State{{ID: "rav4", DriverName: "car", PluggedIn: true, CommandedKnown: true, CommandedW: 4140, CommandedPhases: 3}}
configs := []loadpoint.Config{{ID: "rav4", DriverName: "car", PhaseMode: "3p", MinChargeW: 4140, MaxChargeW: 4140, AllowedStepsW: []float64{0, 4140}}}
return tel, st, points, configs
Expand Down Expand Up @@ -107,8 +108,9 @@ func TestEVPriorityFallsBackWhenTheBatteryCannotYield(t *testing.T) {
{"stale meter", func(tel *telemetry.Store, _ *State) {
tel.Get("meter", telemetry.DerMeter).UpdatedAt = time.Now().Add(-time.Minute)
}},
{"over the working limit", func(tel *telemetry.Store, _ *State) {
{"over the working limit", func(tel *telemetry.Store, st *State) {
tel.Update("meter", telemetry.DerMeter, 9000, nil, []byte(`{"l1_a":15.6,"l2_a":12.5,"l3_a":11.9}`))
lastingFuseHeat(tel, st) // the overage has lasted (I²t)
}},
{"unseen battery rise", func(_ *telemetry.Store, st *State) { sent(st, "battery", 0, 4000) }},
} {
Expand Down
5 changes: 3 additions & 2 deletions go/internal/control/ev_fuse_budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,11 @@ func evMeterBudgetFixture(t *testing.T, gridW float64, phaseA []float64, offerW
}

// A 3p car offered 15 A beside 11 A of house load on L1: 26 A on the 25 A
// working limit (no safety margin). With no earlier reading the fuse heat
// starts at 26 A, so one amp on three phases comes off the offer at once.
// working limit, long enough to spend the heat budget, so one amp on three
// phases comes off the offer.
func TestEVHardLimitTrimsPhaseOverageFromOffer(t *testing.T) {
store, state, points, configs := evMeterBudgetFixture(t, 8280, []float64{26, 20, 20}, 10350, "3p")
lastingFuseHeat(store, state)
got, known := EVFuseBudget(store, state, points, configs, 17250)
if !known || math.Abs(got-9660) > .01 {
t.Fatalf("cap %.1f W, want 10,350 - 1 A x 690 = 9,660 W", got)
Expand Down
10 changes: 5 additions & 5 deletions go/internal/control/ev_fuse_cut_netting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,18 @@ func TestEVFusePhaseChangeCoversNothing(t *testing.T) {
}

// After a restart, the offer Core finds in force is one it did not send in
// this run. A cut takes it as shown: the first reading over the limit trims
// the overage from it, and while that cut travels to a slow charger no
// further reading counts the found offer as a raise on its way.
// this run. A cut takes it as shown: the first reading that spends the heat
// trims the overage from it, and while that cut travels to a slow charger
// no further reading counts the found offer as a raise on its way.
func TestEVFuseRestartTakesFoundOfferAsShown(t *testing.T) {
s := fuseHeatSite(t)
s.chargerDelay, s.chargerMaxAgeS = time.Minute, 180
s.addHouseA(6, 0, 0)
s.run(30 * time.Second)
s.boot()
bootAt := s.now
if took, offer := s.firstCut(5 * time.Second); took != 0 || offer != 8970 {
t.Fatalf("restart at 26 A cut after %v to %.0f W, want the first reading to 8,970 W", took, offer)
if took, offer := s.firstCut(5 * time.Second); took != time.Second || offer != 8970 {
t.Fatalf("restart at 26 A cut after %v to %.0f W, want the second reading to 8,970 W", took, offer)
}
s.run(50 * time.Second)
if cuts := offerWatts(s.cutsSince(bootAt)); len(cuts) != 1 {
Expand Down
34 changes: 29 additions & 5 deletions go/internal/control/fuse_heat.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,34 @@ const fuseInstantFactor = 1.2
//
// A reading stands for the time until the next one. A meter gap counts at
// the last current seen: the reading after it neither fills the gap with its
// own current nor erases an overload from before it. A Core restart starts
// the model at the first reading's current, with no memory of the minutes
// before.
// own current nor erases an overload from before it.
//
// A Core restart loses the model, but not the fuse's heat: a fuse cools over
// minutes and a restart takes seconds. The model starts at the first
// reading's current, at most the working limit (start). Starting cold would
// grant a full fresh budget to an overload already under way: from cold,
// 1.15 × In takes about 85 s to reach In. Starting at the line, the first
// reading over it spends the budget at once, and a sustained overload is cut
// on the next reading. One reading cannot show that an overage has lasted,
// so it is not charged as if it had; its current still counts for the time
// until the next reading, and the instant cut above fuseInstantFactor
// applies to it as to any other.
type fuseHeat struct {
set bool
at time.Time // the last reading
amps [3]float64 // its phase currents, held until the next
sq [3]float64 // filtered I² per phase up to at, A²
}

// start seeds the model from the first reading after Core starts: each
// phase at its current, at most lineA.
func (h *fuseHeat) start(at time.Time, amps []float64, lineA float64) {
h.step(at, amps)
for i, sq := range h.sq {
h.sq[i] = math.Min(sq, lineA*lineA)
}
}

// step folds the time since the last reading into the model at that
// reading's currents, then holds the new ones.
func (h *fuseHeat) step(at time.Time, amps []float64) {
Expand Down Expand Up @@ -118,9 +136,15 @@ func (s *State) stepFuseHeat(meter *telemetry.DerReading, totalW float64) {
if s.fuseHeat.set && !meter.UpdatedAt.After(s.fuseHeat.at) {
return
}
if amps, _, valid := phaseCurrentsA(meter, s, totalW); valid {
s.fuseHeat.step(meter.UpdatedAt, amps)
amps, _, valid := phaseCurrentsA(meter, s, totalW)
if !valid {
return
}
if !s.fuseHeat.set {
s.fuseHeat.start(meter.UpdatedAt, amps, s.fuseLineA()) // evMeterRoom's limitA
return
}
s.fuseHeat.step(meter.UpdatedAt, amps)
}

// phaseCurrentsA reads the site's configured phases, import positive. A
Expand Down
81 changes: 73 additions & 8 deletions go/internal/control/fuse_heat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,62 @@ func TestFuseHeatCountsGapAtLastCurrentSeen(t *testing.T) {
}
}

// A Core restart has no memory: the first reading sets the heat.
// A Core restart has no memory: the first reading sets the heat, at most
// the working limit. One reading cannot show that an overage has lasted.
func TestFuseHeatStartsAtFirstReadingAfterRestart(t *testing.T) {
store, state := fuseHeatState()
state.stepFuseHeat0(meterAt(store, time.Unix(1_800_000_000, 0), [3]float64{26, 3, 0}))
if state.fuseHeat.sq != [3]float64{676, 9, 0} {
t.Fatalf("first reading set %v", state.fuseHeat.sq)
if state.fuseHeat.sq != [3]float64{625, 9, 0} {
t.Fatalf("first reading set %v, want L1 at the 25 A working limit", state.fuseHeat.sq)
}
if state.fuseHeat.amps != [3]float64{26, 3, 0} {
t.Fatalf("first reading held %v, want its own currents", state.fuseHeat.amps)
}
}

// firstStart runs until the first offer above 0 W and returns how long
// after the first reading of the run that was.
func (s *evMeterSite) firstStart(limit time.Duration) time.Duration {
s.t.Helper()
first := s.now.Add(time.Second)
for s.now.Sub(first) < limit {
s.step()
if s.offer() > 0 {
return s.now.Sub(first)
}
}
return -1
}

// Seed 207539: Core starts while one reading shows 1.4 × In on L1, then the
// house is back at 10 A per phase. A reading without room starts the idle
// car's dwell, as it always does; the heat that one second added is gone
// within a couple of readings. The car must not also wait the ~52 s a fuse
// already at 35 A would need to cool under the working limit.
func TestEVStartAfterRestartDoesNotWaitOutOneHighReading(t *testing.T) {
s := newEVMeterSite(t, 0, 6900)
s.addHouseA(.4*25+25-10, 0, 0) // 35 A on L1
s.step() // Core's first reading
s.addHouseA(-(.4*25 + 25 - 10), 0, 0)
got := s.firstStart(3 * time.Minute)
if got < 0 || got > evRestartDwell+3*time.Second {
t.Fatalf("after one 35 A reading the car started after %v, want the %v dwell and at most 3 s of heat", got, evRestartDwell)
}
}

// A sustained 1.15 × In on L1 right after a restart gets no fresh budget:
// the heat starts at the working limit and the second reading cuts. A cold
// model would let it run for about 72 s before it reached the 24 A line.
func TestEVHardLimitSustainedOverageAfterRestartCuts(t *testing.T) {
if cold := secondsToSpend(0, 1.15*25, 24); cold < 60 {
t.Fatalf("setup: a cold model spends the budget after %d s", cold)
}
s := fuseHeatSite(t)
s.boot()
s.addHouseA(1.15*25-20, 0, 0) // 28.75 A, under the instant cut
took, offer := s.firstCut(2 * time.Minute)
if took < 0 || took > time.Second || offer >= 10350 {
t.Fatalf("1.15 × In after a restart cut after %v to %.0f W, want the second reading", took, offer)
}
}

Expand Down Expand Up @@ -275,9 +325,10 @@ func TestEVHardLimitHeatBudgetAcrossMeterGap(t *testing.T) {
}
}

// After a Core restart the heat starts at the first reading. Restarting
// 30 s into 26 A on L1 counts the fuse as already at 26 A and cuts at once,
// which is conservative only because that reading is high.
// After a Core restart the heat starts at the first reading, at most the
// working limit. Restarting 30 s into 26 A on L1, with about 31 s of budget
// left, counts the fuse as at the line: the second reading spends the
// budget and cuts.
func TestEVHardLimitRestartStartsHeatAtFirstReading(t *testing.T) {
s := fuseHeatSite(t)
s.addHouseA(6, 0, 0)
Expand All @@ -287,8 +338,8 @@ func TestEVHardLimitRestartStartsHeatAtFirstReading(t *testing.T) {
}
s.boot()
took, offer := s.firstCut(5 * time.Second)
if took != 0 || offer != 8970 {
t.Fatalf("restart at 26 A cut after %v to %.0f W, want the first reading to 8,970 W", took, offer)
if took != time.Second || offer != 8970 {
t.Fatalf("restart at 26 A cut after %v to %.0f W, want the second reading to 8,970 W", took, offer)
}
}

Expand Down Expand Up @@ -567,6 +618,20 @@ func TestExportingPhaseLevelIsItsReading(t *testing.T) {
}
}

// lastingFuseHeat sets the heat model as if the site meter's last reading
// had held for an hour: the case under test has lasted.
func lastingFuseHeat(store *telemetry.Store, state *State) {
meter := store.Get(state.SiteMeterDriver, telemetry.DerMeter)
amps, _, valid := phaseCurrentsA(meter, state, meter.RawW)
if !valid {
panic("lastingFuseHeat: no usable phase currents")
}
state.fuseHeat = fuseHeat{set: true, at: meter.UpdatedAt.Add(-time.Hour)}
for i, a := range amps {
state.fuseHeat.amps[i], state.fuseHeat.sq[i] = a, a*a
}
}

// stepFuseHeat0 folds a reading with phase currents but no phase power, so
// its total does not matter.
func (s *State) stepFuseHeat0(meter *telemetry.DerReading) { s.stepFuseHeat(meter, 0) }
Loading