Repository navigation
feat(autolearn): check energy suggestions by replaying recorded minutes - #295
Merged
Merged
Conversation
Adds the learned_value condition type to the rules schema and the Python engine. It compares a learned number with a threshold, given as a number or a learned reference, with hysteresis like balance_threshold. A missing or stale value falls back to the configured fallback. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The compared learned key, its fallback and max_age_s are read under learned, a threshold reference is read like the other learned fields. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add learned_value as a condition type in the automations editor. The condition reads as "PV reserve above 1500 W" (German: "PV-Reserve über 1500 W") and gets a learned chip with its origin. The threshold offers learned values in the unit of the learned key, or of its reference. Catalogs in German and English gain the new labels. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add the editor block for learned_value: learned value picker, comparison, threshold (fixed or learned reference), hysteresis, fallback, max age and hold. The condition defaults to a half hour hold, like learned_state, so a rule with a publish action passes the hold check. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replay vectors drive the real Engine and ScenarioEngine with a fixed clock (Europe/Berlin) and check fired steps and phases. Covers balance thresholds with hold, hysteresis, cooldown, repeat, stale balance, time windows across midnight and by start day, sun window edges, learned values with fallback and reference thresholds, and scenarios with when/until, min_run_s, max_duration_s, cooldown_s and hold. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add the replay core that runs rules and scenarios tick by tick, with the same state machines as the automation service: hold, hysteresis, cooldown, repeat, stale balance, time and sun windows, learned values and scenario phases. A target device closes the loop: its simulated state adds or takes load from the balance of the next tick. The Go test runs the shared replay_vectors.json table. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Limits gets ThresholdSteps (eco 20, balanced 40, full 80) and ReplayJointHold (true only on full). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ReplayDays takes complete days from the minute record when it has them, and stretches the quarter hours of the day files otherwise. The noise of a stretched day is seeded by its date and centred per quarter hour, so the 15 minutes keep the quarter mean. RealState reads the switch state from events and the on minutes. ReplayLastYear spreads the hourly statistics of the same weeks one year back. MinuteNoise gives the 95th percentile of the deviation from a 5 minute median near the threshold. Input gets the Minutes reader. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nt keys Reject custom and unknown balance fields as not replayable instead of reading them as absent. Stop applyDelta from creating balance keys with a zero amount, so a condition on a missing key cannot become true. The start peak now covers the first two minutes after switching on (ticks at one and two minutes). Tests load Europe/Berlin from embedded tzdata, fail on a missing tick, and cover the renamed closed-loop case. Remove the unused Light field and the unused scenario hasSince field. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…orrow minute shape The engine gets SetMinutes and fills Input.Minutes each round, and the dashboard wires the minute store into it. Stretched quarter hours take their intra-quarter shape from the minute days with the closest quarter mean. The seeded noise trace only applies when no minute day exists for the key. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add EvaluateReplay, which replays the real situation and the proposed rule over the same minutes, and a ReplayVerdict on the candidate. The gate drops a suggestion that draws more grid import than the export it uses, and caps a stretched replay at estimate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Two new assistant templates: shift_start builds two rules (start on surplus against the learned cycle energy, and a latest start once a day), after_battery_full builds a scenario that runs after the battery is full. The surplus templates get a source step, export or PV reserve, which swaps the start condition for a learned_value on site/pv_reserve_w. A template may now return kind rules with several entries. The assistant adds them together and one undo removes them all. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The assistant maps a surplus suggestion onto surplus_switch and surplus_wallbox: the start power rounded to 100 W, the source export or reserve, and for surplus_switch a fixed runtime in minutes from the suggested run time. An entry that is not a switch is resolved by its device id, so a suggestion that only names the device still preselects the switch entity. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The assistant maps a shift suggestion onto shift_start: the device, the start power rounded to 100 W and the latest start as a five minute window. The device id takes precedence over the entity, because the detector's entity is not always the switch. The minimum run time has no step in shift_start and is ignored. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The battery:full finding offers up to two switchable loads whose power fits the export after full. Each offer is replayed with the after_battery_full scenario. A replay that adds more grid energy than the export it saves drops the offer. Minimum run times come from a role table in minrun.go, heaters have no role and take 300 s. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The assistant maps a battery full suggestion onto after_battery_full: the device by its device id before the entity, and the run time in seconds to the nearest choice of the minimum run time step (none, short, standard, long). Invalid values drop the suggestion. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tuning The engine gets SetSteps and passes the step reader into Input.Steps. The dashboard wires the step log into it. The regulator spec reads gain, max_change_w and the base source. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The regulator detector reads the steps of every enabled scenario with a regulator. It finds the dead time by correlation, the slope K per PV band, and rates gain, deadband and change limit against the target. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The checker reads the same input as the engine through SetReplaySource, and ObservedFindingsWithPV takes it. Nothing reads it yet. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e checks The frequent check takes its hysteresis from twice the minute noise plus the load step, rounded up to 50 W, and proposes the cooldown from the mean gap of the burst. Its evidence shows the triggers that stay with that hysteresis. The overridden check gets the signal feature, the value of the rule's condition at the switch. The feedback check takes its noise from the minutes once three days have minutes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ible The checker keeps the replay input for ten minutes and builds it only when an enabled rule exists. Regulator findings of scenarios stay listed, since their IDs are current targets too. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A regulator finding names its scenario by id. applyFix writes the ops into the scenario draft when no rule has that id, and opens the scenario in its own editor. OpsApplied reads the regulator fields gain, deadband_w and max_change_w of a scenario, so a saved regulator fix is no longer shown as open. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A second demo scenario, nulleinspeisung_last, uses the last value as its base and gain 0,8. Its steps follow the output with K = 1 and dead time 1 (net = min(PV, previous output) - load, with a drifting load), so the regulator rating suggests a gain of about 0,2 (regulator.quality). The surplus window and the load shift are not seeded, the demo has too little November surplus for them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The demo scenario nulleinspeisung_last drove the same output topic as the live scenario nulleinspeisung. The regulator rating skips disabled scenarios, so the scenario stays enabled and gets its own demo-only topic max_power_limit_last_w, which no other fixture uses. A test checks that the demo regulator scenarios share no output topic. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Document the learned_value condition, the shift_start and after_battery_full templates, the PV reserve source of the surplus templates and the energy suggestions checked by replay. Update the energy group help text in both catalogs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… bar Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The regulator steps of the demo read the load of the day, so new demo devices would change them. The steps now use a fixed base load with quarter-hour jumps and a slow drift, independent of the devices. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A dryer that runs at midday on solar power and has no surplus rule gets a surplus window. Demo grid export is derived from PV minus load, and the demo PV peak rises to 6500 W so the midday surplus reaches the window. Existing findings keep their IDs. The threshold ratings of the PV rule and the washer rule are new findings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The demo dishwasher runs for an hour from the grid in the evening, with starts spread over three hours, so the robust spread of its start times passes the shift detector. Its runs fit the midday surplus of the demo. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The shift start template builds one scenario instead of two rules. It starts the device only in the window up to the latest time, on surplus against the learned cycle energy. Its end never switches the device off, the device finishes the cycle itself. A grid import ends the scenario, max_duration_s bounds it, and cooldown_s keeps it from starting again on the same day. The second rule for the latest start is dropped, so the device runs only while there is surplus in the window. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…he assistant Regression tests with the real demo suggestions of the dishwasher. The shift suggestion (device, on_w 500, latest 20:45, min_run_s 3580) and the surplus suggestion (device, on_w 700, min_run_s 3600, source export) both open the assistant on the dishwasher switch with their values, and the shift suggestion creates its scenario. No builder returned null. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The shift detector stabilises its latest start as a minute of the day. Only the key time was shown as HH:MM, so the summary read 1245 Uhr and the prefill latest became the number 1245. The assistant cannot read a number as a start time and opened without the suggestion. latest is now shown as a clock too. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A regulator finding is bound to its scenario by ID and carries a fix. learnNotices skipped every finding with RuleIDs or Apply, because the automations page marks rules with them. A scenario has no such mark, so the regulator finding was shown nowhere. It is listed now. Other rule bound findings are skipped as before. Learned notices carry their facts and show them with the labels of the suggestion band. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n in the frequent evidence A frequent finding with a replay keeps the span of its Ist triggers as the Soll span. The Soll lane then shows the burst again, not the triggers that are left with the hysteresis. The replayed Soll stands alone now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The events shape drew only the Soll spans. The replayed triggers of a frequent finding, the Soll with the hysteresis, were not drawn at all, so the Soll lane stayed empty next to the Ist triggers. The replayed triggers are drawn as bars in the Soll lane now, like the Ist triggers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
After a start the step ring is empty, but Steps read the files only up to the ring cutoff. With a ring of 7 days (balanced) the last 7 days of the 14 day regulator window were missing until 7 days of uptime, so the regulator quality finding did not show. Steps now reads the files up to the earliest step in RAM, or up to now when RAM is empty. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The finding mark and popover of a rule move into one template that scenario cards use as well. A regulator finding names its scenario id, so the card shows it with the same mark and the fix writes the scenario draft. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The shared finding mark still called toggleFinding with rule.id, so a click on a scenario mark threw a ReferenceError. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…evidence Evidence entrance runs once on first insert (AutomationEvidence.mount sets is-enter). Ist comes first, Soll follows 60 ms later, scale bars stagger by 40 ms. Only transform, opacity and clip-path, reduced motion falls back to a plain fade. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…trance The entrance keyframes ended on opacity 1, so the soft target bar flashed bright until the animation class was removed and then dropped to .35. The keyframes now only set the start value. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Exemption granted by Developer-Simon with 👍. No tour is required for these highlights:
|
4 tasks done
Developer-Simon
added a commit
that referenced
this pull request
Nov 23, 2026
Home Assistant now serves as a source of minute values for the learning functions. The replay PR (#295) is merged, this PR is rebased on prerelease. Source: when the companion is paired, the node asks Home Assistant for minute values (1m from the raw states, 5m from the short term statistics) through the existing history exchange. A new server peer `learnrec` keeps the answers in memory only, youngest days first, within half of the minute budget of the learning level. The companion itself is unchanged. Recording mode: `learning_minutes_mode` has a new value `pause_with_companion`. The own recording pauses while the companion offered 1m coverage in the last 10 minutes, and resumes within a minute when it stops. `auto` resolves to it only with a paired companion and no extra drive. An explicit "Always" is never changed. The card Learning > Recording shows the three modes, greys out the middle one without a companion with an action to the Users page, and adds the switch "Reconcile with Home Assistant" (on by default, only with a companion). Reconcile: before the heavy nightly run the node fetches the last 14 days that its own recording does not cover without a gap and waits up to 90 seconds for the answers. Reading prefers the own minute, then 1m from Home Assistant, then 5m. A day with more than 20 percent of 5m minutes does not count as minute exact. The values are never written to a drive and are dropped after the run. Known limits: only `b:pv` and `b:battery_soc` come from Home Assistant as balance fields, grid, load and battery need their signs and units checked first. Pausing together with the location drive leaves gaps in the drive files, a follow-up should only allow it with the location memory. With the mode "Off" the reconcile is still planned in the backend, only the card hides its switch. The demo companion offers no minute coverage for learning series, so the pause is covered by unit tests only. Highlights: - Learning functions can take minute values from Home Assistant Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Squash-merge commit message
Highlight translations
Tour
noneSummary
Energy suggestions for automations are now checked by replaying the recorded minute values before they are shown. The learning page can suggest switching loads into the typical surplus window, moving a cycle from grid into surplus, rating surplus thresholds and offering loads after the battery is full. A zero feed-in regulator is tuned from its own recorded steps, and the result shows up as findings on scenario cards and in the Monitoring tab.
Checks
scripts/dev/check_tracked_secrets.shis clean.