Repository navigation
feat(web): multi-array PV cold-start in Settings → Weather - #91
Conversation
Lets advanced operators enter panel geometry (kWp + tilt + azimuth) per array in the Settings → Weather tab. Used by forecast_solar to build a site-calibrated prediction that beats the single-plane approximation on multi-roof installs. Config: Weather.PVArrays []PVArray alongside the legacy PVTiltDeg/PVAzimuthDeg/PVRatedW fields. When PVArrays is non-empty the forecast_solar provider uses it directly (multi-plane URL /estimate/lat/lon/tilt1/az1/kwp1/tilt2/az2/kwp2/...), otherwise it synthesises a single array from the legacy fields for backwards compat with existing deploys. ForecastSolarProvider.Arrays []Array replaces the flat TiltDeg/AzimuthDeg/KWp triple; NewForecastSolar keeps the single- array constructor signature, NewForecastSolarMulti takes a slice. Settings UI: new "PV arrays" fieldset under Weather. Rows can be added / removed inline; each row has an optional label plus the three geometry fields. Empty list is fine — stays the default — and documented as "model will learn from telemetry". Multi-row is how homes with south + east roofs get accurate forecasts without waiting weeks for the RLS to converge. Also fixes a pre-existing test flake: TestSlotDirectiveAt was anchored to a hardcoded wall-clock date and failed once real time drifted past MaxPlanAge. Now uses time.Now() as the base. Tests: ForecastSolar URL construction for multi-plane, legacy single- plane path still works, config round-trip. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e1f696467
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "%s/estimate/%.4f/%.4f/%.1f/%.1f/%.2f?time=utc", | ||
| f.BaseURL, lat, lon, f.TiltDeg, f.AzimuthDeg, f.KWp, | ||
| ) | ||
| url := fmt.Sprintf("%s/estimate/%.4f/%.4f%s?time=utc", f.BaseURL, lat, lon, planes) |
There was a problem hiding this comment.
Pass forecast.solar API key for multi-plane requests
The new multi-array flow builds requests against the public .../estimate/... route, but forecast.solar documents multi-plane support under paid/API-key plans (their keyed route format is /<api_key>/estimate/... and plane limits are plan-gated). As implemented, Fetch never includes a key and Settings does not provide a forecast.solar key path, so additional arrays will not be honored in production even when users configure them, causing incorrect PV forecasts for multi-roof systems.
Useful? React with 👍 / 👎.
| renderPVArrays(); | ||
| var addBtn = document.getElementById("pv-array-add"); | ||
| if (addBtn) addBtn.addEventListener("click", function () { | ||
| currentConfig.weather.pv_arrays.push({ name: "", kwp: 0, tilt_deg: 35, azimuth_deg: 180 }); |
There was a problem hiding this comment.
Initialize new PV array rows with positive kWp
The UI adds new array rows with kwp: 0, but ForecastSolarProvider.Fetch now rejects any array where kWp <= 0 and returns an error for the whole request. If an operator clicks “Add array” and saves before editing kWp, weather refresh fails entirely and the planner loses fresh forecasts; this should be prevented by a valid default or pre-save validation.
Useful? React with 👍 / 👎.
PR #93 was too aggressive: it treated every non-positive override as a config error, including intentional one-sided constraints. But `max_charge_w: 0` is a legitimate "forbid charging, allow discharge" directive that mpc.Optimize's action grid (`-MaxDischargeW…+MaxChargeW`) already supports. The fix was overriding operator intent. Only the both-zero case (charge and discharge both 0) stays treated as a config error — that leaves the planner with no action space and produces the empty plan that looked like "disabled" in the UI. One-sided zero passes through untouched; negative values still fall back to default 0.5C with a warning. Also fixes a second time-sensitive flake in TestSlotDirectiveAtDischarge that was anchored to a hardcoded wall-clock date (same root cause as the one fixed in #91). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… on Add (#95) * fix(mpc): preserve one-sided zero battery limits (Codex follow-up) PR #93 was too aggressive: it treated every non-positive override as a config error, including intentional one-sided constraints. But `max_charge_w: 0` is a legitimate "forbid charging, allow discharge" directive that mpc.Optimize's action grid (`-MaxDischargeW…+MaxChargeW`) already supports. The fix was overriding operator intent. Only the both-zero case (charge and discharge both 0) stays treated as a config error — that leaves the planner with no action space and produces the empty plan that looked like "disabled" in the UI. One-sided zero passes through untouched; negative values still fall back to default 0.5C with a warning. Also fixes a second time-sensitive flake in TestSlotDirectiveAtDischarge that was anchored to a hardcoded wall-clock date (same root cause as the one fixed in #91). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(drivers): driver restart closes MQTT/Modbus + records health on Add Two foundational stability fixes prompted by tonight's incident on homelab-rpi where POST /api/drivers/ferroamp/restart left ferroamp in a silent `not_running: true` state until a full systemctl restart. Root cause 1: Registry.Remove tore down the runLoop + the Lua VM but never closed the driver's MQTT capability. A subsequent Add dialled a new paho client with the same clientID ("ftw-<driver>") while the old client was still connected. The broker resolved the collision by kicking the newer session on the next keepalive, and subscribe ACKs to the new client raced with the old client's disconnect — net effect was a driver whose subscriptions never activated, so extapi/data/eso messages never arrived, bat_soc stayed missing, and every tick just re-emitted the cached ehub reading. Root cause 2: driver health records were created lazily — the first RecordError (poll failure) or the first emit inserted a row in tel.AllHealth(). A freshly-added driver that was polling fine but hadn't received any MQTT data yet was therefore absent from AllHealth, and /api/status rendered it as `not_running: true, status: offline`. Same appearance as a crashed driver — operator couldn't tell them apart. Fix 1: add Close() error to the MQTTCap and ModbusCap interfaces; runLoop now calls Close() on both caps during stop-path cleanup, right after DefaultMode and Cleanup. mqtt/Capability.Close promoted from () to () error to match. Fix 2: Registry.Add eagerly calls tel.DriverHealthMut() so the record exists before runLoop runs the first poll. runLoop also now calls RecordSuccess() on every successful (non-error) poll — previously only errors and emits bumped the tick count. Tests (new registry_restart_test.go): - TestRemoveClosesMQTTCap — Close call count = 1 after Remove. - TestRemoveClosesModbusCap — same for Modbus. - TestRestartClosesOldMQTTBeforeDialingNew — three restart cycles each produce a fresh MQTT factory call; no cap leak. - TestAddCreatesHealthRecordImmediately — health visible from the instant Add returns, before runLoop has ticked. - TestRunLoopRecordsSuccessEvenWithoutEmits — TickCount > 0 after 350ms of 50ms polls even though the driver emits nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
PR #93 was too aggressive: it treated every non-positive override as a config error, including intentional one-sided constraints. But `max_charge_w: 0` is a legitimate "forbid charging, allow discharge" directive that mpc.Optimize's action grid (`-MaxDischargeW…+MaxChargeW`) already supports. The fix was overriding operator intent. Only the both-zero case (charge and discharge both 0) stays treated as a config error — that leaves the planner with no action space and produces the empty plan that looked like "disabled" in the UI. One-sided zero passes through untouched; negative values still fall back to default 0.5C with a warning. Also fixes a second time-sensitive flake in TestSlotDirectiveAtDischarge that was anchored to a hardcoded wall-clock date (same root cause as the one fixed in #91). Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Advanced operators can now enter panel geometry (kWp + tilt + azimuth) per array in the Settings UI. forecast_solar uses it to produce a site-calibrated prediction — handles multi-roof installs (south + east) without waiting weeks for the RLS to learn orientation.
Data model
```yaml
weather:
provider: forecast_solar
pv_arrays:
- name: south-roof
kwp: 6.0
tilt_deg: 35
azimuth_deg: 180
- name: east-roof
kwp: 4.0
tilt_deg: 30
azimuth_deg: 90
```
Empty `pv_arrays` + legacy `pv_tilt_deg` / `pv_azimuth_deg` fields still work — synthesised into a single array on startup.
UI
Settings → Weather now has a "PV arrays" fieldset below the provider selector. Rows can be added / removed inline. Empty list is fine and documented as "model will learn from telemetry" — matches the principle we discussed: cold-start is optional, not required.
Not addressed
provider: forecast_solaronce you want to test the multi-plane forecast.Tests
🤖 Generated with Claude Code