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
5 changes: 5 additions & 0 deletions .changeset/ev-below-phase-minimum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

A charger set to three phases with a maximum below 6 A on each phase now charges. Three phases cannot run below 6 A each, 4.1 kW at 230 V. With a maximum of 3.8 kW, every planned slot went out as 0 W while the reason still said "plan", so the car did not charge and nothing said why. FTW now plans and orders the lowest three-phase level, 6 A on each phase, for planned charging, the deadline reserve, spare solar and Charge now. Where the phase mode allows one phase and the level fits, the order runs on one phase as before. Saving such a charger, and starting FTW with one, shows a warning with the fix. A Charge now request below 6 A on each phase of a charger set to three phases gets no order, and the status now says "Below 6 A a phase" instead of naming a charger limit or the main fuse. On a charger that can switch phases, such a request now runs on one phase.
3 changes: 3 additions & 0 deletions go/cmd/ftw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ func main() {
for _, w := range cfg.LoadWarnings {
slog.Error(w)
}
for _, w := range cfg.LoadpointWarnings {
slog.Warn(w)
}
for _, notice := range cfg.Retired {
slog.Warn(notice)
}
Expand Down
4 changes: 4 additions & 0 deletions go/internal/api/api_clamped_no_draw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestPositiveEVClampDoesNotHideNoPowerResponse(t *testing.T) {
{"stale charger", "fuse_limit", 6900, 0, false, 3 * time.Minute, "telemetry_stale"},
{"stale site", "site_meter_stale", 6900, 0, true, 3 * time.Minute, "site_meter_stale"},
{"cooldown", "fuse_cooldown", 6900, 0, true, 3 * time.Minute, "fuse_cooldown"},
{"below the phase minimum", "below_phase_minimum", 0, 0, true, 3 * time.Minute, "below_phase_minimum"},
} {
t.Run(tc.name, func(t *testing.T) {
f := ControlFeedback{Kind: "ev", RequestedA: watts(15), OfferedA: watts(10), SentW: watts(tc.sent), ActualW: watts(tc.actual), ObservedAtMs: now.UnixMilli(), DeviceReason: "limited by dynamic charger current"}
Expand All @@ -35,6 +36,9 @@ func TestPositiveEVClampDoesNotHideNoPowerResponse(t *testing.T) {
if tc.want == "no_power_response" && f.Status != "not_following" {
t.Fatalf("zero power must be visible: %+v", f)
}
if tc.want == "below_phase_minimum" && (f.Status != "limited" || f.Severity != "warning") {
t.Fatalf("no valid order must ask for a look: %+v", f)
}
})
}
}
4 changes: 2 additions & 2 deletions go/internal/api/api_control_feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func setControlStatus(f *ControlFeedback) {
status = "limited"
case "import_limit":
status = "limited"
case "device_limit", "offered_current_lower":
case "device_limit", "offered_current_lower", "below_phase_minimum":
status, severity = "limited", "warning"
case "setpoint_changed", "power_below_target", "power_above_target", "power_wrong_direction",
"no_power_response", "power_while_idle":
Expand Down Expand Up @@ -467,7 +467,7 @@ func classifyControlFeedback(f *ControlFeedback, cmd telemetry.CommandEvidence,
// A limit explains a lower order, not a draw that differs from it. A
// charger whose fresh readings have disagreed with the order past its
// response time is judged below, as under any other order.
limit := coreReason == "site_meter_stale" || coreReason == "site_phase_currents_stale" || coreReason == "fuse_cooldown" || coreReason == "fuse_limit" || coreReason == "import_limit" || coreReason == "charger_limit"
limit := coreReason == "site_meter_stale" || coreReason == "site_phase_currents_stale" || coreReason == "fuse_cooldown" || coreReason == "fuse_limit" || coreReason == "import_limit" || coreReason == "charger_limit" || coreReason == "below_phase_minimum"
if limit && !(f.Kind == "ev" && evMismatchObserved) {
set("limited", coreReason, "warning")
return
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"},
"device_limit": {"limited", "warning"},
"below_phase_minimum": {"limited", "warning"},
"power_below_target": {"not_following", "warning"},
"setpoint_changed": {"not_following", "warning"},
"device_fault": {"not_following", "alarm"},
Expand Down
51 changes: 51 additions & 0 deletions go/internal/config/loadpoint_phase_minimum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package config

import (
"strings"
"testing"
)

// srcfl/ftw#1861: a loadpoint pinned to 3p with min = max = 3,800 W cannot
// run three phases, which take at least 6 A each (4,140 W at 230 V). Startup
// and save say so, and say what FTW orders instead.
func TestLoadpointBelowPhaseMinimumWarns(t *testing.T) {
for _, c := range []struct {
name, mode string
phases int
maxW float64
steps []float64
want string
}{
{"3p, maximum below 6 A a phase", "3p", 3, 3800, []float64{0, 3800}, "below 4140 W"},
{"3p, no table", "3p", 3, 3800, nil, "below 4140 W"},
{"3p, a table with no three-phase level", "3p", 3, 5520, []float64{0, 1380, 2300, 3680}, "no level from 4140 W"},
{"3p, legal", "3p", 3, 4140, []float64{0, 4140}, ""},
{"unset runs on one phase", "", 3, 3800, []float64{0, 3800}, ""},
{"auto runs on one phase", "auto", 3, 3800, nil, ""},
{"one-phase site", "3p", 1, 3680, nil, ""},
{"below 6 A on one phase", "1p", 3, 1000, nil, "below 1380 W"},
} {
t.Run(c.name, func(t *testing.T) {
cfg := &Config{
Drivers: []Driver{{Name: "easee"}},
Loadpoints: []Loadpoint{{ID: "rav4", DriverName: "easee", MinChargeW: min(c.maxW, 3800), MaxChargeW: c.maxW, PhaseMode: c.mode, AllowedStepsW: c.steps}},
}
cfg.Fuse.MaxAmps, cfg.Fuse.Phases, cfg.Fuse.Voltage = 20, c.phases, 230
if err := cfg.normalizeLoadpointSteps(); err != nil {
t.Fatal(err)
}
got := strings.Join(cfg.LoadpointWarnings, "\n")
if c.want == "" && got != "" || c.want != "" && (!strings.Contains(got, c.want) || !strings.Contains(got, `"rav4"`)) {
t.Fatalf("warnings %q, want one with %q", got, c.want)
}
// A fixed loadpoint drops the warning on the next save.
cfg.Loadpoints[0].MaxChargeW, cfg.Loadpoints[0].AllowedStepsW = 11000, nil
if err := cfg.normalizeLoadpointSteps(); err != nil {
t.Fatal(err)
}
if len(cfg.LoadpointWarnings) != 0 {
t.Fatalf("warnings after the fix: %q", cfg.LoadpointWarnings)
}
})
}
}
46 changes: 46 additions & 0 deletions go/internal/config/loadpoint_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"slices"
"strings"

"github.com/srcfl/ftw/go/internal/units"
)
Expand Down Expand Up @@ -35,5 +36,50 @@ func (c *Config) normalizeLoadpointSteps() error {
}
c.Loadpoints = loadpoints
c.warnMissingLoadpointConnections()
c.warnLoadpointPhaseMinimum()
return nil
}

const belowPhaseMinimum = "Below the phase minimum: "

// warnLoadpointPhaseMinimum names each charger whose maximum or step table
// stops below 6 A on each of its phases: three when pinned to 3p on a
// three-phase site, else one. Core orders that minimum instead
// (srcfl/ftw#1861). The warning goes when the loadpoint is fixed.
func (c *Config) warnLoadpointPhaseMinimum() {
warnings := make([]string, 0, len(c.LoadpointWarnings))
for _, warning := range c.LoadpointWarnings {
if !strings.HasPrefix(warning, belowPhaseMinimum) {
warnings = append(warnings, warning)
}
}
voltage := c.Fuse.Voltage
if math.IsNaN(voltage) || math.IsInf(voltage, 0) || voltage <= 0 {
voltage = 230
}
for _, lp := range c.Loadpoints {
phases, amps, fix := "one phase", "6 A", ""
minimumW := 6 * voltage
if lp.PhaseMode == "3p" && (c.Fuse.Phases <= 0 || c.Fuse.Phases == 3) {
phases, amps, fix = "three phases", "6 A on each", ", or set the phase mode to auto if the charger can switch to one phase"
minimumW *= 3
}
var problem, change string
switch {
case lp.MaxChargeW > 0 && lp.MaxChargeW < minimumW:
problem = fmt.Sprintf("Its maximum of %g W is below that", lp.MaxChargeW)
change = fmt.Sprintf("Raise the maximum to %g W or more", minimumW)
case len(lp.AllowedStepsW) > 0 && !slices.ContainsFunc(lp.AllowedStepsW, func(w float64) bool {
return w >= minimumW && (lp.MaxChargeW <= 0 || w <= lp.MaxChargeW)
}):
problem = fmt.Sprintf("Its charging steps have no level from %g W", minimumW)
change = fmt.Sprintf("Add a step of %g W or more", minimumW)
default:
continue
}
warnings = append(warnings, belowPhaseMinimum+fmt.Sprintf(
"charger %q on %s cannot charge below %g W (%s). %s, so FTW charges at %g W. %s%s.",
lp.ID, phases, minimumW, amps, problem, minimumW, change, fix))
}
c.LoadpointWarnings = warnings
}
47 changes: 45 additions & 2 deletions go/internal/control/sitesim_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,29 @@ func homeBox(use fieldUse, tm fieldTiming) fieldCase {
lp: func(c *loadpoint.Config) { c.VehicleCapacityWh = 76000 }}
}

// issue1861 is srcfl/ftw#1861, v0.155.1-beta.1: a three-phase charger
// pinned to 3p with min = max = 3,800 W and steps [0, 3800], below three
// phases' 6 A each. Every planned slot went out as 0 W. The report has no
// fuse; it runs at 20 A, as the help report's site. steps own is the
// report's table, one level only one phase can run; 3p is three-phase
// levels, all above the maximum; none is no table. Unset, the same
// numbers read as a one-phase charger (srcfl/ftw#1799), and it is one here,
// without a table: 3,800 W is above its 16 A on one phase.
func issue1861(use fieldUse, tm fieldTiming, mode, steps string, carPhases int) fieldCase {
c := fieldCase{report: "issue1861", fuseA: 20, mode: mode, steps: steps, timing: tm, carPhases: carPhases, use: use,
house: houseBalanced, houseName: "balanced",
lp: func(c *loadpoint.Config) {
if steps == "own" {
c.AllowedStepsW = []float64{0, 3800}
}
c.MinChargeW, c.MaxChargeW = 3800, 3800
}}
if mode == "" {
c.charger = "1p32A"
}
return c
}

// fieldCases crosses the axes. The field reports run with every charger
// timing. The sweep crosses fuse, phase mode, step table, car and house for
// planned charging and Charge now with an Easee Cloud charger; the timing
Expand Down Expand Up @@ -249,6 +272,24 @@ func fieldCases() []fieldCase {
for _, c := range probeCases() {
add(c)
}
for _, steps := range []string{"own", "3p", "none"} {
for _, use := range []fieldUse{usePlanned, useNow} {
for _, tm := range []fieldTiming{timingFast, timingEasee} {
for _, car := range []int{3, 1} {
add(issue1861(use, tm, "3p", steps, car))
}
}
if steps == "none" {
add(issue1861(use, timingEasee, "", steps, 3))
}
}
}
for _, car := range []int{3, 1} {
add(issue1861(useNoPlan, timingEasee, "3p", "own", car))
}
for _, steps := range []string{"own", "3p", "none"} {
add(issue1861(useSurplus, timingEasee, "3p", steps, 3))
}
return out
}

Expand Down Expand Up @@ -685,14 +726,16 @@ func (f *fieldRun) check(s *simSite) {
}

// fieldRoomW is the most the car can draw under Core's limit with the
// house's steady load: what a deadline goal can be held to.
// house's steady load and the loadpoint's maximum, which still runs at 6 A
// a phase: what a deadline goal can be held to.
func fieldRoomW(c fieldCase, e *sitesim.EVSE, car *sitesim.Car) float64 {
phases := min(e.Phases, car.Phases)
worst := 0.0
for i := range phases {
worst = math.Max(worst, c.house[i])
}
roomA := math.Min(c.fuseA-evPhaseMarginA-worst, e.MaxA)
lpA := math.Max(e.MinA, fieldLoadpoint(c).MaxChargeW/(230*float64(e.Phases)))
roomA := min(c.fuseA-evPhaseMarginA-worst, e.MaxA, lpA)
if roomA < e.MinA {
return 0
}
Expand Down
27 changes: 20 additions & 7 deletions go/internal/loadpoint/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1305,12 +1305,14 @@ func (c *Controller) chooseTick(now time.Time, cfg Config, sample EVSample, disp
// runs as planned charging does: three phases on a charger that can, one on
// a charger that cannot. A hold below the 3Φ minimum goes out as auto, so a
// sticky Start on a 1380 W surplus slot does not die at 3Φ's 6 A. A
// client's 3p on a charger that cannot run three phases is not a pin: the
// app sends the phases the API reported, and a 3p order there is 0 W. The
// loadpoint's own mode decides.
// client's 3p is not a pin: the app sends the phases the API reported, and
// a 3p order on a charger that cannot run three phases, or below 6 A on
// each, cannot run. The loadpoint's own mode decides those. A stop keeps
// the client's 3p.
func holdPhaseMode(hold ManualHold, cfg Config, site SiteFuse) string {
mode := hold.PhaseMode
if mode == "" || (mode == "3p" && !threePhaseCapable(cfg, site)) {
belowThreePhases := hold.PowerW > 0 && hold.PowerW < phaseMinChargeW(cfg, "3p", site)
if mode == "" || (mode == "3p" && (!threePhaseCapable(cfg, site) || belowThreePhases)) {
mode = cfg.PhaseMode
}
switch {
Expand Down Expand Up @@ -1476,9 +1478,9 @@ func (c *Controller) tickOne(ctx context.Context, now time.Time, lpCfg Config, s
// zero/empty fields fall through to the normal defaults so a
// minimal hold (just `power_w`) still carries the per-phase
// fuse clamp inputs the driver needs to stay safe.
holdW := clampManualPower(lpCfg, hold, c.siteFuse())
if holdW != hold.PowerW {
cmdReason = "charger_limit"
holdW, limit := clampManualPower(lpCfg, hold, c.siteFuse())
if limit != "" {
cmdReason = limit
}
// An explicit manual hold ("Start" / amp slider) takes priority
// over surplus_only: when the operator deliberately pins a charge
Expand All @@ -1492,6 +1494,7 @@ func (c *Controller) tickOne(ctx context.Context, now time.Time, lpCfg Config, s
// A hold changed after the budget froze names its own phases; the
// phase check below makes it wait for the next tick's budget.
phaseMode = holdPhaseMode(hold, lpCfg, c.siteFuse())
lpCfg = c.tickConfig(lpCfg, phaseMode)
if phaseMode != "" {
cmd["phase_mode"] = phaseMode
}
Expand Down Expand Up @@ -1527,6 +1530,7 @@ func (c *Controller) tickOne(ctx context.Context, now time.Time, lpCfg Config, s
cmd["site_phases"] = site.Phases()
}
} else {
lpCfg = c.tickConfig(lpCfg, phaseMode)
// Snap to steps legal on the phases this command names.
cmdW, planReady, _ := c.computeCommandForBudget(now, c.fuseConfig(lpCfg, phaseMode), sample.PowerW, false)
cmdReason = "plan"
Expand Down Expand Up @@ -2651,6 +2655,15 @@ func (c *Controller) computeCommandForBudget(now time.Time, lpCfg Config, curren
}
maxW := lpCfg.MaxChargeW
if ceiling, ok := d.LoadpointMaxPowerW[lpCfg.ID]; ok {
// A level below the least order on these phases runs at that
// order, on only as long as the slot's energy lasts.
lowest := lpCfg.MinChargeW
if onePhaseCar {
lowest /= 3
}
if ceiling > 0 && ceiling < lowest {
ceiling = lowest
}
// A duty plan commands its legal on-power for its on-time, the slot's
// energy at that power, and on until the energy is spent. A car that
// draws more than its step, as on a mains above 230 V, spends the
Expand Down
31 changes: 25 additions & 6 deletions go/internal/loadpoint/controller_fuse_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package loadpoint

import (
"math"
"slices"
"sort"
"time"
)
Expand Down Expand Up @@ -48,7 +49,7 @@ func (c *Controller) freezeFuseBudget(now time.Time, samples map[string]EVSample
request := fuseRequest{cfg: c.fuseConfig(cfg, c.tickChoices[cfg.ID].phaseMode), deadline: st.TargetTime}
if sample.Connected && !sample.ConnectionUnknown && c.driverCanDispatch(cfg.DriverName) {
if hold, held := c.GetManualHold(cfg.ID, now); held {
request.wantW = clampManualPower(cfg, hold, c.siteFuse())
request.wantW, _ = clampManualPower(cfg, hold, c.siteFuse())
} else {
request.wantW, _, _ = c.computeCommandForBudget(now, request.cfg, sample.PowerW, false)
}
Expand All @@ -58,7 +59,7 @@ func (c *Controller) freezeFuseBudget(now time.Time, samples map[string]EVSample
armed := c.batSoCArmed[cfg.ID]
c.batSoCArmedMu.Unlock()
if cfg.SurplusOnly || armed || c.wakeKickActive(cfg.ID, now) || (st.FinishAtVehicleLimit && !st.GoalComplete) {
request.wantW = cfg.MaxChargeW
request.wantW = request.cfg.MaxChargeW
}
if d.LoadpointFallback[cfg.ID] && sample.PowerUnavailable {
request.wantW = 0
Expand Down Expand Up @@ -219,13 +220,16 @@ func (c *Controller) phaseRoomCapW(id, mode string, wantW, split, roomA float64)
}

// FuseConfigs returns the loadpoints with the phase mode each command names
// this tick. control.EVFuseBudget measures room on those phases, so an auto
// or 1p offer never gets three phases of room. Outside a tick, and for a
// loadpoint that gets no command, the configured mode stands.
// this tick, and the least each can order on those phases. control.
// EVFuseBudget measures room on those phases, so an auto or 1p offer never
// gets three phases of room, and waits for room for that least order, not
// the configured minimum. Outside a tick, and for a loadpoint that gets no
// command, the configured mode stands.
func (c *Controller) FuseConfigs() []Config {
configs := c.manager.Configs()
for i := range configs {
if mode := c.tickChoices[configs[i].ID].phaseMode; mode != "" {
configs[i] = c.fuseConfig(configs[i], mode)
configs[i].PhaseMode = mode
}
}
Expand All @@ -243,7 +247,22 @@ func fusePhase(mode string) string {
// fuseConfig snaps a fuse cap to the smallest legal step on the phases the
// command names. A 3p label on a 1p-sized offer is below 6 A and never charges.
func (c *Controller) fuseConfig(cfg Config, phaseMode string) Config {
cfg.MinChargeW = phaseMinChargeW(cfg, phaseMode, c.siteFuse())
return phaseLimits(cfg, phaseMode, c.siteFuse())
}

// tickConfig is cfg as this tick's order runs it. A three-phase order
// whose maximum or table stops below 6 A on each phase takes the phase
// limits, so surplus, a wake-kick, the car's completion and the current cap
// all name the lowest three-phase level (srcfl/ftw#1861). Any other
// loadpoint keeps its own limits.
func (c *Controller) tickConfig(cfg Config, phaseMode string) Config {
if fusePhase(phaseMode) != "3p" || c.siteFuse().Phases() != 3 {
return cfg
}
limits := c.fuseConfig(cfg, "3p")
if limits.MaxChargeW > cfg.MaxChargeW || !slices.Equal(limits.AllowedStepsW, cfg.AllowedStepsW) {
return limits
}
return cfg
}

Expand Down
4 changes: 2 additions & 2 deletions go/internal/loadpoint/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ type State struct {
// CommandedReason names the dispatch branch that decided CommandedW:
// "plan", "no_plan_budget", "pv_surplus", "pv_surplus_pause",
// "fuse_limit", "import_limit", "site_meter_stale", "manual_hold",
// "wake_kick". Empty until the first dispatch tick. The UI renders the specific cause
// "below_phase_minimum", "wake_kick". Empty until the first dispatch tick. The UI renders the specific cause
// instead of a generic "paused by the box".
CommandedReason string `json:"commanded_reason,omitempty"`

Expand Down Expand Up @@ -576,7 +576,7 @@ func (m *Manager) SetCommandedW(id string, w float64) {
// reverse-engineer from amp readings (#1009). Reasons are short stable
// tokens: "plan", "no_plan_budget", "pv_surplus", "pv_surplus_pause",
// "fuse_limit", "import_limit", "site_meter_stale", "manual_hold",
// "wake_kick". Empty keeps whatever was recorded before (used by the legacy SetCommandedW wrapper).
// "below_phase_minimum", "wake_kick". Empty keeps whatever was recorded before (used by the legacy SetCommandedW wrapper).
// No-op for an unknown id.
func (m *Manager) SetCommanded(id string, w float64, reason string) {
m.setCommandedForManual(id, w, reason, time.Time{})
Expand Down
Loading
Loading