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
9 changes: 9 additions & 0 deletions .changeset/battery-limit-words-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"ftw": patch
---

Fix two phrases from the battery limit verdicts. A reported battery limit
without a known target now reads "The battery reports a limit below what FTW
asked for." instead of doubling "the". The Numbers list now labels a
battery's learned current limit "Battery current limit", not "Charger lets
the car take". The words match the web app's.
30 changes: 30 additions & 0 deletions .changeset/inverter-stream-headroom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"ftw": minor
---

Read a hybrid's inverter stream, and say when its inverter has no grid
headroom left.

The driver contract lets a battery or hybrid driver report its AC stage with
`host.emit("inverter", …)`: its power, phases, rating, and
`available_import_W` / `available_export_W`, how much more the inverter will
take from or give to the grid now. Core refused that emit, so the Solis C&I
drivers lost it on every poll. Core now keeps the latest inverter reading per
driver. `/api/status` shows it while the driver is live (`inverter_w`,
`inverter_available_import_w`, `inverter_available_export_w`,
`inverter_updated_at_ms`), and `/api/drivers/{name}` shows the last one with
its age (`inverter`). It is not a device type: no site total, dispatch, fuse
guard or energy ledger reads it, and none of it is written to history. A
field that is not a usable number is left out and the rest kept.

A battery that gives part of its order while its inverter reports, in the
same driver poll, no more import headroom while charging, or no more export
headroom while discharging, now reads "Limited by the inverter", with words
such as "The inverter reports that it can take no more from the grid now.
FTW asked for 5.0 kW charge." A battery that gives nothing keeps its warning,
since a dead battery on a site that may not export sees no export headroom
either; only the battery's own report of 0 available explains it. Headroom
above 100 W, headroom from an earlier poll, and a stale, offline or faulted
driver explain nothing. Wrong direction, power above the order or while
idle, a changed setpoint and lost readings keep their own reasons. Limited
verdicts never send the "not following" notice.
15 changes: 15 additions & 0 deletions go/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,21 @@ func (s *Server) handleStatus(w http.ResponseWriter, r *http.Request) {
}
}
}
// The inverter stream is a battery or hybrid's AC stage. It sits
// beside the driver's readings and is never added to them. Shown
// only while the driver is live, with when it was read.
if inv, ok := s.deps.Tel.LiveInverter(name); ok {
d["inverter_updated_at_ms"] = inv.UpdatedAt.UnixMilli()
if inv.W != nil {
d["inverter_w"] = *inv.W
}
if inv.AvailableImportW != nil {
d["inverter_available_import_w"] = *inv.AvailableImportW
}
if inv.AvailableExportW != nil {
d["inverter_available_export_w"] = *inv.AvailableExportW
}
}
drivers[name] = d
}
// Merge config drivers that aren't in the registry so the UI can
Expand Down
38 changes: 36 additions & 2 deletions go/internal/api/api_control_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (

// A battery that gives 4.3 kW of a 5 kW order because that is all it can do
// now is limited, not out of control. This file judges a battery's shortfall
// against what it can do now: what its driver reports, and the limits it has
// shown before (battery.Plateaus). It changes the verdict and nothing else;
// against what it can do now: what its driver reports for the battery and
// for its inverter's grid headroom, and the limits it has shown before
// (battery.Plateaus). It changes the verdict and nothing else;
// dispatch, fuse protection, clamps and commands never read it.

// batteryNow is what a battery's driver reports it can do now
Expand Down Expand Up @@ -96,6 +97,14 @@ func (b batteryNow) standby() bool { return b.DeviceState == "standby" || b.Devi
// so the words can say why;
// - a reported available_*_W below the order that the battery delivers,
// within the control tolerance, is limited / battery_limit;
// - a battery that gives part of its order while its inverter reports,
// in the same driver poll, no more grid headroom in the order's
// direction (available_import_W while charging, available_export_W
// while discharging, at most Core's smallest control tolerance) is
// limited / battery_limit, limit_kind inverter_import or
// inverter_export. A zero response keeps its warning: a dead battery
// on a site that may not export also sees no export headroom. Only the
// battery's own report of 0 available explains it;
// - a trusted learned plateau the shortfall sits on is limited /
// learned_limit.
//
Expand Down Expand Up @@ -126,6 +135,14 @@ func (s *Server) explainBatteryShortfall(f *ControlFeedback, data json.RawMessag
f.LimitW, f.LimitSource, f.LimitKind = watts(*limit), "device", "battery_reported"
return
}
// The inverter takes no more from the grid, or gives no more to it, so
// the battery can get or give no more through it. That explains less
// power, never none.
if room, kind := s.inverterRoom(f.Driver, charge); f.Reason == "power_below_target" && room != nil && *room <= telemetry.ControlToleranceW(0) {
f.State, f.Reason, f.Severity = "limited", "battery_limit", "info"
f.LimitW, f.LimitSource, f.LimitKind = watts(*room), "device", kind
return
}
if f.shortfall == nil {
return
}
Expand Down Expand Up @@ -160,6 +177,23 @@ func (s *Server) explainBatteryShortfall(f *ControlFeedback, data json.RawMessag
}
}

// inverterRoom is how much more the battery's own inverter reports it will
// take from the grid while charging, or give to it while discharging, from
// the inverter stream of the battery reading's poll. Nil when the driver
// sends no such headroom, its inverter read failed, or the driver is stale,
// offline or faulted.
func (s *Server) inverterRoom(driver string, charge bool) (*float64, string) {
inv, ok := s.deps.Tel.LiveBatteryInverter(driver)
if !ok {
return nil, ""
}
kind := "inverter_export"
if charge {
kind = "inverter_import"
}
return inv.Headroom(charge), kind
}

func (s *Server) learnedLimit(driver string, sample battery.ShortfallSample) (battery.Plateau, bool) {
if s.deps.Models == nil || s.deps.ModelsMu == nil {
return battery.Plateau{}, false
Expand Down
17 changes: 16 additions & 1 deletion go/internal/api/api_control_capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type sungrowTrace struct {
// frozenMeterW, when set, is the one grid value a driver keeps resending
// from its cache.
frozenMeterW *float64
// inverter, when set, gives the inverter stream emit of this poll, or
// "" when the inverter read failed.
inverter func() string
// polls numbers the driver's polls, as the driver host does.
polls uint64
}

func newSungrowTrace() *sungrowTrace {
Expand All @@ -64,7 +69,17 @@ func (s *sungrowTrace) poll() {
}
s.tel.Update("sungrow", telemetry.DerMeter, grid, nil, []byte(`{"power_origin":"external_meter"}`))
soc := 0.5
s.tel.Update("sungrow", telemetry.DerBattery, w, &soc, []byte(fmt.Sprintf(`{"setpoint_w":%g,"a":%.1f,"v":%.1f%s}`, s.cmdW, a, v, extra)))
s.polls++
s.tel.UpdateFromPoll("sungrow", telemetry.DerBattery, w, &soc, []byte(fmt.Sprintf(`{"setpoint_w":%g,"a":%.1f,"v":%.1f%s}`, s.cmdW, a, v, extra)), s.polls)
if s.inverter != nil {
if data := s.inverter(); data != "" {
r, err := telemetry.ParseInverterReading([]byte(data))
if err != nil {
panic(err)
}
s.tel.UpdateInverter("sungrow", r, s.polls)
}
}
s.tel.RecordDriverSuccess("sungrow")
}

Expand Down
3 changes: 2 additions & 1 deletion go/internal/api/api_control_feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ type ControlFeedback struct {
// the limit in W and, under a grid limit, the battery's room, both
// positive in the order's direction; where it comes from ("device" or
// "learned"), what holds it ("grid_import", "grid_export",
// "battery_current", "battery_power" or "battery_reported"), how many
// "battery_current", "battery_power", "battery_reported",
// "inverter_import" or "inverter_export"), how many
// runs showed it, since when, and the learned limit it replaced.
LimitW *float64 `json:"limit_w,omitempty"`
LimitRoomW *float64 `json:"limit_room_w,omitempty"`
Expand Down
Loading
Loading