Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
972c4aa
feat(learnrec): resolve where the minute recording lives
Developer-Simon Nov 22, 2026
f0e0eec
feat(learnrec): add the binary day format of the minute recording
Developer-Simon Nov 22, 2026
64aff34
feat(learnrec): keep minute values in RAM and append them to the chos…
Developer-Simon Nov 22, 2026
cfb599f
feat(learnrec): read ranges from the minute recording and replay them…
Developer-Simon Nov 22, 2026
9ca1843
feat(learnrec): let chain suggestions catch up from the recording
Developer-Simon Nov 22, 2026
b82ff94
feat(automation): publish every regulator step of a scenario
Developer-Simon Nov 22, 2026
cb5a507
feat(autolearn): keep the regulator steps of each scenario
Developer-Simon Nov 22, 2026
8f2a75a
fix(autolearn): write step files per scenario and day, drop deadband …
Developer-Simon Nov 22, 2026
885314a
feat(dashboard): wire the minute recording and step log into the main…
Developer-Simon Nov 22, 2026
0046eee
fix(dashboard): bound the step ring by the RAM days and log slow flushes
Developer-Simon Nov 22, 2026
744091f
feat(dashboard): report the minute recording in learning status
Developer-Simon Nov 22, 2026
81d9b09
feat(settings): add the texts for the minute recording card
Developer-Simon Nov 22, 2026
d6e14c7
feat(settings): choose where minute values are kept
Developer-Simon Nov 22, 2026
2c55808
fix(settings): format the drive free space in GB
Developer-Simon Nov 22, 2026
956b559
feat(autolearn): seed minute values and regulator steps in the demo
Developer-Simon Nov 22, 2026
4c6823b
chore(demo): keep the minute recording on the system drive
Developer-Simon Nov 22, 2026
e3c7711
docs(automations): describe the minute recording
Developer-Simon Nov 22, 2026
604eb49
chore(dashboard): bump the cache-bust marks for the minute recording
Developer-Simon Nov 22, 2026
84aa771
chore(dashboard): bump the cache-bust mark of the settings page
Developer-Simon Nov 22, 2026
2135428
chore(release): bump component versions
Nov 22, 2026
eca18ee
docs(changelog): update changelogs
Nov 22, 2026
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/293.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"de": {
"*": "Die Node zeichnet Minutenwerte auf und behält jeden Reglerschritt als Grundlage zum Lernen"
},
"en": {
"*": "The node records minute values and keeps every regulator step as a base for learning"
}
}
24 changes: 20 additions & 4 deletions dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## v0.11.22-pre.31 (2026-11-06)
## v0.11.22-pre.32 (2026-11-06)

### Features

Expand Down Expand Up @@ -31,6 +31,19 @@
- **automations:** Learning knows the seasons, the sun and the outdoor temperature (#287) (8812dc2)
- **automations:** Learning knows device cycles, the PV reserve and the remaining surplus of the day (#289) (5d86b6b)
- **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)
- **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)
- **learnrec:** read ranges from the minute recording and replay them to one consumer (cfb599f)
- **learnrec:** let chain suggestions catch up from the recording (9ca1843)
- **autolearn:** keep the regulator steps of each scenario (cb5a507)
- **dashboard:** wire the minute recording and step log into the main program (885314a)
- **dashboard:** report the minute recording in learning status (744091f)
- **settings:** add the texts for the minute recording card (81d9b09)
- **settings:** choose where minute values are kept (d6e14c7)
- **autolearn:** seed minute values and regulator steps in the demo (956b559)
- **autolearn:** The node records minute values and keeps every regulator step as a base for learning (#293)
- **autolearn:** let a fix change several rules and estimate signal noise (80c444e)
- **autolearn:** flag rules whose own load flips their condition (67cbc32)
- **autolearn:** name feedback as the cause of flapping rules (f6ea384)
Expand All @@ -54,7 +67,6 @@
- **automations:** draw Ist and Soll curves in one chart (5f880ad)
- **monitoring:** open the suggestion from its notice (9eaa37c)
- **monitoring:** collect the suggestions under their own filter (add1bab)
- **autolearn:** The rule check finds feedback, competition for the surplus, a rising base load and battery problems (#292)
- **i18n:** add the view_monitoring texts (0385648)
- **auth:** add the view_monitoring right (44c40f9)
- **monitoring:** collect notices from energy, chains and learning (e85d98c)
Expand Down Expand Up @@ -287,10 +299,13 @@
- **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)
- **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)
- **backup:** A restore stays in place even when the battery state cannot be written (#288) (e5c5437)
- **autolearn:** drop findings whose fix is saved and show an early full battery in Monitoring (cb2d65b)
- **automations:** keep learned findings while a fix sits in the draft (715cbfd)
- **automations:** preselect the switch of night off and quiet off suggestions (e3a0952)
- **backup:** A restore stays in place even when the battery state cannot be written (#288) (e5c5437)
- **webui:** translate the time value of the monitoring model (d55ca28)
- **webui:** add labels and load error to the monitoring panel (79ad0f3)
- **energy:** keep monitoring jumps and refresh the summary line (9ad7b8a)
Expand Down Expand Up @@ -423,8 +438,9 @@

### Chores

- **dashboard:** bump the cache-bust marks for the minute recording (604eb49)
- **dashboard:** bump the cache-bust mark of the settings page (84aa771)
- **dashboard:** bump the cache-bust marks for energy findings (85a44b4)
- **dashboard:** bump the cache-bust mark of the settings page (a590474)
- **dashboard:** bump the cache-bust marks for the curve chart and suggestion notices (e4c86cb)
- **webui:** bump the lazy asset marks of the monitoring page (79de377)
- **dashboard:** bump the cache-bust marks for energy learning (8bd6f10)
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.31
v0.11.22-pre.32
68 changes: 68 additions & 0 deletions dashboard/cmd/dashboard/learn_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/Developer-Simon/energy-node-dashboard/internal/learnrec"
"github.com/Developer-Simon/energy-node-dashboard/internal/registry"
"github.com/Developer-Simon/energy-node-dashboard/internal/settings"
"github.com/Developer-Simon/energy-node-dashboard/internal/storage"
)

func TestEngineRunnerDropsTickWhenChannelIsFull(t *testing.T) {
Expand Down Expand Up @@ -146,3 +148,69 @@ func TestPVKeepDaysFollowsTheSeasonSwitch(t *testing.T) {
t.Fatalf("switch off without profile days = %d, want the default", got)
}
}

func TestMinuteSnapshotWithoutDriveIsRAM(t *testing.T) {
snap := minuteSnapshotFor(settings.Default(), "", storage.Status{Mode: storage.ModeNone}, "/data", "/mnt/data", learnrec.Limits{})
if snap.plan.Location != learnrec.LocRAM || !snap.plan.AutoLocation {
t.Fatalf("plan = %+v, want auto ram", snap.plan)
}
if snap.dirs.Drive != "" {
t.Fatalf("drive dir = %q without a drive", snap.dirs.Drive)
}
if dir := snap.stepDir(); dir != "" {
t.Fatalf("step dir = %q, want ram", dir)
}
}

func TestMinuteSnapshotWithDriveFollowsStorageMode(t *testing.T) {
value := settings.Default()
up := minuteSnapshotFor(value, "uuid", storage.Status{Mode: storage.ModeDrive}, "/data", "/mnt/data", learnrec.Limits{})
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{})
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())
}
}

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{})
if snap.plan.Location != learnrec.LocSystem || snap.stepDir() != "/data" {
t.Fatalf("location = %q step dir = %q, want system /data", snap.plan.Location, snap.stepDir())
}
}

func TestWatchHandlerRoutesStepsAndKeepsOtherTopics(t *testing.T) {
steps := autolearn.NewStepLog(func() int { return 3 }, func() string { return "" })
var others []string
handler := watchHandler(automationServiceID, steps, func(topic string, _ []byte) {
others = append(others, topic)
})
if got := stepTopic(automationServiceID); got != "outstation/automation/scenario/+/step" {
t.Fatalf("step topic = %q", got)
}
now := time.Now()
payload := []byte(fmt.Sprintf(`{"at":%d,"err":-5,"net":-5,"from":1200,"to":1200,"why":"unchanged"}`, now.Unix()))
handler("outstation/automation/scenario/heizung/step", payload)
if got := steps.Steps("heizung", now.Add(-time.Hour), now.Add(time.Hour)); len(got) != 1 {
t.Fatalf("steps routed to the log = %d, want 1", len(got))
}
handler("outstation/automation/status/online", []byte("online"))
handler("outstation/energy_node/scenario/heizung/step", payload)
handler("outstation/automation/scenario/heizung/extra/step", payload)
want := []string{"outstation/automation/status/online", "outstation/energy_node/scenario/heizung/step", "outstation/automation/scenario/heizung/extra/step"}
if len(others) != len(want) {
t.Fatalf("other topics = %v, want %v", others, want)
}
for i := range want {
if others[i] != want[i] {
t.Fatalf("other topics = %v, want %v", others, want)
}
}
}
162 changes: 162 additions & 0 deletions dashboard/cmd/dashboard/learn_minutes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package main

import (
"errors"
"log"
"strings"
"sync/atomic"
"time"

"github.com/Developer-Simon/energy-node-dashboard/internal/autolearn"
"github.com/Developer-Simon/energy-node-dashboard/internal/learnrec"
"github.com/Developer-Simon/energy-node-dashboard/internal/settings"
"github.com/Developer-Simon/energy-node-dashboard/internal/storage"
)

// automationServiceID ist der Dienst der Automationen. Seine Reglerschritte
// kommen auf outstation/automation/scenario/<id>/step.
const automationServiceID = "automation"

// minuteSnapshot ist, was die Minutenaufzeichnung aus Einstellungen, Laufwerk
// und Lernstufe braucht. Der Minutenweg liest ihn atomar, ohne Datei und ohne Lock.
type minuteSnapshot struct {
plan learnrec.MinutePlan
dirs learnrec.MinuteDirs
driveUp bool
driveConfigured 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 {
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}
if status.Mode == storage.ModeDrive {
snap.driveUp = true
snap.dirs.Drive = storage.DriveRuntimeDir(storage.Paths{Mount: mount})
}
return snap
}

// stepDir ist das Basisverzeichnis der Schrittdateien am Ort der Minuten. Leer
// heisst RAM, also am Laufwerk ohne Laufwerk.
func (s *minuteSnapshot) stepDir() string {
switch s.plan.Location {
case learnrec.LocDrive:
if s.driveUp {
return s.dirs.Drive
}
case learnrec.LocSystem:
return s.dirs.System
}
return ""
}

// 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
}

// minuteRecording buendelt den MinuteStore und den StepLog. Beide lesen ihre
// Einstellungen aus dem Schnappschuss, den Refresh im Zehn-Sekunden-Takt erneuert.
type minuteRecording struct {
store *learnrec.MinuteStore
steps *autolearn.StepLog
src minuteSources
snap atomic.Pointer[minuteSnapshot]
}

// newMinuteRecording legt die Aufzeichnung an und liest den ersten Schnappschuss.
func newMinuteRecording(src minuteSources) *minuteRecording {
r := &minuteRecording{src: src}
r.Refresh()
r.store = learnrec.NewMinuteStore(time.Local, r.plan, r.dirs, r.driveUp, r.limits, log.Printf)
r.steps = autolearn.NewStepLog(func() int { return r.snap.Load().plan.Days }, r.stepDir).WithRingDays(r.stepRingDays)
return r
}

// stepRingDays ist die Zahl der Tage im RAM-Ring der Schritte. Sie folgt dem
// RAM-Budget wie die Minuten im RAM: die Bytes eines vollen Tages sind die
// Kanaele mal 1440 Minuten mal 4 Byte je Wert. Der Ort aendert den Ring nicht.
func (r *minuteRecording) stepRingDays() int {
const bytesPerValue = 4
const minutesPerDay = 1440
keys := r.store.Usage().Keys
return learnrec.RAMDays(r.limits(), int64(keys)*minutesPerDay*bytesPerValue)
}

// Refresh liest Einstellungen, Laufwerk und Lernstufe und ersetzt den
// Schnappschuss. Ohne lesbare Einstellungen gelten die Standardwerte.
func (r *minuteRecording) Refresh() {
value, err := r.src.settings()
if err != nil {
value = settings.Default()
}
driveUUID := ""
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()))
}

func (r *minuteRecording) plan() learnrec.MinutePlan { return r.snap.Load().plan }
func (r *minuteRecording) dirs() learnrec.MinuteDirs { return r.snap.Load().dirs }
func (r *minuteRecording) driveUp() bool { return r.snap.Load().driveUp }

// DriveConfigured meldet, ob ein Laufwerk eingerichtet ist, wie der Schnappschuss es sieht.
func (r *minuteRecording) DriveConfigured() bool { return r.snap.Load().driveConfigured }
func (r *minuteRecording) limits() learnrec.Limits { return r.snap.Load().limits }
func (r *minuteRecording) stepDir() string { return r.snap.Load().stepDir() }

// Flush schreibt Minuten und Schritte an den Ort. Beide laufen, auch wenn der
// eine einen Fehler meldet.
func (r *minuteRecording) Flush(now time.Time) error {
return errors.Join(r.store.Flush(now), r.steps.Flush(now))
}

// Reset loescht die Minuten und die Schritte am Ort, am Laufwerk und im System.
func (r *minuteRecording) Reset() error {
drive := storage.DriveRuntimeDir(storage.Paths{Mount: r.src.mount})
return errors.Join(r.store.Reset(), r.steps.Reset(r.src.dataDir, drive))
}

// stepTopic ist das Topic der Reglerschritte aller Szenarien des Dienstes.
func stepTopic(serviceID string) string {
return "outstation/" + serviceID + "/scenario/+/step"
}

// stepScenario liefert die Szenario-ID eines Schritt-Topics des Dienstes. ok ist
// false bei jedem anderen Topic.
func stepScenario(serviceID, topic string) (string, bool) {
id, ok := strings.CutPrefix(topic, "outstation/"+serviceID+"/scenario/")
if !ok {
return "", false
}
id, ok = strings.CutSuffix(id, "/step")
if !ok || strings.Contains(id, "/") {
return "", false
}
return id, true
}

// watchHandler verteilt die Nachrichten von mqttclient.WatchTopics. Schritte gehen
// an den StepLog, alles andere an other. Ein unlesbarer Schritt faellt in Add weg.
func watchHandler(serviceID string, steps *autolearn.StepLog, other func(topic string, payload []byte)) func(topic string, payload []byte) {
return func(topic string, payload []byte) {
if id, ok := stepScenario(serviceID, topic); ok {
_ = steps.Add(id, payload)
return
}
other(topic, payload)
}
}
Loading
Loading