Repository navigation
fix(mpc): price the clock hour in progress for planners that announce demand_elapsed_hours - #1966
Conversation
… demand_elapsed_hours With 15-minute prices Core replans at :15, :30 and :45, and bindDemandCharges sent only the tariff hours that start at or after slot 0. The hour already running was left out of the peak-power tariff the planner sees, so a plan could set a new monthly peak in it, and today's completed peak counted twice in the top-N mean. Core now sends the hour in progress with the import measured so far (the site meter's hourly counter, else the history; uncovered time counts at no less than slot 0's forecast import) and puts today's completed peak in today's group. Only a planner whose handshake announces demand_elapsed_hours gets this shape; any other planner, including the bundled one, gets exactly the request it got before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a675fe157
ℹ️ 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".
| covered := max(0, h.lastAt.Sub(h.start)-h.unknown) | ||
| return mpc.HourImport{Start: h.start, ImportedWh: h.importedWh, Covered: covered} |
There was a problem hiding this comment.
Keep measured hour import independent of ceiling resets
When an owner enables or changes the import ceiling mid-hour, stepHourImportLimits resets h.importedWh and marks all preceding time unknown. This getter therefore returns only the import since that setting change, not the site's measured import for the hour. For a planner advertising demand_elapsed_hours, runningHourImportWh then prefers this truncated counter over available history and reconstructs the missing period using the subsequent mean or forecast. If import was higher before the change, the request understates the running hour's consumption and can schedule charging that creates an avoidable demand peak. Preserve a separate full-hour measured counter, or fall back to history when the ceiling counter has been reset.
Useful? React with 👍 / 👎.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Bundle the worker from srcfl/energyplan 847936a (0.7.0, tag v0.7.0-beta.1) for linux-arm64 and linux-amd64. The macOS worker is no longer bundled; #1977 lets verify.py check such a bundle and skip execution on a Mac. The worker lists demand_elapsed_hours, so Core (#1966) sends it the demand hour in progress and the day's completed peak in that day's group, and the native demand test now requires the feature. The contract describes the feature and the demand-charge fields, each call's time limit since #1968, the batteries' total recovery rule and optional reply diagnostics, and it stays identical to Energyplan's copy. The worker version pins and the README follow. Licenses and forecast schemas are unchanged; the notices list two more microlp modifications. Protocol v1 is unchanged. Signed-off-by: Fredrik Ahlgren <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
With 15-minute prices Core replans at :15, :30 and :45 (and reactively, for
example when a car plugs in at 17:20).
bindDemandChargessends only thetariff hours that start at or after slot 0, so the clock hour already running
is left out of the peak-power tariff the planner sees. The plan can then set a
new monthly peak in that hour. Today's completed peak also goes into
already_kwwhile today's planned hours form today's group, so today countstwice in the top-N mean.
Change
bindDemandChargessends the hour in progress even when it began beforeslot 0, with the import it has had up to execution start. That import comes
from the site meter's live hourly counter (
control.MeasuredHourImport, thecounter the import ceiling uses, restored at boot by
SeedHourImport) whenit measures that hour, else from the import history. Time neither covers
counts at the larger of the covered mean and slot 0's forecast import, never
at zero.
day's group (its own start, end, kWh and weight) instead of a value in
already_kw, so each local day is one sample. Hours go out in ascendingstart order.
prepareEnergyplanRequestsends thenew shape only to a planner whose handshake announces
demand_elapsed_hours. Any other planner gets exactly the request it gotbefore (no hour before slot 0, completed days in
already_kw, a charge leftempty dropped, months in their earlier order), and
time_limit_sfollowsthe charges it actually gets.
priceReserveChargingkeeps its skip onp.DemandCharges: the tariff existsfor either planner.
The bundled planner does not announce the feature yet, so Core's requests to
it are unchanged. The contract text for the feature lands with the pin bump.
Tests
TestBindDemandChargesSendsTheRunningHourBeforeTheFirstSlotreplacesTestBindDemandChargesSkipsUnalignedCurrentHour: at 10:17 with slot 0 at10:15 the 10:00 hour goes out with its import, for the new shape only.
TestBindDemandChargesPutsTodaysPeakInTodaysGroup: on a weekday at 19:20today's group is {completed peak, hour in progress} and
already_kwhas noentry for today; the old shape is checked against its JSON.
TestRunningHourImportCountsUncoveredTime: counter, history and the fill.TestLegacyDemandChargesKeepTheirOrderAtTheEndOfAMonth: at 23:20 on amonth's last day the new shape starts with the month whose last hour is in
progress; an old planner still gets the earlier JSON, the month with
planned hours first.
TestEnergyplanRequestNegotiatesElapsedDemandHours: old and new plannersget their JSON; a site whose only demand hour is the one in progress gives
an old planner no demand charge and the non-demand budget.
TestReservePricingKeepsAwayFromADemandTariffWithOnlyTheRunningHour.TestMeasuredHourImportCountsTheMeteredHour(control).TestNativeEnergyplanTakesElapsedDemandHours: throughNewEnergyplanOptimizer, with slot 0 at :15, the plan passesValidatePlan. It skips while the planner's handshake lacks the feature,as
TestNativeEnergyplanTakesHourlyImportCapsdoes; it asserts once thepin moves.
Overlap
This also changes
go/cmd/ftw/main.goandgo/internal/mpc/service.go, which open PR #1956 touches. The two branches merge without a conflict in those files.go vetis clean, andgo test -count=1 ./internal/mpc/... ./internal/control/... ./cmd/ftw/...passes on a8b696a.🤖 Generated with Claude Code