Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions .changeset/load-balancer-start-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"ftw": patch
---

A car whose start the charger's own load balancing holds back now reads
"Waiting for load balancing" instead of "Not following", and Charge now no
longer says the car is not drawing. The driver must report that the load
balancing leaves less than the 6 A a car starts on. Easee's Equalizer raises
the current slowly, up to 15 minutes after the home uses less, so FTW waits
that long. A start still missing after 15 minutes is reported as before, and
the next step names the load balancing. The resume retries log their failed
start after the same wait.
4 changes: 3 additions & 1 deletion go/cmd/ftw/ev_observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func currentEVSample(r *telemetry.DerReading, health *telemetry.DriverHealth, wa
PowerAt string `json:"power_observed_at"`
PowerMaxAgeS int `json:"power_max_age_s"`
EnergyAt string `json:"energy_observed_at"`
LimitA *float64 `json:"current_limit_a"`
LimitedBy string `json:"current_limited_by"`
}
if json.Unmarshal(r.Data, &d) != nil || (d.SessionWh != nil && *d.SessionWh < 0) {
return loadpoint.EVSample{}, false
Expand All @@ -45,7 +47,7 @@ func currentEVSample(r *telemetry.DerReading, health *telemetry.DriverHealth, wa
}
sample := loadpoint.EVSample{ConnectionGeneration: d.ConnectionGeneration, PowerW: r.RawW,
PowerAt: r.UpdatedAt, PowerMaxAge: time.Duration(min(max(d.PowerMaxAgeS, 0), 180)) * time.Second, Connected: *d.Connected, RequestKnown: d.RequestActive != nil, RequestActive: active, DeviceID: deviceID, SessionID: d.SessionID,
SessionWhUnavailable: d.SessionWh == nil}
SessionWhUnavailable: d.SessionWh == nil, LoadBalancerHold: loadpoint.LoadBalancerHoldsStart(d.LimitA, d.LimitedBy)}
_, powerKnown := telemetry.ControlPowerObservation(sample.PowerW, r.Data, r.UpdatedAt)
sample.PowerUnavailable = !powerKnown
if d.SessionWh != nil {
Expand Down
20 changes: 20 additions & 0 deletions go/cmd/ftw/ev_observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@ func TestEVObservationDistinguishesExplicitVehicleStopFromMissingRequest(t *test
}
}
}

// The loadpoint learns that the charger's own load balancing holds the start
// only from a named cause and a limit below what a car starts on.
func TestEVObservationReadsALoadBalancerHold(t *testing.T) {
now := time.Now()
health := &telemetry.DriverHealth{Status: telemetry.StatusOk}
for body, want := range map[string]bool{
`{"connected":true,"current_limit_a":0,"current_limited_by":"load_balancer"}`: true,
`{"connected":true,"current_limit_a":5.5,"current_limited_by":"load_balancer"}`: true,
`{"connected":true,"current_limit_a":6,"current_limited_by":"load_balancer"}`: false,
`{"connected":true,"current_limit_a":0}`: false,
`{"connected":true,"current_limited_by":"load_balancer"}`: false,
`{"connected":true,"current_limit_a":-1,"current_limited_by":"load_balancer"}`: false,
} {
r := &telemetry.DerReading{UpdatedAt: now, Data: json.RawMessage(body)}
if s, ok := currentEVSample(r, health, time.Minute, now, false, "charger"); !ok || s.LoadBalancerHold != want {
t.Errorf("%s: hold %v, want %v", body, s.LoadBalancerHold, want)
}
}
}
23 changes: 22 additions & 1 deletion go/internal/api/api_control_feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func (s *Server) controlFeedback(now time.Time) []ControlFeedback {
// last reading for a minute after the driver stops sending. The
// driver checked its limit against the pilot when it was fresh,
// so only the pilot becomes unknown.
if d.PilotConfirmedAtMs != nil && (!pilotValid || (pilotFresh && *d.PilotA == 0)) {
// A zero pilot agrees with load balancing that holds the start.
if d.PilotConfirmedAtMs != nil && (!pilotValid || (pilotFresh && *d.PilotA == 0 && !loadpoint.LoadBalancerHoldsStart(d.LimitA, d.LimitedBy))) {
d.LimitA, d.LimitedBy = nil, ""
}
if d.LimitA != nil {
Expand Down Expand Up @@ -442,6 +443,8 @@ func setControlStatus(f *ControlFeedback) {
status = "limited"
case "device_limit", "offered_current_lower":
status, severity = "limited", "warning"
case "load_balancer_wait":
status = "waiting"
case "setpoint_changed", "power_below_target", "power_above_target", "power_wrong_direction",
"no_power_response", "power_while_idle":
status, severity = "not_following", "warning"
Expand Down Expand Up @@ -554,6 +557,24 @@ func classifyControlFeedback(f *ControlFeedback, cmd telemetry.CommandEvidence,
set("waiting", "vehicle_declined", "info")
return
}
// The charger's own load balancing lets the car take too little to
// start. Easee raises that current slowly after household use falls, so
// Core waits LoadBalancerRaiseWait from the first zero reading under
// positive orders (a pause ends that run) before it reports no power.
// Safety pauses, a charger holding a lower order, a pilot the car could
// start on, and a run without that clock older than the wait keep their
// own verdicts.
if f.Kind == "ev" && commanded && cmd.Result == "accepted" &&
coreReason != "site_meter_stale" && coreReason != "site_phase_currents_stale" && coreReason != "fuse_cooldown" &&
f.SentW != nil && *f.SentW > 100 && f.ActualW != nil && math.Abs(*f.ActualW) < 100 &&
loadpoint.LoadBalancerHoldsStart(f.LimitA, f.LimitedBy) && (f.RequestedA == nil || *f.LimitA+0.5 < *f.RequestedA) &&
(f.OfferedA == nil || f.RequestedA == nil || *f.OfferedA+0.5 >= *f.RequestedA) &&
(f.PilotA == nil || *f.PilotA < loadpoint.MinStartCurrentA) &&
(!cmd.NoPowerSince.IsZero() && cmd.NoPowerAt.Sub(cmd.NoPowerSince) < loadpoint.LoadBalancerRaiseWait ||
cmd.NoPowerSince.IsZero() && now.Sub(cmd.Since) < loadpoint.LoadBalancerRaiseWait) {
set("waiting", "load_balancer_wait", "info")
return
}
// A positive clamp explains the lower offer, not prolonged zero delivery.
// Keep known safety pauses and unconfirmed/stale commands authoritative.
evMismatchObserved := !cmd.PowerMismatchSince.IsZero() && cmd.LastObservation.Sub(cmd.PowerMismatchSince) >= evMismatchWait
Expand Down
1 change: 1 addition & 0 deletions go/internal/api/api_control_scenarios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func TestControlStatusAnswersEveryReason(t *testing.T) {
"battery_nearly_full": {"limited", "info"},
"fuse_limit": {"limited", "info"},
"load_balancer_limit": {"limited", "info"},
"load_balancer_wait": {"waiting", "info"},
"device_limit": {"limited", "warning"},
"power_below_target": {"not_following", "warning"},
"setpoint_changed": {"not_following", "warning"},
Expand Down
100 changes: 98 additions & 2 deletions go/internal/api/api_ev_load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/srcfl/ftw/go/internal/config"
"github.com/srcfl/ftw/go/internal/drivers"
"github.com/srcfl/ftw/go/internal/loadpoint"
"github.com/srcfl/ftw/go/internal/telemetry"
)

Expand All @@ -37,8 +38,12 @@ func TestEaseeLoadBalancingReadsAsLimited(t *testing.T) {
{"nor a car 1.5 A under a 7 A limit", held + `,"current_limit_a":7,"current_limited_by":"load_balancer"`, 3800, "not_following", "power_below_target", "warning"},
{"nor a car at the order", named, 10300, "following", "power_observed", "info"},
{"limit at the order", held + `,"current_limit_a":15,"current_limited_by":"load_balancer"`, 8850, "not_following", "power_below_target", "warning"},
{"a zero limit", held + `,"current_limit_a":0,"current_limited_by":"load_balancer"`, 0, "not_following", "no_power_response", "warning"},
{"a zero limit, no readback", `,"current_limit_a":0,"current_limited_by":"load_balancer"`, 0, "not_following", "no_power_response", "warning"},
// Load balancing that leaves less than a car starts on holds the
// start for a while (TestLoadBalancingHoldsAStartForFifteenMinutes).
{"a zero limit", held + `,"current_limit_a":0,"current_limited_by":"load_balancer"`, 0, "waiting", "load_balancer_wait", "info"},
{"a zero limit, no readback", `,"current_limit_a":0,"current_limited_by":"load_balancer"`, 0, "waiting", "load_balancer_wait", "info"},
{"a zero limit under a lower readback", `,"max_a":12,"current_limit_a":0,"current_limited_by":"load_balancer"`, 0, "not_following", "no_power_response", "warning"},
{"a 6 A limit does not explain zero", held + `,"current_limit_a":6,"current_limited_by":"load_balancer"`, 0, "not_following", "no_power_response", "warning"},
// A charger that holds a lower order than FTW sent says so first.
{"charger holds 12 A", `,"max_a":12,"current_limit_a":10,"current_limited_by":"load_balancer"`, 6900, "limited", "offered_current_lower", "warning"},
} {
Expand Down Expand Up @@ -106,6 +111,97 @@ func TestEaseeLoadBalancingStepsUp(t *testing.T) {
})
}

// Field report, 12 Nov 2026 (srcfl/ftw#1948), Easee Cloud with an Equalizer:
// FTW ordered 12 A, the charger read back 12 A, Easee allocated 0 A on all
// three phases and the car drew nothing. Easee raises the current again up
// to 15 minutes after household use falls. Core waits that long and then
// reports the start as failed; a start that comes in time follows.
func TestLoadBalancingHoldsAStartForFifteenMinutes(t *testing.T) {
const order, hold = 8280, `,"max_a":12,"current_limit_a":0,"current_limited_by":"load_balancer"`
run := func(t *testing.T, e *evTrace, w float64, d time.Duration, each func(ControlFeedback)) ControlFeedback {
var f ControlFeedback
for range int(d / (5 * time.Second)) {
e.tick(w, "plan")
f = e.verdict(t)
each(f)
}
return f
}
calm := func(t *testing.T, start time.Time) func(ControlFeedback) {
return func(f ControlFeedback) {
if f.Status == "not_following" || f.Severity != "info" {
t.Fatalf("at %v: %s/%s/%s", time.Since(start), f.Status, f.Reason, f.Severity)
}
}
}
t.Run("bounded", func(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
e := newEVTrace(0)
e.extra = hold
start := time.Now()
var last time.Duration
f := run(t, e, order, 20*time.Minute, func(f ControlFeedback) {
since := time.Since(start)
switch {
case f.Reason == "load_balancer_wait":
last = since
if f.Status != "waiting" || f.Severity != "info" || f.LimitA == nil || *f.LimitA != 0 ||
f.LimitedBy != "load_balancer" || f.RequestedA == nil || math.Abs(*f.RequestedA-12) > 0.01 {
t.Fatalf("at %v: %+v", since, f)
}
case since < loadpoint.LoadBalancerRaiseWait:
t.Fatalf("at %v, inside the wait: %s/%s", since, f.Status, f.Reason)
}
})
if f.Status != "not_following" || f.Reason != "no_power_response" || f.Severity != "warning" {
t.Fatalf("after 20 min without a start: %s/%s/%s", f.Status, f.Reason, f.Severity)
}
// The limit and its cause stay on the failed row for the words.
if f.LimitA == nil || *f.LimitA != 0 || f.LimitedBy != "load_balancer" {
t.Fatalf("failed row lost the limit: %+v", f)
}
if wait := loadpoint.LoadBalancerRaiseWait; last < wait-10*time.Second || last >= wait+10*time.Second {
t.Fatalf("waited %v, want %v", last, wait)
}
})
})
t.Run("a start in time follows", func(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
e := newEVTrace(0)
e.extra = hold
start := time.Now()
run(t, e, order, 11*time.Minute, calm(t, start))
e.extra, e.drawW, e.changedAt = `,"max_a":12`, order, time.Now()
if f := run(t, e, order, 3*time.Minute, calm(t, start)); f.Status != "following" {
t.Fatalf("after the start: %s/%s", f.Status, f.Reason)
}
})
})
t.Run("a pause starts a new wait", func(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
e := newEVTrace(0)
e.extra = hold
start := time.Now()
run(t, e, order, 12*time.Minute, calm(t, start))
run(t, e, 0, time.Minute, calm(t, start))
if f := run(t, e, order, 12*time.Minute, calm(t, start)); f.Reason != "load_balancer_wait" {
t.Fatalf("after the new start: %s/%s", f.Status, f.Reason)
}
})
})
t.Run("the hold ends without a start", func(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
e := newEVTrace(0)
e.extra = hold
run(t, e, order, 5*time.Minute, func(ControlFeedback) {})
e.extra = `,"max_a":12`
if f := run(t, e, order, 5*time.Second, func(ControlFeedback) {}); f.Reason != "no_power_response" {
t.Fatalf("allocation back, no draw: %s/%s", f.Status, f.Reason)
}
})
})
}

// The sentence names the charger's make with its limit, from the identity
// its driver reported. Rows without a limit do not carry it.
func TestChargerLimitCarriesTheMake(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions go/internal/api/api_loadpoint_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ func (s *Server) chargerReadings() map[string]loadpoint.ChargerReading {
Reason string `json:"reason_no_current_label"`
CommandStalled bool `json:"command_stalled"`
Online *bool `json:"is_online"`
LimitA *float64 `json:"current_limit_a"`
LimitedBy string `json:"current_limited_by"`
}
if len(rd.Data) > 0 {
_ = json.Unmarshal(rd.Data, &d)
Expand All @@ -343,6 +345,9 @@ func (s *Server) chargerReadings() map[string]loadpoint.ChargerReading {
r.LimitA = *d.MaxA
r.LimitKnown = true
}
if loadpoint.LoadBalancerHoldsStart(d.LimitA, d.LimitedBy) {
r.BalancerA = d.LimitA
}
out[rd.Driver] = r
}
return out
Expand Down
2 changes: 2 additions & 0 deletions go/internal/api/api_pilot_evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func TestPilotAwareDriverFeedback(t *testing.T) {
{"future confirmation cannot explain power", 8850, 13, at13, false, -time.Minute, "not_following", "power_below_target", "warning"},
{"zero delivery stays visible", 0, 13, at13, false, 5 * time.Second, "not_following", "no_power_response", "warning"},
{"zero pilot cannot explain ongoing draw", 8850, 0, at13, false, 5 * time.Second, "not_following", "power_below_target", "warning"},
{"zero pilot under load balancing that holds the start", 0, 0, `,"current_limit_a":0,"current_limited_by":"load_balancer"`, false, 5 * time.Second, "waiting", "load_balancer_wait", "info"},
{"a pilot the car could start on is not a hold", 0, 6, `,"current_limit_a":0,"current_limited_by":"load_balancer"`, false, 5 * time.Second, "not_following", "no_power_response", "warning"},
{"delivery below effective pilot stays visible", 4000, 13, at13, false, 5 * time.Second, "not_following", "power_below_target", "warning"},
{"pilot above the order", 8850, 20, at13, false, 5 * time.Second, "limited", "offered_current_lower", "warning"},
{"pilot above the limit", 8850, 14.2, at13, false, 5 * time.Second, "limited", "offered_current_lower", "warning"},
Expand Down
3 changes: 3 additions & 0 deletions go/internal/loadpoint/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ type EVSample struct {
RequestActive bool
DeviceID string
SessionID string
// LoadBalancerHold: the driver reports that the charger's own load
// balancing lets the car take less than it needs to start.
LoadBalancerHold bool
}

// PlanFunc returns the current-slot directive for now, or (_, false)
Expand Down
19 changes: 16 additions & 3 deletions go/internal/loadpoint/controller_resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type resumeOffer struct {
deliverySince, deliveryAt time.Time
zeroOffer bool
noDrawSince, noDrawAt time.Time
// holdSince is when the driver first reported, in this run without
// draw, that the charger's own load balancing holds the start.
holdSince time.Time
}

// Allow a missed five-second tick and ordinary cloud poll jitter. Repeating
Expand Down Expand Up @@ -127,6 +130,11 @@ func (c *Controller) recoverOfferedCharge(ctx context.Context, cfg Config, sampl
return // Already drawing: observe it rather than sending another resume.
}
previous.deliverySince, previous.deliveryAt = time.Time{}, time.Time{}
if !sample.LoadBalancerHold {
previous.holdSince = time.Time{}
} else if previous.holdSince.IsZero() {
previous.holdSince = now
}
if !previous.zeroOffer {
if previous.noDrawSince.IsZero() || observedAt.Before(previous.noDrawAt) ||
(!previous.noDrawAt.IsZero() && observedAt.Sub(previous.noDrawAt) > resumeObservationGap) {
Expand All @@ -141,8 +149,12 @@ func (c *Controller) recoverOfferedCharge(ctx context.Context, cfg Config, sampl
return
}
if previous.acknowledgedAttempts >= 3 {
if previous.acknowledgedAttempts == 3 {
slog.Warn("loadpoint resume acknowledged but no charge observed", "lp", cfg.ID, "driver", cfg.DriverName)
// The charger's own load balancing may hold a start for up to
// LoadBalancerRaiseWait. A start still missing after that, or one
// with no such hold, has failed.
if previous.acknowledgedAttempts == 3 && (previous.holdSince.IsZero() || now.Sub(previous.holdSince) >= LoadBalancerRaiseWait) {
slog.Warn("loadpoint resume acknowledged but no charge observed", "lp", cfg.ID, "driver", cfg.DriverName,
"load_balancer_hold", !previous.holdSince.IsZero())
previous.acknowledgedAttempts++
}
return
Expand All @@ -159,7 +171,8 @@ func (c *Controller) recoverOfferedCharge(ctx context.Context, cfg Config, sampl
// three acknowledged attempts. Only observed delivery clears the proof.
previous.acknowledgedAttempts++
slog.Info("loadpoint resume acknowledged; waiting for measured charge", "lp", cfg.ID, "driver", cfg.DriverName,
"attempt", previous.acknowledgedAttempts, "offer_w", offerW, "observed_w", sample.PowerW, "power_at", sample.PowerAt)
"attempt", previous.acknowledgedAttempts, "offer_w", offerW, "observed_w", sample.PowerW, "power_at", sample.PowerAt,
"load_balancer_hold", sample.LoadBalancerHold)
previous.nextAttempt = now.Add(30 * time.Second)
previous.retryDelay = 0
}
71 changes: 71 additions & 0 deletions go/internal/loadpoint/controller_resume_load_balancer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package loadpoint

import (
"bytes"
"context"
"log/slog"
"strings"
"testing"
"time"
)

// Field report, srcfl/ftw#1948: an Easee Equalizer held the start for 11–14
// minutes after FTW resumed the charger, and Core logged a failed start after
// its three resumes, about two minutes in. With the driver's word that the
// charger's own load balancing holds the start, Core waits up to
// LoadBalancerRaiseWait before it logs the failure; without it, or once the
// hold ends, a start that has not come has failed.
func TestResumeWarningWaitsOutALoadBalancerHold(t *testing.T) {
for _, tc := range []struct {
name string
hold bool
release time.Duration // when the driver stops reporting the hold; 0 never
warnAt time.Duration // when the failed start is logged, from the resume
}{
{"no hold", false, 0, 90 * time.Second},
{"held throughout", true, 0, LoadBalancerRaiseWait},
{"hold ends without a start", true, 5 * time.Minute, 5 * time.Minute},
} {
t.Run(tc.name, func(t *testing.T) {
var logs bytes.Buffer
previous := slog.Default()
slog.SetDefault(slog.New(slog.NewTextHandler(&logs, nil)))
t.Cleanup(func() { slog.SetDefault(previous) })

now := time.Date(2026, 11, 12, 2, 24, 0, 0, time.UTC)
sender := &fakeSender{}
cfg := Config{ID: "garage", DriverName: "easee", MinChargeW: 4140, MaxChargeW: 11000, AllowedStepsW: []float64{0, 4140, 8280, 11000}}
samples := map[string]EVSample{"easee": {Connected: true, RequestActive: true, DeviceID: "box", SessionID: "plug-1",
ConnectionGeneration: 1, LoadBalancerHold: tc.hold}}
dir := &Directive{SlotStart: now, SlotEnd: now.Add(time.Hour), LoadpointEnergyWh: map[string]float64{"garage": 0}}
c := newTestController(t, []Config{cfg}, dir, samples, sender)
c.Tick(context.Background(), now)
dir.LoadpointEnergyWh["garage"] = 8280
resumed := now.Add(5 * time.Second)
warned := time.Duration(0)
for at := resumed; at.Before(resumed.Add(20 * time.Minute)); at = at.Add(5 * time.Second) {
if tc.release > 0 && at.Sub(resumed) >= tc.release {
sample := samples["easee"]
sample.LoadBalancerHold = false
samples["easee"] = sample
}
c.Tick(context.Background(), at)
if warned == 0 && strings.Contains(logs.String(), "no charge observed") {
warned = at.Sub(resumed)
}
}
if n := countAction(sender.calls, "ev_resume"); n != 3 {
t.Fatalf("resumes: %d, want 3 whether or not the start is held", n)
}
if warned < tc.warnAt || warned > tc.warnAt+10*time.Second {
t.Fatalf("failed start logged %v after the resume, want %v\n%s", warned, tc.warnAt, logs.String())
}
if n := strings.Count(logs.String(), "no charge observed"); n != 1 {
t.Fatalf("failed start logged %d times", n)
}
if tc.hold && !strings.Contains(logs.String(), "load_balancer_hold=true") {
t.Fatalf("resume log does not name the hold:\n%s", logs.String())
}
})
}
}
Loading
Loading