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
8 changes: 8 additions & 0 deletions changelog/highlights/294.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"de": {
"*": "Die Lernfunktionen können Minutenwerte aus Home Assistant übernehmen"
},
"en": {
"*": "Learning functions can take minute values from Home Assistant"
}
}
13 changes: 10 additions & 3 deletions dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## v0.11.22-pre.33 (2026-11-06)
## v0.11.22-pre.34 (2026-11-06)

### Features

Expand Down Expand Up @@ -33,6 +33,12 @@
- **monitoring:** A Monitoring tab with notices, acknowledgement and all learned values (#291) (7ae50a9)
- **autolearn:** The rule check finds feedback, competition for the surplus, a rising base load and battery problems (#292) (142387b)
- **autolearn:** The node records minute values and keeps every regulator step as a base for learning (#293) (19e65e7)
- **autolearn:** Automation suggestions for surplus and load shifts are checked against your data (#295) (6c255ad)
- **learnrec:** fetch minute values from Home Assistant through the companion (97e2665)
- **learnrec:** pause the own recording while Home Assistant delivers minutes (4086c45)
- **learnrec:** read own minutes first, then Home Assistant, and fetch gaps before the heavy run (44ee05d)
- **settings:** let Home Assistant fill the minute recording (3d7d231)
- **autolearn:** Learning functions can take minute values from Home Assistant (#294)
- **autolearn:** parse the learned_value condition (da541e8)
- **automations:** edit the learned_value condition (672ca29)
- **automations:** edit the learned_value fields in the rule card (ae0c8e1)
Expand Down Expand Up @@ -62,7 +68,6 @@
- **automations:** build the shift start as one scenario (4b75e8f)
- **automations:** show findings on scenario cards (054b01a)
- **automations:** ease the target curve and the scale bars into the evidence (0134794)
- **autolearn:** Automation suggestions for surplus and load shifts are checked against your data (#295)
- **learnrec:** resolve where the minute recording lives (972c4aa)
- **learnrec:** add the binary day format of the minute recording (f0e0eec)
- **learnrec:** keep minute values in RAM and append them to the chosen drive (64aff34)
Expand Down Expand Up @@ -329,6 +334,7 @@
- **storage:** offer sticks with several partitions as a group and format single partitions (#243) (c4e6d33)
- **storage:** wipe old file system signatures before formatting a stick (#245) (aeafa63)
- **storage:** set up, back up and replug the additional drive reliably (#247) (b668394)
- **backup:** A restore stays in place even when the battery state cannot be written (#288) (e5c5437)
- **autolearn:** harden the replay against unsupported fields and absent keys (f762aae)
- **automations:** prefill the surplus templates from a suggestion (d977098)
- **automations:** prefill the shift start template from a suggestion (d1b835a)
Expand All @@ -348,7 +354,6 @@
- **autolearn:** read the regulator steps from the files after a start (0edcbe0)
- **automations:** open the scenario finding with its own key (5116883)
- **automations:** keep the target bar at its own opacity after the entrance (2bb3b06)
- **backup:** A restore stays in place even when the battery state cannot be written (#288) (e5c5437)
- **autolearn:** write step files per scenario and day, drop deadband from figures (8f2a75a)
- **dashboard:** bound the step ring by the RAM days and log slow flushes (0046eee)
- **settings:** format the drive free space in GB (2c55808)
Expand Down Expand Up @@ -488,6 +493,8 @@

### Chores

- **dashboard:** bump the cache-bust marks for the Home Assistant source (8b3bb59)
- **dashboard:** refresh the cache-bust history after the rebase (33c7bcb)
- **dashboard:** bump the cache-bust marks for energy suggestions (5e08c00)
- **dashboard:** bump the cache-bust marks for the evidence animation (a185d8b)
- **dashboard:** bump the cache-bust marks for the minute recording (604eb49)
Expand Down
2 changes: 1 addition & 1 deletion dashboard/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.11.22-pre.33
v0.11.22-pre.34
8 changes: 4 additions & 4 deletions dashboard/cmd/dashboard/learn_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestPVKeepDaysFollowsTheSeasonSwitch(t *testing.T) {
}

func TestMinuteSnapshotWithoutDriveIsRAM(t *testing.T) {
snap := minuteSnapshotFor(settings.Default(), "", storage.Status{Mode: storage.ModeNone}, "/data", "/mnt/data", learnrec.Limits{})
snap := minuteSnapshotFor(settings.Default(), "", storage.Status{Mode: storage.ModeNone}, "/data", "/mnt/data", learnrec.Limits{}, false)
if snap.plan.Location != learnrec.LocRAM || !snap.plan.AutoLocation {
t.Fatalf("plan = %+v, want auto ram", snap.plan)
}
Expand All @@ -164,14 +164,14 @@ func TestMinuteSnapshotWithoutDriveIsRAM(t *testing.T) {

func TestMinuteSnapshotWithDriveFollowsStorageMode(t *testing.T) {
value := settings.Default()
up := minuteSnapshotFor(value, "uuid", storage.Status{Mode: storage.ModeDrive}, "/data", "/mnt/data", learnrec.Limits{})
up := minuteSnapshotFor(value, "uuid", storage.Status{Mode: storage.ModeDrive}, "/data", "/mnt/data", learnrec.Limits{}, false)
if up.plan.Location != learnrec.LocDrive || !up.driveUp {
t.Fatalf("plan = %+v driveUp = %v, want drive", up.plan, up.driveUp)
}
if up.dirs.Drive != "/mnt/data/runtime" || up.stepDir() != "/mnt/data/runtime" {
t.Fatalf("drive dir = %q, step dir = %q", up.dirs.Drive, up.stepDir())
}
down := minuteSnapshotFor(value, "uuid", storage.Status{Mode: storage.ModeFallbackSystem}, "/data", "/mnt/data", learnrec.Limits{})
down := minuteSnapshotFor(value, "uuid", storage.Status{Mode: storage.ModeFallbackSystem}, "/data", "/mnt/data", learnrec.Limits{}, false)
if down.driveUp || down.dirs.Drive != "" || down.stepDir() != "" {
t.Fatalf("fallback keeps drive out: driveUp = %v drive = %q step = %q", down.driveUp, down.dirs.Drive, down.stepDir())
}
Expand All @@ -180,7 +180,7 @@ func TestMinuteSnapshotWithDriveFollowsStorageMode(t *testing.T) {
func TestMinuteSnapshotSystemLocationUsesDataDir(t *testing.T) {
value := settings.Default()
value.LearningMinutesLocation = "system"
snap := minuteSnapshotFor(value, "uuid", storage.Status{Mode: storage.ModeDrive}, "/data", "/mnt/data", learnrec.Limits{})
snap := minuteSnapshotFor(value, "uuid", storage.Status{Mode: storage.ModeDrive}, "/data", "/mnt/data", learnrec.Limits{}, false)
if snap.plan.Location != learnrec.LocSystem || snap.stepDir() != "/data" {
t.Fatalf("location = %q step dir = %q, want system /data", snap.plan.Location, snap.stepDir())
}
Expand Down
82 changes: 82 additions & 0 deletions dashboard/cmd/dashboard/learn_ha_prepare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"context"
"sort"
"time"
)

// haPrefetchDays ist die Zahl der Tage vor heute, die der Vorlauf prueft.
const haPrefetchDays = 14

// haPrefetchTimeout ist die Frist des Vorlaufs. Antworten danach zaehlen nicht.
const haPrefetchTimeout = 90 * time.Second

// haFetcher ist der Teil des Abgleichs, den der Vorlauf braucht.
type haFetcher interface {
Prefetch(keys []string, days []string, deadline time.Time)
WaitIdle(ctx context.Context) bool
Drop()
}

// ownMinutes ist der Teil des eigenen Minutenspeichers, den der Vorlauf liest.
type ownMinutes interface {
Keys(from, to time.Time) []string
Coverage(from, to time.Time) int
}

// haPreparer holt vor dem schweren Lauf die Minuten nach, die der eigene
// Speicher in den letzten Tagen nicht lueckenlos hat. Nach dem Lauf verwirft
// er den Zwischenspeicher.
type haPreparer struct {
own ownMinutes
ha haFetcher
// active meldet, ob der Abgleich laeuft und der Companion gekoppelt ist.
active func() bool
loc *time.Location
}

// Prepare plant die Nachfragen fuer die Tage ohne lueckenlose Minuten und
// wartet, bis alle Antworten da sind oder die Frist vorbei ist.
func (p *haPreparer) Prepare(now time.Time) {
if p.active == nil || !p.active() {
return
}
loc := p.loc
if loc == nil {
loc = time.Local
}
local := now.In(loc)
today := time.Date(local.Year(), local.Month(), local.Day(), 0, 0, 0, 0, loc)
from := today.AddDate(0, 0, -haPrefetchDays)

keySet := map[string]bool{"b:pv": true, "b:battery_soc": true}
for _, key := range p.own.Keys(from, today) {
keySet[key] = true
}
var days []string
for k := haPrefetchDays; k >= 1; k-- {
start := today.AddDate(0, 0, -k)
if p.own.Coverage(start, start.AddDate(0, 0, 1)) != 1 {
days = append(days, start.Format("2006-01-02"))
}
}
if len(days) == 0 {
return
}
keys := make([]string, 0, len(keySet))
for key := range keySet {
keys = append(keys, key)
}
sort.Strings(keys)

p.ha.Prefetch(keys, days, now.Add(haPrefetchTimeout))
ctx, cancel := context.WithTimeout(context.Background(), haPrefetchTimeout)
defer cancel()
p.ha.WaitIdle(ctx)
}

// Release verwirft den Zwischenspeicher, auch wenn der Lauf fehlschlug.
func (p *haPreparer) Release() {
p.ha.Drop()
}
103 changes: 103 additions & 0 deletions dashboard/cmd/dashboard/learn_ha_prepare_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package main

import (
"context"
"testing"
"time"
)

type fakeOwn struct {
keys []string
covered map[string]bool
}

func (f *fakeOwn) Keys(from, to time.Time) []string { return f.keys }

func (f *fakeOwn) Coverage(from, to time.Time) int {
if f.covered[from.Format("2006-01-02")] {
return 1
}
return 0
}

type fakeHA struct {
prefetches int
keys []string
days []string
deadline time.Time
drops int
}

func (f *fakeHA) Prefetch(keys []string, days []string, deadline time.Time) {
f.prefetches++
f.keys, f.days, f.deadline = keys, days, deadline
}

func (f *fakeHA) WaitIdle(ctx context.Context) bool { return true }

func (f *fakeHA) Drop() { f.drops++ }

func TestHAPreparerDoesNothingWhenReconcileIsOff(t *testing.T) {
ha := &fakeHA{}
p := &haPreparer{own: &fakeOwn{}, ha: ha, active: func() bool { return false }, loc: time.UTC}
p.Prepare(time.Date(2026, 11, 20, 3, 30, 0, 0, time.UTC))
if ha.prefetches != 0 {
t.Fatalf("Prefetch ohne Abgleich aufgerufen: %d", ha.prefetches)
}
p.Release()
if ha.drops != 1 {
t.Fatalf("Release muss den Zwischenspeicher leeren, Drop = %d", ha.drops)
}
}

func TestHAPreparerPrefetchesOnlyIncompleteDays(t *testing.T) {
now := time.Date(2026, 11, 20, 3, 30, 0, 0, time.UTC)
ha := &fakeHA{}
own := &fakeOwn{
keys: []string{"e:uid1"},
covered: map[string]bool{"2026-11-19": true},
}
p := &haPreparer{own: own, ha: ha, active: func() bool { return true }, loc: time.UTC}
p.Prepare(now)

if ha.prefetches != 1 {
t.Fatalf("Prefetch-Aufrufe = %d, want 1", ha.prefetches)
}
if len(ha.days) != 13 {
t.Fatalf("Tage = %d, want 13 (14 minus der lueckenlose 19.11.)", len(ha.days))
}
for _, d := range ha.days {
if d == "2026-11-19" {
t.Fatal("der lueckenlose Tag darf nicht nachgeholt werden")
}
}
if ha.days[0] != "2026-11-06" || ha.days[len(ha.days)-1] != "2026-11-18" {
t.Fatalf("Tage = %v, want 2026-11-06 bis 2026-11-18 ohne 2026-11-19", ha.days)
}
want := map[string]bool{"b:pv": true, "b:battery_soc": true, "e:uid1": true}
if len(ha.keys) != len(want) {
t.Fatalf("Schluessel = %v", ha.keys)
}
for _, k := range ha.keys {
if !want[k] {
t.Fatalf("unerwarteter Schluessel %q in %v", k, ha.keys)
}
}
if !ha.deadline.Equal(now.Add(90 * time.Second)) {
t.Fatalf("Frist = %v, want jetzt+90 s", ha.deadline)
}
}

func TestHAPreparerNoPrefetchWhenAllDaysComplete(t *testing.T) {
now := time.Date(2026, 11, 20, 3, 30, 0, 0, time.UTC)
covered := map[string]bool{}
for k := 1; k <= 14; k++ {
covered[now.AddDate(0, 0, -k).Format("2006-01-02")] = true
}
ha := &fakeHA{}
p := &haPreparer{own: &fakeOwn{covered: covered}, ha: ha, active: func() bool { return true }, loc: time.UTC}
p.Prepare(now)
if ha.prefetches != 0 {
t.Fatalf("lueckenlose Tage duerfen keine Nachfrage ausloesen: %d", ha.prefetches)
}
}
41 changes: 28 additions & 13 deletions dashboard/cmd/dashboard/learn_minutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ type minuteSnapshot struct {
dirs learnrec.MinuteDirs
driveUp bool
driveConfigured bool
companionPaired bool
limits learnrec.Limits
}

// minuteSnapshotFor baut den Schnappschuss. Das Laufwerksverzeichnis ist nur
// gesetzt, wenn der Speicher im Modus Laufwerk steht. Die Aufzeichnung legt
// learnrec/minutes selbst unter dem Basisverzeichnis an.
func minuteSnapshotFor(value settings.Settings, driveUUID string, status storage.Status, dataDir, mount string, limits learnrec.Limits) *minuteSnapshot {
func minuteSnapshotFor(value settings.Settings, driveUUID string, status storage.Status, dataDir, mount string, limits learnrec.Limits, companionPaired bool) *minuteSnapshot {
plan := learnrec.ResolveMinutes(learnrec.MinuteSettings{
Mode: value.LearningMinutesMode,
Location: value.LearningMinutesLocation,
Days: value.LearningMinutesDays,
}, driveUUID != "")
snap := &minuteSnapshot{plan: plan, dirs: learnrec.MinuteDirs{System: dataDir}, driveConfigured: driveUUID != "", limits: limits}
Mode: value.LearningMinutesMode,
Location: value.LearningMinutesLocation,
Days: value.LearningMinutesDays,
ReconcileOff: value.LearningHAReconcileDisabled,
}, driveUUID != "", companionPaired)
snap := &minuteSnapshot{plan: plan, dirs: learnrec.MinuteDirs{System: dataDir}, driveConfigured: driveUUID != "", companionPaired: companionPaired, limits: limits}
if status.Mode == storage.ModeDrive {
snap.driveUp = true
snap.dirs.Drive = storage.DriveRuntimeDir(storage.Paths{Mount: mount})
Expand All @@ -60,11 +62,14 @@ func (s *minuteSnapshot) stepDir() string {

// minuteSources sind die Quellen, aus denen Refresh den Schnappschuss baut.
type minuteSources struct {
settings func() (settings.Settings, error)
status func() storage.Status
limits func() learnrec.Limits
dataDir string
mount string
settings func() (settings.Settings, error)
status func() storage.Status
limits func() learnrec.Limits
companionPaired func() bool
// ha ist der Abgleich mit Home Assistant. Nil heisst: keine Pause.
ha *learnrec.HASync
dataDir string
mount string
}

// minuteRecording buendelt den MinuteStore und den StepLog. Beide lesen ihre
Expand Down Expand Up @@ -106,10 +111,20 @@ func (r *minuteRecording) Refresh() {
if cfg, err := storage.LoadConfig(r.src.dataDir); err == nil {
driveUUID = cfg.UUID
}
r.snap.Store(minuteSnapshotFor(value, driveUUID, r.src.status(), r.src.dataDir, r.src.mount, r.src.limits()))
paired := r.src.companionPaired != nil && r.src.companionPaired()
r.snap.Store(minuteSnapshotFor(value, driveUUID, r.src.status(), r.src.dataDir, r.src.mount, r.src.limits(), paired))
}

func (r *minuteRecording) plan() learnrec.MinutePlan { return r.snap.Load().plan }
// plan liefert den Plan des Schnappschusses. Paused gilt nur im Modus
// pause_with_companion und nur, solange Home Assistant frische Minuten liefert.
// Faellt die Lieferung weg, laeuft die eigene Aufzeichnung in der naechsten Minute weiter.
func (r *minuteRecording) plan() learnrec.MinutePlan {
plan := r.snap.Load().plan
if plan.PauseMode && r.src.ha != nil {
plan.Paused = r.src.ha.Fresh1m(time.Now())
}
return plan
}
func (r *minuteRecording) dirs() learnrec.MinuteDirs { return r.snap.Load().dirs }
func (r *minuteRecording) driveUp() bool { return r.snap.Load().driveUp }

Expand Down
Loading
Loading