Skip to content
Merged
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/show-charger-reported-reason.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

Show the charger's reported reason in EV charging shortfall messages when current charger readings include an explanation.
26 changes: 25 additions & 1 deletion go/internal/api/api_control_feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,30 @@ type feedbackReading struct {
DeviceLimitA *float64 `json:"device_limit_a"`
DeviceLimitAgeS *float64 `json:"device_limit_age_s"`
Reason string `json:"reason_no_current_label"`
ReasonObservedAt string `json:"reason_observed_at"`
StateObservedAt string `json:"state_observed_at"`
LimitA *float64 `json:"current_limit_a"`
LimitedBy string `json:"current_limited_by"`
Connected *bool `json:"connected"`
Online *bool `json:"is_online"`
}

// Timestamped reasons describe the charger state in which they were reported.
func (d feedbackReading) currentChargerReason(now time.Time) string {
if d.Reason == "" || d.ReasonObservedAt == "" {
return d.Reason
}
reasonAt, err := time.Parse(time.RFC3339Nano, d.ReasonObservedAt)
if err != nil || reasonAt.After(now) {
return ""
}
stateAt, err := time.Parse(time.RFC3339Nano, d.StateObservedAt)
if err == nil && reasonAt.Before(stateAt) {
return ""
}
return d.Reason
}

func watts(v float64) *float64 {
if math.IsNaN(v) || math.IsInf(v, 0) {
return nil
Expand Down Expand Up @@ -173,7 +191,10 @@ func (s *Server) controlFeedback(now time.Time) []ControlFeedback {
f := ControlFeedback{Driver: rd.Driver, Kind: kind.String(), Mode: mode, State: "waiting", Reason: "no_command", Severity: "info", Response: "unconfirmed"}
var d feedbackReading
_ = json.Unmarshal(rd.Data, &d)
f.ReadbackW, f.OfferedA, f.DeviceReason = d.SetpointW, d.MaxA, d.Reason
f.ReadbackW, f.OfferedA = d.SetpointW, d.MaxA
if kind != telemetry.DerEV {
f.DeviceReason = d.Reason
}
f.DynamicLimitA = d.DynamicLimitA
pilotAge, pilotValid := pilotReadingAge(d, now)
pilotFresh := pilotValid && pilotAge <= pilotFreshFor
Expand Down Expand Up @@ -209,6 +230,9 @@ func (s *Server) controlFeedback(now time.Time) []ControlFeedback {
if d.Online != nil && !*d.Online {
fresh = false
}
if kind == telemetry.DerEV && fresh && (d.Connected == nil || *d.Connected) {
f.DeviceReason = d.currentChargerReason(now)
}
measurement, powerKnown := telemetry.ControlPowerObservation(rd.RawW, rd.Data, rd.UpdatedAt)
if !measurement.At.IsZero() {
f.ObservedAtMs = measurement.Seen().UnixMilli()
Expand Down
30 changes: 30 additions & 0 deletions go/internal/api/api_control_feedback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,33 @@ func TestFullBatteryFeedbackKeepsEvidenceAndFaultsSeparate(t *testing.T) {
})
}
}

func TestControlFeedbackUsesCurrentChargerReason(t *testing.T) {
now := time.Now()
for _, tc := range []struct {
name, data, want string
age time.Duration
}{
{"same charger state", `{"reason_no_current_label":"limited","reason_observed_at":"2000-01-01T00:00:01Z","state_observed_at":"2000-01-01T00:00:01Z"}`, "limited", 0},
{"older than charger state", `{"reason_no_current_label":"limited","reason_observed_at":"2000-01-01T00:00:00Z","state_observed_at":"2000-01-01T00:00:01Z"}`, "", 0},
{"legacy label", `{"reason_no_current_label":"limited"}`, "limited", 0},
{"stale reading", `{"reason_no_current_label":"limited"}`, "", 2 * time.Minute},
{"offline", `{"is_online":false,"reason_no_current_label":"limited"}`, "", 0},
{"unplugged", `{"connected":false,"reason_no_current_label":"limited"}`, "", 0},
{"future reason", `{"reason_no_current_label":"limited","reason_observed_at":"2999-01-01T00:00:00Z"}`, "", 0},
{"no current label", `{}`, "", 0},
} {
t.Run(tc.name, func(t *testing.T) {
tel := telemetry.NewStore()
tel.Update("charger", telemetry.DerEV, 0, nil, []byte(`{"reason_no_current_label":"previous reason"}`))
cmd := tel.BeginCommand("charger", []byte(`{"action":"ev_set_current","power_w":3680}`), now)
tel.CompleteCommand(cmd, "accepted")
tel.Update("charger", telemetry.DerEV, 0, nil, []byte(tc.data))
srv := New(&Deps{Tel: tel})
rows := srv.controlFeedback(time.Now().Add(tc.age))
if len(rows) != 1 || rows[0].DeviceReason != tc.want {
t.Fatalf("feedback %+v, want charger reason %q", rows, tc.want)
}
})
}
}
2 changes: 1 addition & 1 deletion go/internal/ocpp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ func (h *Handler) pushReading(id string, s *chargerState) {
// the zero out of manual-command acknowledgements in both clients.
data["connection_unknown"] = true
data["is_online"] = false
data["reason_no_current_label"] = "Waiting for charger connection status"
data["state_label"] = "Waiting for charger connection status"
}
h.mu.Unlock()
if !approved {
Expand Down
11 changes: 8 additions & 3 deletions go/internal/ocpp/identity_probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,19 @@ func TestDelayedStatusAfterDisconnectStaysUnknown(t *testing.T) {
h.OnDisconnect("garage")
h.OnStatusNotification("garage", &core.StatusNotificationRequest{ConnectorId: 1, Status: core.ChargePointStatusAvailable, ErrorCode: core.NoError})
var data struct {
Connected *bool `json:"connected"`
Unknown bool `json:"connection_unknown"`
Online *bool `json:"is_online"`
Connected *bool `json:"connected"`
Unknown bool `json:"connection_unknown"`
Online *bool `json:"is_online"`
State string `json:"state_label"`
Reason string `json:"reason_no_current_label"`
}
if err := json.Unmarshal(tel.Get("garage", telemetry.DerEV).Data, &data); err != nil {
t.Fatal(err)
}
if data.Connected != nil || !data.Unknown || data.Online == nil || *data.Online {
t.Fatalf("late status looked physically unplugged: %+v", data)
}
if data.State != "Waiting for charger connection status" || data.Reason != "" {
t.Fatalf("connection wait must be a state, got %+v", data)
}
}
12 changes: 8 additions & 4 deletions web/control-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,22 @@ function evPowerWarning(row) {

function nextStep(row) {
const name = noun(row);
const reported = row.kind === 'ev' && row.readings_fresh === true && typeof row.device_reason === 'string'
? row.device_reason.trim() : '';
const chargerReport = reported ? `The charger reports: ${reported}.` : '';
switch (row.reason) {
case 'power_below_target': case 'power_above_target': case 'power_wrong_direction':
case 'no_power_response': case 'power_while_idle':
case 'power_below_target': case 'no_power_response':
return chargerReport || `The ${name} has not said why. Check its app or display.`;
case 'power_above_target': case 'power_wrong_direction': case 'power_while_idle':
return `The ${name} has not said why. Check its app or display.`;
case 'vehicle_declined': return 'Check the car’s charge limit and schedule.';
case 'setpoint_changed': return 'Another app or controller may be changing it.';
case 'device_fault': return `Check the ${name}.`;
case 'telemetry_stale': case 'readings_lost': case 'command_failed': case 'default_failed':
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 'offered_current_lower': return 'Check the charger’s load balancing and limits.';
case 'device_limit': return [chargerReport, 'Raise the limit in the charger’s app if you want faster charging.'].filter(Boolean).join(' ');
case 'offered_current_lower': return [chargerReport, 'Check the charger’s load balancing and limits.'].filter(Boolean).join(' ');
case 'charger_pilot_limit': return 'Check Available energy in the charger’s app for the active limit.';
case 'load_balancer_limit': return 'If this happens often, compare the charger’s load balancing settings with FTW’s main fuse setting.';
case 'observe_only': return 'Turn on control in the device settings if you want FTW to steer it.';
Expand Down
29 changes: 29 additions & 0 deletions web/control-feedback.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,35 @@ test('the plan and what happens now, in words', () => {
assert.equal(planNowWords({...morning, planned_battery_w: -3000, battery_w: -1000, why: 'less_home'}).then, 'The battery gives only what the home needs.');
});

test('EV shortfalls show the reported reason without changing the verdict', () => {
for (const reason of ['no_power_response', 'power_below_target', 'offered_current_lower', 'device_limit']) {
const ev = row({kind: 'ev', reason, status: 'not_following', severity: 'warning', sent_w: 3680,
actual_w: reason === 'no_power_response' ? 0 : 1400, requested_a: 16, offered_a: 6, device_limit_a: 6,
device_reason: ' current limited by equalizer '});
const before = controlStatus({...ev, device_reason: undefined});
const shown = controlStatus(ev);
const advice = {
device_limit: ' Raise the limit in the charger’s app if you want faster charging.',
offered_current_lower: ' Check the charger’s load balancing and limits.',
};
assert.equal(shown.next, 'The charger reports: current limited by equalizer.' + (advice[reason] || ''));
for (const key of ['title', 'text', 'tone', 'proof']) assert.equal(shown[key], before[key], `${reason}: ${key}`);
assert.doesNotMatch(Object.values(shown).join(' '), /has not said why/);
assert.equal(controlStatus(ev, false).title, 'Status not current');
assert.doesNotMatch(controlStatus({...ev, readings_fresh: false}).next, /equalizer/);
for (const missing of [undefined, null, '', ' ', 29]) {
assert.equal(controlStatus({...ev, device_reason: missing}).next, before.next);
}
}
});

test('a charger reason does not explain excess power or replace a known fault', () => {
for (const reason of ['power_above_target', 'power_wrong_direction', 'power_while_idle', 'command_failed', 'load_balancer_limit']) {
const ev = row({kind: 'ev', reason});
assert.deepEqual(controlStatus({...ev, device_reason: 'limited by schedule'}), controlStatus(ev));
}
});

test('EV warnings show fresh pilot evidence with the measured charging power', () => {
const ev = row({kind: 'ev', status: 'not_following', severity: 'warning',
requested_a: 15, sent_w: 10350, pilot_a: 11, actual_w: 7489, reason: 'power_below_target'});
Expand Down
Loading