diff --git a/.changeset/ev-below-phase-minimum.md b/.changeset/ev-below-phase-minimum.md new file mode 100644 index 000000000..ff733e7fe --- /dev/null +++ b/.changeset/ev-below-phase-minimum.md @@ -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. diff --git a/go/cmd/ftw/main.go b/go/cmd/ftw/main.go index ad1a18932..0133d9fcb 100644 --- a/go/cmd/ftw/main.go +++ b/go/cmd/ftw/main.go @@ -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) } diff --git a/go/internal/api/api_clamped_no_draw_test.go b/go/internal/api/api_clamped_no_draw_test.go index 017e0b649..1de362fe3 100644 --- a/go/internal/api/api_clamped_no_draw_test.go +++ b/go/internal/api/api_clamped_no_draw_test.go @@ -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"} @@ -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) + } }) } } diff --git a/go/internal/api/api_control_feedback.go b/go/internal/api/api_control_feedback.go index 1ed31dd9d..f7fc59e8a 100644 --- a/go/internal/api/api_control_feedback.go +++ b/go/internal/api/api_control_feedback.go @@ -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": @@ -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 diff --git a/go/internal/api/api_control_scenarios_test.go b/go/internal/api/api_control_scenarios_test.go index 365957861..fa12c5923 100644 --- a/go/internal/api/api_control_scenarios_test.go +++ b/go/internal/api/api_control_scenarios_test.go @@ -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"}, diff --git a/go/internal/config/loadpoint_phase_minimum_test.go b/go/internal/config/loadpoint_phase_minimum_test.go new file mode 100644 index 000000000..cf04dbc63 --- /dev/null +++ b/go/internal/config/loadpoint_phase_minimum_test.go @@ -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) + } + }) + } +} diff --git a/go/internal/config/loadpoint_steps.go b/go/internal/config/loadpoint_steps.go index 445738fb9..c43cc5a7b 100644 --- a/go/internal/config/loadpoint_steps.go +++ b/go/internal/config/loadpoint_steps.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "slices" + "strings" "github.com/srcfl/ftw/go/internal/units" ) @@ -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 +} diff --git a/go/internal/control/sitesim_field_test.go b/go/internal/control/sitesim_field_test.go index 29263817c..d2089fa10 100644 --- a/go/internal/control/sitesim_field_test.go +++ b/go/internal/control/sitesim_field_test.go @@ -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 @@ -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 } @@ -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 } diff --git a/go/internal/loadpoint/controller.go b/go/internal/loadpoint/controller.go index 1987b8b2c..04bc9b24d 100644 --- a/go/internal/loadpoint/controller.go +++ b/go/internal/loadpoint/controller.go @@ -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 { @@ -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 @@ -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 } @@ -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" @@ -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 diff --git a/go/internal/loadpoint/controller_fuse_budget.go b/go/internal/loadpoint/controller_fuse_budget.go index 938db18e0..d2d5b53f0 100644 --- a/go/internal/loadpoint/controller_fuse_budget.go +++ b/go/internal/loadpoint/controller_fuse_budget.go @@ -2,6 +2,7 @@ package loadpoint import ( "math" + "slices" "sort" "time" ) @@ -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) } @@ -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 @@ -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 } } @@ -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 } diff --git a/go/internal/loadpoint/loadpoint.go b/go/internal/loadpoint/loadpoint.go index e532d9d3a..2c38879d9 100644 --- a/go/internal/loadpoint/loadpoint.go +++ b/go/internal/loadpoint/loadpoint.go @@ -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"` @@ -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{}) diff --git a/go/internal/loadpoint/manual_limits.go b/go/internal/loadpoint/manual_limits.go index c0f12a08b..12b4f1c77 100644 --- a/go/internal/loadpoint/manual_limits.go +++ b/go/internal/loadpoint/manual_limits.go @@ -1,27 +1,46 @@ package loadpoint -import "math" +import ( + "math" + "slices" +) // A manual selection is a ceiling. Never round it up to a larger step or -// let it bypass the configured charger's rating. -func clampManualPower(cfg Config, hold ManualHold, site SiteFuse) float64 { - minimum := manualMinChargeW(cfg, hold, site) - w := floorChargeW(hold.PowerW, minimum, cfg.MaxChargeW, cfg.AllowedStepsW) +// let it bypass the configured charger's rating. The app's full power is +// the configured maximum: on phases whose minimum is above it, full power +// is that minimum. The reason names what held the order below the hold: +// below_phase_minimum when the hold is under the lowest level its phases +// can run, charger_limit for any other limit. +func clampManualPower(cfg Config, hold ManualHold, site SiteFuse) (float64, string) { + mode := holdPhaseMode(hold, cfg, site) + limits := phaseLimits(cfg, mode, site) + ceiling := hold.PowerW + if cfg.MaxChargeW > 0 && ceiling >= cfg.MaxChargeW { + ceiling = math.Max(ceiling, limits.MaxChargeW) + } + w := floorChargeW(ceiling, limits.MinChargeW, limits.MaxChargeW, limits.AllowedStepsW) amps := hold.MaxAmpsPerPhase if site.MaxAmps > 0 && (!finite(amps) || amps <= 0 || amps > site.MaxAmps) { amps = site.MaxAmps } - if amps <= 0 { - return w + if amps > 0 { + w = manualCurrentCeiling(w, amps, mode, cfg, hold, site) + w = floorChargeW(w, limits.MinChargeW, limits.MaxChargeW, limits.AllowedStepsW) } - mode := hold.PhaseMode - if mode == "" { - mode = cfg.PhaseMode + switch { + case w >= hold.PowerW: + return w, "" + case w == 0 && ceiling < limits.MinChargeW: + return 0, "below_phase_minimum" } + return w, "charger_limit" +} + +// manualCurrentCeiling is w under the hold's current ceiling, as the +// command's own check will apply it. +func manualCurrentCeiling(w, amps float64, mode string, cfg Config, hold ManualHold, site SiteFuse) float64 { if site.Phases() == 1 { mode = "1p" - } else if mode == "" && cfg.SurplusOnly { - mode = "auto" } voltage := site.Voltage if voltage <= 0 { @@ -36,18 +55,26 @@ func clampManualPower(cfg Config, hold ManualHold, site SiteFuse) float64 { // Apply the same final ceiling until that phase choice is stable. for applyCurrentCeiling(cmd) { } - return floorChargeW(cmd["power_w"].(float64), minimum, cfg.MaxChargeW, cfg.AllowedStepsW) + return cmd["power_w"].(float64) } -func manualMinChargeW(cfg Config, hold ManualHold, site SiteFuse) float64 { - mode := hold.PhaseMode - if mode == "" { - mode = cfg.PhaseMode - } - if mode == "1p" || mode == "auto" { - return phaseMinChargeW(cfg, mode, site) - } - return cfg.MinChargeW +// phaseLimits holds cfg to the orders a command on mode's phases can run: +// at least 6 A on each phase. A maximum below that cannot be met on those +// phases, so the order runs at the minimum, the lowest level the charger +// has there. So does a step table with no level in reach. Startup and save +// warn about such a loadpoint (srcfl/ftw#1861). +func phaseLimits(cfg Config, mode string, site SiteFuse) Config { + cfg.MinChargeW = phaseMinChargeW(cfg, mode, site) + if cfg.MaxChargeW > 0 && cfg.MaxChargeW < cfg.MinChargeW { + cfg.MaxChargeW = cfg.MinChargeW + } + inReach := func(w float64) bool { + return w > 0 && w >= cfg.MinChargeW && (cfg.MaxChargeW <= 0 || w <= cfg.MaxChargeW) + } + if cfg.MinChargeW > 0 && len(cfg.AllowedStepsW) > 0 && !slices.ContainsFunc(cfg.AllowedStepsW, inReach) { + cfg.AllowedStepsW = []float64{0, cfg.MinChargeW} + } + return cfg } // phaseMinChargeW is the smallest legal offer on the phases a command names: diff --git a/go/internal/loadpoint/manual_limits_test.go b/go/internal/loadpoint/manual_limits_test.go index 429cdd258..c35156867 100644 --- a/go/internal/loadpoint/manual_limits_test.go +++ b/go/internal/loadpoint/manual_limits_test.go @@ -14,7 +14,7 @@ func TestManualSelectionIsAPowerCeiling(t *testing.T) { {1000, 11000, 0}, {0, 11000, 0}, {math.NaN(), 11000, 0}, } { cfg.MaxChargeW = tc.max - got := clampManualPower(cfg, ManualHold{PowerW: tc.request, PhaseMode: "3p"}, SiteFuse{MaxAmps: 16, Voltage: 230, PhaseCnt: 3}) + got, _ := clampManualPower(cfg, ManualHold{PowerW: tc.request, PhaseMode: "3p"}, SiteFuse{MaxAmps: 16, Voltage: 230, PhaseCnt: 3}) if got != tc.want { t.Errorf("request %v max %v: got %v want %v", tc.request, tc.max, got, tc.want) } diff --git a/go/internal/loadpoint/manual_status.go b/go/internal/loadpoint/manual_status.go index c008c5c8c..4f2b621ee 100644 --- a/go/internal/loadpoint/manual_status.go +++ b/go/internal/loadpoint/manual_status.go @@ -40,7 +40,8 @@ type ManualStatus struct { // current, in its words (reason_no_current_label). Empty when it has none. ChargerReason string `json:"charger_reason,omitempty"` // LimitReason names the clamp behind ManualLimited: "fuse_limit", - // "import_limit", "fuse_cooldown" or "site_meter_stale". + // "import_limit", "fuse_cooldown", "site_meter_stale", "charger_limit" + // or "below_phase_minimum". LimitReason string `json:"limit_reason,omitempty"` } @@ -108,7 +109,7 @@ const ( // before the hold was installed and says nothing about it. func holdClampReason(reason string) bool { switch reason { - case "fuse_limit", "import_limit", "fuse_cooldown", "site_meter_stale", "charger_limit": + case "fuse_limit", "import_limit", "fuse_cooldown", "site_meter_stale", "charger_limit", "below_phase_minimum": return true } return false diff --git a/go/internal/loadpoint/manual_status_test.go b/go/internal/loadpoint/manual_status_test.go index ee3681a8d..c87435162 100644 --- a/go/internal/loadpoint/manual_status_test.go +++ b/go/internal/loadpoint/manual_status_test.go @@ -82,6 +82,11 @@ func TestManualStatusFrom(t *testing.T) { st: ordered(0, "fuse_cooldown", t0.Add(40*time.Second)), ch: easee(0, false, "", false), now: t0.Add(50 * time.Second), wantState: ManualLimited, wantCmdA: 0, wantLimit: "fuse_cooldown", }, + { + name: "a hold below 6 A on each phase gets no order", + st: ordered(0, "below_phase_minimum", t0.Add(2*time.Second)), ch: easee(0, false, "", false), + now: t0.Add(10 * time.Second), wantState: ManualLimited, wantCmdA: 0, wantLimit: "below_phase_minimum", + }, { name: "a charger without a limit reading is only ever sent or charging", st: ordered(11040, "manual_hold", t0.Add(2*time.Second)), ch: ChargerReading{Known: true}, diff --git a/go/internal/loadpoint/one_phase_car.go b/go/internal/loadpoint/one_phase_car.go index ca2c1d816..84f763610 100644 --- a/go/internal/loadpoint/one_phase_car.go +++ b/go/internal/loadpoint/one_phase_car.go @@ -242,6 +242,7 @@ func (m *Manager) observeSteadyPhase(s *carPhases, amps [3]float64, drawA float6 // chargerPhaseMaxA is the most current a charger offers on each phase of a // three-phase order: its maximum over three phases, within the site fuse. +// A maximum below 6 A a phase still runs at 6 A (srcfl/ftw#1861). func chargerPhaseMaxA(cfg Config, site SiteFuse) float64 { voltage := site.Voltage if !finite(voltage) || voltage <= 0 { @@ -249,7 +250,7 @@ func chargerPhaseMaxA(cfg Config, site SiteFuse) float64 { } maxA := 32.0 if finite(cfg.MaxChargeW) && cfg.MaxChargeW > 0 { - maxA = math.Floor(cfg.MaxChargeW/(3*voltage) + 1e-9) + maxA = math.Max(6, math.Floor(cfg.MaxChargeW/(3*voltage)+1e-9)) } if finite(site.MaxAmps) && site.MaxAmps > 0 { maxA = math.Min(maxA, math.Floor(site.MaxAmps)) diff --git a/go/internal/loadpoint/phase_minimum_test.go b/go/internal/loadpoint/phase_minimum_test.go new file mode 100644 index 000000000..71d1a28ab --- /dev/null +++ b/go/internal/loadpoint/phase_minimum_test.go @@ -0,0 +1,190 @@ +package loadpoint + +import ( + "context" + "slices" + "testing" + "time" +) + +// srcfl/ftw#1861, v0.155.1-beta.1: a loadpoint pinned to 3p with min = max = +// 3,800 W and steps [0, 3800]. Three phases cannot run below 6 A each, +// 4,140 W at 230 V, so the order's minimum rose above its maximum and every +// planned slot went out as 0 W with the reason "plan". The car did not charge +// all weekend. The order is now the lowest level the charger can run on its +// phases, and the planner plans with that level. +var issue1861Site = SiteFuse{MaxAmps: 20, Voltage: 230, PhaseCnt: 3} + +func issue1861Loadpoint(mode string, steps []float64) Config { + return Config{ID: "rav4", DriverName: "easee", MinChargeW: 3800, MaxChargeW: 3800, PhaseMode: mode, AllowedStepsW: steps} +} + +func TestSnapChargeWMaximumBelowMinimumRunsAtMinimum(t *testing.T) { + for _, c := range []struct { + name string + steps []float64 + want float64 + }{ + {"no table", nil, 4140}, + {"a table with the minimum", []float64{0, 3800, 4140}, 4140}, + {"a table without it", []float64{0, 3800}, 0}, + } { + if got := SnapChargeW(3800, 4140, 3800, c.steps); got != c.want { + t.Errorf("%s: SnapChargeW(3800, min 4140, max 3800) = %.0f W, want %.0f W", c.name, got, c.want) + } + } + if got := SnapChargeW(0, 4140, 3800, nil); got != 0 { + t.Errorf("no request snapped to %.0f W, want off", got) + } +} + +func TestPhasePinBelowThreePhaseMinimumPlansTheLowestLevel(t *testing.T) { + for _, steps := range [][]float64{{0, 3800}, nil} { + cfg := issue1861Loadpoint("3p", steps) + if got := PlanningSteps(cfg, issue1861Site); !slices.Equal(got, []float64{0, 4140}) { + t.Errorf("steps %v: planner steps %v, want [0 4140]", steps, got) + } + st := State{ID: cfg.ID, MinChargeW: cfg.MinChargeW, MaxChargeW: cfg.MaxChargeW, AllowedStepsW: steps} + minW, maxW, got := PlanningLimits(st, cfg, issue1861Site) + if minW != 4140 || maxW != 4140 || !slices.Equal(got, []float64{0, 4140}) { + t.Errorf("steps %v: planning limits %.0f-%.0f W %v, want 4140-4140 W [0 4140]", steps, minW, maxW, got) + } + // A one-phase car takes 6 A on its one phase. + st.CarPhases = 1 + if minW, maxW, got := PlanningLimits(st, cfg, issue1861Site); minW != 1380 || maxW != 1380 || !slices.Equal(got, []float64{0, 1380}) { + t.Errorf("steps %v, one-phase car: planning limits %.0f-%.0f W %v, want 1380-1380 W [0 1380]", steps, minW, maxW, got) + } + } + // One phase allowed: the planner gets the level one phase can run, 16 A. + cfg := issue1861Loadpoint("", nil) + st := State{ID: cfg.ID, MinChargeW: cfg.MinChargeW, MaxChargeW: cfg.MaxChargeW} + if minW, maxW, got := PlanningLimits(st, cfg, issue1861Site); minW != 3680 || maxW != 3800 || !slices.Equal(got, []float64{0, 3680}) { + t.Errorf("unset mode, no table: planning limits %.0f-%.0f W %v, want 3680-3800 W [0 3680]", minW, maxW, got) + } +} + +// issue1861Tick runs one controller tick and returns the order and its reason. +func issue1861Tick(t *testing.T, cfg Config, dir *Directive, hold *ManualHold) (sentCommand, string) { + t.Helper() + now := time.Now() + if dir != nil { + dir.SlotStart, dir.SlotEnd = now.Add(-time.Second), now.Add(15*time.Minute) + } + sender := &fakeSender{} + c := newTestController(t, []Config{cfg}, dir, map[string]EVSample{cfg.DriverName: {Connected: true}}, sender) + c.SetSiteFuse(issue1861Site) + if hold != nil { + hold.StartedAt, hold.UpdatedAt, hold.Persistent = now, now, true + c.SetManualHold(cfg.ID, *hold) + } + c.Tick(context.Background(), now) + cmd, ok := lastSetCurrent(sender.calls) + if !ok { + t.Fatal("no order went out") + } + st, _ := c.manager.State(cfg.ID) + return cmd, st.CommandedReason +} + +func TestPhasePinBelowThreePhaseMinimumCharges(t *testing.T) { + for _, steps := range [][]float64{{0, 3800}, nil} { + cfg := issue1861Loadpoint("3p", steps) + // The slot the old planner sent: 3,800 W for the whole quarter hour. + dir := &Directive{LoadpointEnergyWh: map[string]float64{cfg.ID: 950}, LoadpointMaxPowerW: map[string]float64{cfg.ID: 3800}} + if cmd, reason := issue1861Tick(t, cfg, dir, nil); cmd.power != 4140 || cmd.phaseMode != "3p" || reason != "plan" { + t.Errorf("steps %v, old plan: sent %.0f W %q (%s), want 4140 W \"3p\" (plan)", steps, cmd.power, cmd.phaseMode, reason) + } + // The plan with the levels it now gets. + dir = &Directive{LoadpointEnergyWh: map[string]float64{cfg.ID: 1035}, LoadpointMaxPowerW: map[string]float64{cfg.ID: 4140}} + if cmd, reason := issue1861Tick(t, cfg, dir, nil); cmd.power != 4140 || cmd.phaseMode != "3p" || reason != "plan" { + t.Errorf("steps %v: sent %.0f W %q (%s), want 4140 W \"3p\" (plan)", steps, cmd.power, cmd.phaseMode, reason) + } + // Charge now from the app asks for the loadpoint's maximum. + hold := &ManualHold{PowerW: 3800, PhaseMode: "3p"} + if cmd, reason := issue1861Tick(t, cfg, nil, hold); cmd.power != 4140 || cmd.phaseMode != "3p" || reason != "manual_hold" { + t.Errorf("steps %v, Charge now: sent %.0f W %q (%s), want 4140 W \"3p\" (manual_hold)", steps, cmd.power, cmd.phaseMode, reason) + } + } +} + +// One phase allowed and the level fits: the order runs on one phase, as +// before. The charger's 16 A on one phase holds it to 3,680 W. +func TestBelowThreePhaseMinimumUsesOnePhaseWhereAllowed(t *testing.T) { + for _, mode := range []string{"", "auto"} { + cfg := issue1861Loadpoint(mode, []float64{0, 3800}) + dir := &Directive{LoadpointEnergyWh: map[string]float64{cfg.ID: 950}, LoadpointMaxPowerW: map[string]float64{cfg.ID: 3800}} + if cmd, _ := issue1861Tick(t, cfg, dir, nil); cmd.power != 3680 || cmd.phaseMode != "1p" { + t.Errorf("%q: sent %.0f W %q, want 3680 W \"1p\"", mode, cmd.power, cmd.phaseMode) + } + } + // The app names three phases for a three-phase loadpoint. A level below + // 6 A on each goes out where the loadpoint allows one phase. + cfg := Config{ID: "garage", DriverName: "easee", MinChargeW: 1380, MaxChargeW: 11000, PhaseMode: "auto", AllowedStepsW: ftwStepSet} + if cmd, reason := issue1861Tick(t, cfg, nil, &ManualHold{PowerW: 2760, PhaseMode: "3p"}); cmd.power != 2760 || cmd.phaseMode != "auto" || reason != "manual_hold" { + t.Errorf("auto, 2,760 W from the app: sent %.0f W %q (%s), want 2760 W \"auto\" (manual_hold)", cmd.power, cmd.phaseMode, reason) + } +} + +// No valid order: a hold below 6 A on each phase of a loadpoint pinned to +// three. A hold is a ceiling, so it is not raised; the reason says why the +// car gets nothing. +func TestHoldBelowPhaseMinimumSaysSo(t *testing.T) { + cfg := Config{ID: "garage", DriverName: "easee", MinChargeW: 1380, MaxChargeW: 11000, PhaseMode: "3p", AllowedStepsW: ftwStepSet} + cmd, reason := issue1861Tick(t, cfg, nil, &ManualHold{PowerW: 2760, PhaseMode: "3p"}) + if cmd.power != 0 || reason != "below_phase_minimum" { + t.Errorf("3p pin, 2,760 W hold: sent %.0f W %q (%s), want 0 W (below_phase_minimum)", cmd.power, cmd.phaseMode, reason) + } +} + +// Surplus, a wake-kick and the car's own completion order the loadpoint's +// maximum or a surplus level; on three phases below 6 A each those run at +// the lowest three-phase level too. The order's current cap names 6 A. +func TestBelowThreePhaseMinimumEveryOrderRuns(t *testing.T) { + for _, steps := range [][]float64{{0, 3800}, nil} { + cfg := issue1861Loadpoint("3p", steps) + cfg.SurplusOnly = true + now := time.Date(2026, 10, 24, 12, 0, 0, 0, time.UTC) + sender := &fakeSender{} + c := newTestController(t, []Config{cfg}, nil, map[string]EVSample{cfg.DriverName: {Connected: true, RequestActive: true}}, sender) + c.SetSiteFuse(issue1861Site) + c.SetSiteSurplusForEV(func() (float64, bool) { return 10000, true }) + c.SetPeakRemainingSurplusW(func() (float64, bool) { return 10000, true }) + c.SetFuseEVMax(meteredEVCap(c, func() float64 { return 3 })) + for i := range 12 { + c.Tick(context.Background(), now.Add(time.Duration(i)*5*time.Second)) + } + cmd, _ := lastSetCurrent(sender.calls) + st, _ := c.manager.State(cfg.ID) + if cmd.power != 4140 || cmd.phaseMode != "3p" || st.CommandedReason != "pv_surplus" { + t.Errorf("steps %v, 10 kW surplus: sent %.0f W %q (%s), want 4140 W \"3p\" (pv_surplus)", steps, cmd.power, cmd.phaseMode, st.CommandedReason) + } + if cmd.capAmpsPerPhase == nil { + t.Errorf("steps %v: no cap_amps_per_phase", steps) + } else if *cmd.capAmpsPerPhase < 6 { + t.Errorf("steps %v: cap_amps_per_phase %.2f A under the 6 A order", steps, *cmd.capAmpsPerPhase) + } + } +} + +// A plan level below the least order its phases run goes out at that +// order, on only as long as the slot's energy lasts: 2,070 Wh at 4,140 W +// is 30 min, not the 34.5 min the 3,600 W level would take. +func TestPlanLevelBelowPhaseMinimumKeepsTheSlotsEnergy(t *testing.T) { + cfg := Config{ID: "garage", DriverName: "easee", MinChargeW: 4140, MaxChargeW: 11040, PhaseMode: "3p"} + start := time.Date(2026, 10, 24, 1, 0, 0, 0, time.UTC) + dir := &Directive{SlotStart: start, SlotEnd: start.Add(time.Hour), + LoadpointEnergyWh: map[string]float64{cfg.ID: 2070}, LoadpointMaxPowerW: map[string]float64{cfg.ID: 3600}} + samples := map[string]EVSample{cfg.DriverName: {Connected: true}} + sender := &fakeSender{} + c := newTestController(t, []Config{cfg}, dir, samples, sender) + c.SetSiteFuse(issue1861Site) + c.Tick(context.Background(), start) + if cmd, _ := lastSetCurrent(sender.calls); cmd.power != 4140 { + t.Fatalf("a 3,600 W level sent %.0f W, want 4140 W", cmd.power) + } + samples[cfg.DriverName] = EVSample{Connected: true, PowerW: 4140, SessionWh: 2070} + c.Tick(context.Background(), start.Add(32*time.Minute)) + if cmd, _ := lastSetCurrent(sender.calls); cmd.power != 0 { + t.Errorf("slot energy spent at 32 min, still sent %.0f W", cmd.power) + } +} diff --git a/go/internal/loadpoint/planning_steps.go b/go/internal/loadpoint/planning_steps.go index 538d70bc3..dfc09c161 100644 --- a/go/internal/loadpoint/planning_steps.go +++ b/go/internal/loadpoint/planning_steps.go @@ -11,10 +11,14 @@ import ( // charger's explicit steps keep those at or above 6 A on its phases; one- // phase levels in a shared table would let the plan spread a night at 3 kW // that only one phase can deliver. Other explicit steps keep their meaning. +// A three-phase charger whose maximum or table stops below 6 A on each +// phase gets that level alone, as phaseLimits orders it. func PlanningSteps(cfg Config, site SiteFuse) []float64 { phases := site.Phases() if !threePhaseCapable(cfg, site) { phases = 1 + } else { + cfg = phaseLimits(cfg, "3p", site) } voltage := site.Voltage if voltage <= 0 { @@ -33,11 +37,13 @@ func PlanningSteps(cfg Config, site SiteFuse) []float64 { } return steps } - minimum := math.Max(6, math.Ceil(cfg.MinChargeW/step)) - maximum := math.Floor(cfg.MaxChargeW / step) + minimum := math.Max(6, math.Ceil(cfg.MinChargeW/step-1e-9)) + maximum := math.Floor(cfg.MaxChargeW/step + 1e-9) if site.MaxAmps > 0 { maximum = math.Min(maximum, math.Floor(site.MaxAmps)) } + // A minimum and maximum between two whole amps leave the highest. + minimum = math.Min(minimum, math.Max(maximum, 6)) steps := []float64{0} // IEC home charging is bounded here even if stored configuration is bad. if !finite(minimum) || !finite(maximum) || maximum > 1000 { @@ -57,6 +63,14 @@ func PlanningSteps(cfg Config, site SiteFuse) []float64 { // minimum allow. The charger's own minimum would leave the planner no level. func PlanningLimits(st State, cfg Config, site SiteFuse) (minW, maxW float64, steps []float64) { planning := PlanningSteps(cfg, site) + // The session's range holds the levels the charger can run: a maximum + // below the lowest is raised to it, a minimum above the highest lowered. + if levels := slices.DeleteFunc(slices.Clone(planning), func(w float64) bool { return w <= 0 }); len(levels) > 0 { + if lowest := slices.Min(levels); st.MaxChargeW > 0 && st.MaxChargeW < lowest { + st.MaxChargeW = lowest + } + st.MinChargeW = math.Min(st.MinChargeW, slices.Max(levels)) + } if st.CarPhases == 1 && threePhaseCapable(cfg, site) { topW := OnePhaseCarMaxW(cfg, site) levels := []float64{0} @@ -102,6 +116,9 @@ func threePhaseCapable(cfg Config, site SiteFuse) bool { if site.Phases() != 3 || cfg.PhaseMode == "1p" { return false } + if cfg.PhaseMode == "3p" { + return true // Pinned: it runs three phases, at 6 A on each or more. + } voltage := site.Voltage if !finite(voltage) || voltage <= 0 { voltage = 230 diff --git a/go/internal/loadpoint/snap.go b/go/internal/loadpoint/snap.go index de544f79b..9e4af6ee5 100644 --- a/go/internal/loadpoint/snap.go +++ b/go/internal/loadpoint/snap.go @@ -4,20 +4,21 @@ import "math" // SnapChargeW picks the nearest feasible step. want <= 0 is off, not // the minimum step. Nearest, not floor: float error just under a step -// must still hit that step. +// must still hit that step. A maximum below the minimum cannot be met: +// the minimum is the lowest level the charger can run, so it runs there. func SnapChargeW(want, min, max float64, steps []float64) float64 { if math.IsNaN(want) || math.IsInf(want, 0) || want <= 0 { return 0 } + if max > 0 && max < min { + max = min + } if want < min { want = min } if max > 0 && want > max { want = max } - if max > 0 && max < min { - return 0 - } if len(steps) == 0 { return want } diff --git a/go/internal/mpc/deadline_directive.go b/go/internal/mpc/deadline_directive.go index e943a10b4..e46c5c718 100644 --- a/go/internal/mpc/deadline_directive.go +++ b/go/internal/mpc/deadline_directive.go @@ -32,10 +32,14 @@ func (s *Service) withDeadlineReserve(now time.Time, d SlotDirective, accepted b if st.ManualActive && st.PluggedIn { // Manual intent has already passed the charger's own clamps. // Reserve its ceiling, including an explicit Stop, without - // turning it into a saved scheduled goal. + // turning it into a saved scheduled goal. Full power below the + // least order its phases run is that order (srcfl/ftw#1861). peak, ok = 0, true if finite(st.ManualChargeW) && st.ManualChargeW > 0 && finite(st.MaxChargeW) && st.MaxChargeW > 0 { peak = min(st.ManualChargeW, st.MaxChargeW) + if peak == st.MaxChargeW && finite(minW) { + peak = max(peak, minW) + } } need = peak * d.SlotEnd.Sub(now).Hours() } diff --git a/go/internal/mpc/deadline_directive_test.go b/go/internal/mpc/deadline_directive_test.go index 924b49204..15f7e0c2f 100644 --- a/go/internal/mpc/deadline_directive_test.go +++ b/go/internal/mpc/deadline_directive_test.go @@ -171,3 +171,22 @@ func TestGoalReserveHoldsToThePlansLimits(t *testing.T) { } } } + +// srcfl/ftw#1861: Charge now at full power on a loadpoint pinned to 3p with +// a 3,800 W maximum runs at 4,140 W, 6 A on each phase. The reserve holds +// what Core orders, not the configured maximum. +func TestManualReserveHoldsTheLowestThreePhaseLevel(t *testing.T) { + now := time.Now() + cfg := loadpoint.Config{ID: "a", MinChargeW: 3800, MaxChargeW: 3800, AllowedStepsW: []float64{0, 3800}, PhaseMode: "3p"} + site := loadpoint.SiteFuse{MaxAmps: 20, Voltage: 230, PhaseCnt: 3} + for _, holdW := range []float64{3800, 4140} { + st := deadlineGoalState(now, "a") + st.MinChargeW, st.MaxChargeW, st.AllowedStepsW = cfg.MinChargeW, cfg.MaxChargeW, cfg.AllowedStepsW + st.ManualActive, st.ManualChargeW = true, holdW + svc := &Service{LoadpointStates: func() []loadpoint.State { return []loadpoint.State{st} }, + PlanningLimits: func(st loadpoint.State) (float64, float64, []float64) { return loadpoint.PlanningLimits(st, cfg, site) }} + if d, ok := svc.SlotDirectiveAt(now); !ok || d.LoadpointMaxPowerW["a"] != 4140 { + t.Errorf("Charge now %.0f W: reserve %+v ok=%v, want 4140 W", holdW, d, ok) + } + } +} diff --git a/web/app.js b/web/app.js index 6903f25b1..62e2850be 100644 --- a/web/app.js +++ b/web/app.js @@ -2894,6 +2894,7 @@ (reason || " Check the car's own charge limit or schedule, then the charger's app."); case "limited": if (m.limit_reason === "charger_limit") return "The charger limits this request to " + cmdA + " (" + reqA + " requested)."; + if (m.limit_reason === "below_phase_minimum") return "Not charging: " + reqA + " is below 6 A on each phase, and no charger runs lower. Ask for 6 A or more."; if (m.limit_reason === "fuse_cooldown") { return "Paused by site power limits — " + reqA + " requested; charging resumes on its own." + sinceP; } @@ -3571,6 +3572,9 @@ var minA = Math.max(1, Math.round(wToA((lp && lp.min_charge_w) || 0)) || 6); var topW = evChargeNowTopW(lp); + // No charger runs below 6 A a phase: Core orders a top below that at + // 6 A (srcfl/ftw#1861). + if (topW > 0 && topW < aToW(6)) { topW = aToW(6); } var maxA = Math.round(wToA(topW)) || 16; if (maxA <= minA) { maxA = minA + 1; } // orderW is the hold a slider position sends. The top sends the top step @@ -3578,6 +3582,8 @@ // watts to the step below (10,400 W at 3 × 230 V reads 15 A, and // 15 A = 10,350 W orders 9,700 W). function orderW(a) { return a >= maxA && topW > 0 ? topW : aToW(a); } + // orderA is the current that order names: the top is the top step's. + function orderA(a) { return Math.round(wToA(orderW(a))); } var active = !!(lp && lp.manual_active); var curA = active ? Math.round(wToA((lp && lp.manual_charge_w) || 0)) : maxA; @@ -3631,7 +3637,7 @@ readout.style.color = "var(--fg)"; function renderReadout() { var a = parseInt(slider.value, 10) || minA; - readout.textContent = a + " A · " + (orderW(a) / 1000).toFixed(1) + " kW"; + readout.textContent = orderA(a) + " A · " + (orderW(a) / 1000).toFixed(1) + " kW"; } renderReadout(); var currentEditingUntil = 0; @@ -3651,7 +3657,7 @@ status.style.minHeight = "1em"; status.setAttribute("role", "status"); status.setAttribute("aria-live", "polite"); - var idleText = "Starts at up to " + maxA + " A · " + (orderW(maxA) / 1000).toFixed(1) + " kW. Ignores the goal and solar rule until you return to the plan or unplug."; + var idleText = "Starts at up to " + orderA(maxA) + " A · " + (orderW(maxA) / 1000).toFixed(1) + " kW. Ignores the goal and solar rule until you return to the plan or unplug."; status.textContent = active ? "Changes apply when you release the slider." : idleText; box.appendChild(status); @@ -3756,7 +3762,7 @@ startBtn.disabled = true; var a = parseInt(slider.value, 10) || minA; pauseBtn.disabled = true; - status.textContent = pause ? "Sending pause request…" : "Asking FTW for " + a + " A…"; + status.textContent = pause ? "Sending pause request…" : "Asking FTW for " + orderA(a) + " A…"; // CONTROL write — strict (FIX-B): persistent manual hold (hold_s:0) // with no SoC release — see the note above the slider. evWrite("/api/loadpoints/" + encodeURIComponent(lp.id) + "/manual_hold", { @@ -3770,7 +3776,7 @@ }).then(failOn).then(function () { busy = false; slider.disabled = false; - status.textContent = pause ? "Pause requested. Waiting for the charger to stop…" : "FTW received " + a + " A. Waiting for the charger…"; + status.textContent = pause ? "Pause requested. Waiting for the charger to stop…" : "FTW received " + orderA(a) + " A. Waiting for the charger…"; holdLineUntil = Date.now() + 6000; refreshEvModalAfterWrite(); // read the hold and charger response without rebuilding focused inputs }).catch(function (e) { diff --git a/web/control-feedback.js b/web/control-feedback.js index e81644039..25c5b554e 100644 --- a/web/control-feedback.js +++ b/web/control-feedback.js @@ -66,7 +66,7 @@ const REASON_TITLES = { core_limit: 'Limited by FTW', fuse_limit: 'Limited by the main fuse', fuse_cooldown: 'Waiting after a site power limit', import_limit: 'Limited by the hourly import limit', charger_limit: 'Limited by FTW’s charger setting', device_limit: 'Charger limit', offered_current_lower: 'Charger offers less current', - one_phase: 'Charging on one phase', + one_phase: 'Charging on one phase', below_phase_minimum: 'Below 6 A a phase', device_fault: 'Device fault', telemetry_stale: 'No fresh readings', readings_lost: 'Lost control', command_failed: 'Commands failing', command_unconfirmed: 'Command not confirmed', default_failed: 'Cannot hand back control', response_unknown: 'No power reading', observe_only: 'Monitoring only', disabled: 'Disabled', device_control: 'Own control', @@ -98,6 +98,7 @@ function sentence(row) { case 'import_limit': return `FTW lowered the rate to ${target(row)} to keep this hour’s grid import within its limit.`; case 'fuse_cooldown': return 'FTW waits a moment after a site power limit before it raises the rate.'; case 'charger_limit': return 'The charger limit in FTW’s settings caps the rate.'; + case 'below_phase_minimum': return 'Not charging: the request is below 6 A on each phase, and no charger runs lower.'; case 'device_limit': return `The charger’s own limit is ${amps(row.device_limit_a)}, below the ${amps(row.requested_a)} FTW asked for.`; case 'offered_current_lower': return `The charger offers ${amps(row.offered_a)}, below the ${amps(row.requested_a)} FTW asked for.`; case 'one_phase': return `The car charges on ${row.charging_phase || 'one phase'} only${num(row.charging_phase_max_w) ? `, at most ${controlPower(row.charging_phase_max_w)}` : ''}. FTW plans with what it takes.`; @@ -136,6 +137,7 @@ function nextStep(row) { return `Check the ${name}’s connection.`; case 'site_meter_stale': case 'site_phase_currents_stale': return 'Check the grid meter’s connection.'; case 'device_limit': return 'Raise the limit in the charger’s app if you want faster charging.'; + case 'below_phase_minimum': return 'Ask for 6 A or more, or set the charger’s phase mode to auto if it can switch to one phase.'; case 'offered_current_lower': return 'Check the charger’s load balancing and limits.'; case 'observe_only': return 'Turn on control in the device settings if you want FTW to steer it.'; default: return ''; diff --git a/web/control-feedback.test.mjs b/web/control-feedback.test.mjs index 9250313ca..8a33e46fa 100644 --- a/web/control-feedback.test.mjs +++ b/web/control-feedback.test.mjs @@ -160,3 +160,11 @@ test('limited positive EV offer does not explain prolonged zero delivery', () => assert.match(hour.text,/this hour’s grid import/); assert.doesNotMatch(hour.text,/fuse/); }); + +test('no order below 6 A a phase says why the car gets nothing', () => { + const below=controlStatus(row({kind:'ev',status:'limited',reason:'below_phase_minimum',severity:'warning',sent_w:0,actual_w:0})); + assert.equal(below.title,'Below 6 A a phase'); + assert.match(below.text,/6 A on each phase/); + assert.match(below.next,/phase mode/); + assert.doesNotMatch(below.text,/cannot describe/); +}); diff --git a/web/ev-charge-now-range.test.mjs b/web/ev-charge-now-range.test.mjs index 7e2e8172c..d6536f006 100644 --- a/web/ev-charge-now-range.test.mjs +++ b/web/ev-charge-now-range.test.mjs @@ -121,3 +121,17 @@ test('a hold at the top step reads as the top', () => { assert.equal(ui.slider.value, '15'); assert.equal(ui.readout.textContent, '15 A · 10.4 kW'); }); + +// srcfl/ftw#1861: a three-phase loadpoint with a maximum of 3,800 W, below +// 6 A on each phase. Core orders 4,140 W, the lowest three-phase level; the +// slider read "7 A · 3.8 kW". +test('a top below 6 A a phase reads and orders 6 A, as Core does', () => { + const ui = build({ + id: 'rav4', phases: 3, voltage_v: 230, plugged_in: true, + min_charge_w: 3800, max_charge_w: 3800, allowed_steps_w: [0, 3800], + }); + assert.equal(ui.readout.textContent, '6 A · 4.1 kW'); + assert.match(ui.status.textContent, /^Starts at up to 6 A · 4\.1 kW\./); + ui.start.fire('click'); + assert.deepEqual(ui.sent, [{ power_w: 4140, hold_s: 0, phase_mode: '3p' }]); +}); diff --git a/web/ev-manual-feedback.test.mjs b/web/ev-manual-feedback.test.mjs index 96aba8e1f..f071bcf35 100644 --- a/web/ev-manual-feedback.test.mjs +++ b/web/ev-manual-feedback.test.mjs @@ -90,6 +90,14 @@ test('pause status waits for the charger before claiming it stopped', () => { }); +test('a hold below 6 A a phase says it gets no order', () => { + const words = describeManual({ ...lp, manual: { ...lp.manual, state: 'limited', limit_reason: 'below_phase_minimum', commanded_a: 0 } }); + assert.match(words, /Not charging/); + assert.match(words, /6 A on each phase/); + assert.doesNotMatch(words, /Site power limits/); +}); + + test('a charger limit does not blame the main fuse', () => { const words = describeManual({ ...lp, manual: { ...lp.manual, state: 'limited', limit_reason: 'charger_limit', commanded_a: 10 } }); assert.match(words, /The charger limits this request to 10 A/);