Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ca31a44
fix(autolearn): learn the season median of the weather factor from me…
Developer-Simon Nov 30, 2026
d5ffb8e
fix(autolearn): count a load that the PV covers as a weather measurement
Developer-Simon Nov 30, 2026
0ad8879
fix(autolearn): need a known off state before a switch counts as turn…
Developer-Simon Nov 30, 2026
53d5881
fix(autolearn): let a detected shade cap the best PV curve
Developer-Simon Nov 30, 2026
839eae2
fix(autolearn): expect the night base load from the outdoor temperature
Developer-Simon Nov 30, 2026
5db0bd2
fix(autolearn): ignore rule started runs when learning the day start
Developer-Simon Nov 30, 2026
8b74a6e
fix(autolearn): count a rule start in the first quarter of the day
Developer-Simon Nov 30, 2026
da6fe78
fix(autolearn): suggest the threshold reached on three of the last 14…
Developer-Simon Nov 30, 2026
d2a3351
refactor(autolearn): share the rounding step of the suggested threshold
Developer-Simon Nov 30, 2026
ea018f3
fix(autolearn): find contradicting rules whose ranges meet
Developer-Simon Nov 30, 2026
e85cf0b
feat(monitoring): add a notice for a missing site location
Developer-Simon Nov 30, 2026
ce30731
test(autolearn): prove the region tests against empty ranges
Developer-Simon Nov 30, 2026
9300975
feat(monitoring): ask for the site location when PV learning needs it
Developer-Simon Nov 30, 2026
a7315a2
docs(dashboard): describe the corrected learning methods
Developer-Simon Nov 30, 2026
556b5ae
chore(webui): bump cache marks for the learning follow-up
Developer-Simon Nov 30, 2026
8ab46e3
docs(dashboard): match the learning docs to the reviewed behaviour
Developer-Simon Nov 30, 2026
ee702d3
fix(autolearn): correct the findings of the branch review
Developer-Simon Nov 30, 2026
dc430cb
chore(release): bump component versions
Nov 30, 2026
c410fb3
docs(changelog): update changelogs
Nov 30, 2026
05b07be
chore(changelog): fold the learning follow-up into #279
Developer-Simon Nov 30, 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
9 changes: 9 additions & 0 deletions changelog/highlights/306.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"de": {
"*": "Das Lernen rechnet genauer und bittet um den Standort, wenn er für PV fehlt"
},
"en": {
"*": "Correct the learning methods after the spec check"
},
"folded_into": 279
}
18 changes: 17 additions & 1 deletion dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## v0.11.23-pre.40 (2026-11-06)
## v0.11.23-pre.41 (2026-11-06)

### Features

Expand Down Expand Up @@ -38,6 +38,8 @@
- **monitoring:** Monitoring shows the forecast check, a year comparison and the learned values as a usual day (#297) (4f93975)
- **dashboard:** show system versions on the versions page (#299) (18a2b0b)
- **automations:** Monitoring checks the results of adopted suggestions and rules report a season drift (#300) (d9e023b)
- **monitoring:** add a notice for a missing site location (e85cf0b)
- **monitoring:** ask for the site location when PV learning needs it (9300975)
- **automations:** mark rules that came from a learned suggestion (f85130f)
- **webui:** record which suggestion a saved rule came from (ae2baed)
- **autolearn:** measure the effect of an adopted suggestion against the season (a1e9dc6)
Expand Down Expand Up @@ -368,6 +370,17 @@
- **storage:** set up, back up and replug the additional drive reliably (#247) (b668394)
- **automations:** correct the learning feature after the full review (#296) (88f3c75)
- Monitoring names values without a role and links to the learning settings (#303) (29450b8)
- **autolearn:** learn the season median of the weather factor from measured minutes (ca31a44)
- **autolearn:** count a load that the PV covers as a weather measurement (d5ffb8e)
- **autolearn:** need a known off state before a switch counts as turned on (0ad8879)
- **autolearn:** let a detected shade cap the best PV curve (53d5881)
- **autolearn:** expect the night base load from the outdoor temperature (839eae2)
- **autolearn:** ignore rule started runs when learning the day start (5db0bd2)
- **autolearn:** count a rule start in the first quarter of the day (8b74a6e)
- **autolearn:** suggest the threshold reached on three of the last 14 days (da6fe78)
- **autolearn:** find contradicting rules whose ranges meet (ea018f3)
- **autolearn:** correct the findings of the branch review (ee702d3)
- **automations:** correct the learning methods after the spec check (#306)
- **history:** keep proxies from compressing the event streams (#304) (0298760)
- **backup:** A restore stays in place even when the battery state cannot be written (#288) (e5c5437)
- **monitoring:** add the text for the learning settings button (50b5e84)
Expand Down Expand Up @@ -533,6 +546,7 @@

### Refactors

- **autolearn:** share the rounding step of the suggested threshold (d2a3351)
- **devicemap:** call the saved chains chains like the energy page (6974b1b)
- **chainsuggest:** read minute means from the shared collector (f1f3c68)
- **dashboard:** feed chain learning and the rule observer through the shared collector (5b8386f)
Expand All @@ -551,6 +565,7 @@

### Tests

- **autolearn:** prove the region tests against empty ranges (ce30731)
- **smoke:** split the main run into four independent runs (fa7e3df)
- **demo:** expect a sure effect beside the estimates (aa987aa)
- **demo:** fake the system packages for the versions page (ca2dc1e)
Expand All @@ -576,6 +591,7 @@

### Chores

- **webui:** bump cache marks for the learning follow-up (556b5ae)
- **energy:** drop the styles and getter of the old energy notices (a864af2)
- **monitoring:** drop the old notice keys, bump the changed assets, describe the button (c99833b)
- **webui:** bump the cache marks of the changed automation assets (fa93e53)
Expand Down
2 changes: 1 addition & 1 deletion dashboard/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.11.23-pre.40
v0.11.23-pre.41
32 changes: 24 additions & 8 deletions dashboard/cmd/dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func main() {
automationEngine.Register(autolearn.BaseLoadDetector)
automationEngine.Register(autolearn.BatteryDetector)
automationEngine.Register(autolearn.NewPVModelDetector(pvTracker.Snapshot, pvModelStore))
automationEngine.Register(autolearn.NewShadeDetector(pvTracker.Snapshot, pvModelStore.Model))
automationEngine.Register(autolearn.NewShadeDetector(pvTracker.Snapshot, pvModelStore))
// Modell und Himmelsraster fuer den Rest-Ueberschuss. Der Raster-Schnappschuss
// entsteht nur, wenn ein Modell da ist.
pvSource := func() (autolearn.PVModel, *autolearn.Raster, bool) {
Expand Down Expand Up @@ -711,16 +711,17 @@ func main() {
if monitoringSuggestions != nil {
in.Suggestions = monitoringSuggestions()
}
if effectsOn() {
var doc autolearn.Doc
ok := false
if raw, err := configManager.Read("automation_rules"); err == nil {
if parsed, err := autolearn.ParseDoc(raw); err == nil {
doc, ok = parsed, true
}
var doc autolearn.Doc
ok := false
if raw, err := configManager.Read("automation_rules"); err == nil {
if parsed, err := autolearn.ParseDoc(raw); err == nil {
doc, ok = parsed, true
}
}
if effectsOn() {
in.Effects, in.RuleNames = monitoringEffects(effectStore.Measured(time.Now()), doc, ok)
}
in.LocationMissing = locationMissing(effectsOn(), ok, doc, in.Config.Assignments)
return in
}
monitoringStore := monitoring.OpenStore(filepath.Join(autolearnDir, "monitoring.json"), log.Printf)
Expand Down Expand Up @@ -2048,3 +2049,18 @@ func performanceBusy(jobDir string) func() bool {
return progress.State == "pending" || progress.State == "running"
}
}

// locationMissing reports whether the notice asks for the site location: the
// pattern learning is on, the rules document could be read, it has no location
// and a PV plant is assigned.
func locationMissing(patternsOn, docOK bool, doc autolearn.Doc, assignments map[string]energy.Assignment) bool {
if !patternsOn || !docOK || doc.Location != nil {
return false
}
for _, a := range assignments {
if a.Role == energy.RolePV {
return true
}
}
return false
}
31 changes: 31 additions & 0 deletions dashboard/cmd/dashboard/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"time"

"github.com/Developer-Simon/energy-node-dashboard/internal/appconfig"
"github.com/Developer-Simon/energy-node-dashboard/internal/autolearn"
"github.com/Developer-Simon/energy-node-dashboard/internal/chainwatch"
"github.com/Developer-Simon/energy-node-dashboard/internal/energy"
"github.com/Developer-Simon/energy-node-dashboard/internal/nodeagent"
"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/sun"
)

func TestValidateNodeDeviceID(t *testing.T) {
Expand Down Expand Up @@ -184,3 +186,32 @@ func TestHoldsFromEnv(t *testing.T) {
t.Fatalf("30 s: got %+v, want all five at 30 s", got)
}
}

// The location notice needs learning switched on, a readable rules document,
// no location in it and a PV plant.
func TestLocationMissing(t *testing.T) {
pv := map[string]energy.Assignment{"pv": {Role: energy.RolePV}}
grid := map[string]energy.Assignment{"grid": {Role: energy.RoleGridImport}}
withLocation := autolearn.Doc{Location: &sun.Location{Lat: 52.52, Lon: 13.405}}
tests := []struct {
name string
patternsOn bool
docOK bool
doc autolearn.Doc
assignments map[string]energy.Assignment
want bool
}{
{"all conditions hold", true, true, autolearn.Doc{}, pv, true},
{"learning switched off", false, true, autolearn.Doc{}, pv, false},
{"rules unreadable", true, false, autolearn.Doc{}, pv, false},
{"location set", true, true, withLocation, pv, false},
{"no PV plant", true, true, autolearn.Doc{}, grid, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := locationMissing(tt.patternsOn, tt.docOK, tt.doc, tt.assignments); got != tt.want {
t.Errorf("locationMissing = %v, want %v", got, tt.want)
}
})
}
}
45 changes: 39 additions & 6 deletions dashboard/internal/autolearn/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type baseRec struct {
load [dayQuarters]float64
prof [dayQuarters]float64 // Last geteilt durch Tagessumme, nur bei full
hand [dayQuarters]float64 // Handgriffe aller Geräte je Viertelstunde
ruleW [dayQuarters]float64 // Leistung der per Regel gestarteten Läufe je Viertelstunde
group int // Tagestyp, -1 ohne Zuordnung
}

Expand Down Expand Up @@ -139,6 +140,10 @@ func baseRecords(days []DayFile, loc *time.Location, today string) []baseRec {
for q := range dd.Hand {
r.hand[q] += float64(dd.Hand[q])
}
rw := ruleRunW(dd)
for q := range rw {
r.ruleW[q] += rw[q]
}
}
r.full = allSeen && sum > 0
r.morn = morning && sumMorning > 0
Expand Down Expand Up @@ -554,6 +559,29 @@ func houseWindowOf(byDate map[string]*DayFile, day time.Time, q int) (baseMetric
return baseMetricOver(load, hand), true
}

// ruleRunW liefert je Viertelstunde die Leistung eines Laufs, den eine Regel
// gestartet hat. Ein Lauf beginnt in Viertelstunde q, wenn er dort läuft und
// vorher nicht. Für q = 0 gilt die Viertelstunde davor als aus, ein Lauf in 0
// startet also dort. Er ist ein Regel-Lauf, wenn die Regel ihn in q gestartet
// hat und weder Handgriff noch Ext ihn berührt. Er zählt bis vor die nächste
// Viertelstunde ohne Lauf. Ein Lauf, der vor Mitternacht begann, hat in 0 keine
// Regel (Rule[0] == 0) und zählt deshalb nicht.
func ruleRunW(dd *DeviceDay) [dayQuarters]float64 {
var w [dayQuarters]float64
for q := 0; q < dayQuarters; q++ {
if dd.OnMin[q] == 0 || (q > 0 && dd.OnMin[q-1] != 0) {
continue
}
if dd.Rule[q] == 0 || dd.Hand[q] != 0 || dd.Ext[q] != 0 {
continue
}
for k := q; k < dayQuarters && dd.OnMin[k] > 0; k++ {
w[k] = float64(dd.AvgW[k])
}
}
return w
}

// baseBounds setzt je Tagestyp den Kreismedian von Tagesbeginn und Nachtruhe.
func baseBounds(recs []baseRec, base *Base) {
starts := map[int][]float64{}
Expand All @@ -579,20 +607,25 @@ func baseBounds(recs []baseRec, base *Base) {
}

// baseDayBounds findet Tagesbeginn und Nachtruhe eines Tages in Minuten. Die
// Last liegt für zwei Viertelstunden über Nachtlast + max(50 W, 3 Streuungen).
// Der Beginn ist die erste solche Viertelstunde oder der erste Handgriff, je
// nachdem was früher kommt. Die Nachtruhe spiegelt das vom Abend her.
// Last ohne die per Regel gestarteten Läufe liegt für zwei Viertelstunden über
// Nachtlast + max(50 W, 3 Streuungen). Der Beginn ist die erste solche
// Viertelstunde oder der erste Handgriff, je nachdem was früher kommt. Die
// Nachtruhe spiegelt das vom Abend her.
func baseDayBounds(r *baseRec) (start, end float64, ok bool) {
night := r.load[:baseNight]
var load [dayQuarters]float64
for q := range load {
load[q] = math.Max(0, r.load[q]-r.ruleW[q])
}
night := load[:baseNight]
thr := basePercentile10(night) + math.Max(50, 3*MADScale(night))
first, last := -1, -1
for q := 0; q+1 < dayQuarters && first < 0; q++ {
if r.load[q] > thr && r.load[q+1] > thr {
if load[q] > thr && load[q+1] > thr {
first = q
}
}
for q := dayQuarters - 1; q >= 1 && last < 0; q-- {
if r.load[q] > thr && r.load[q-1] > thr {
if load[q] > thr && load[q-1] > thr {
last = q
}
}
Expand Down
116 changes: 116 additions & 0 deletions dashboard/internal/autolearn/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,119 @@ func TestBaseQuietDaysWithoutManualSwitching(t *testing.T) {
t.Errorf("away days = %v, want exactly the %d quiet days", base.Away, len(quiet))
}
}

// baseRuleDay baut einen vollständigen Tag. Die Last ist nachts 100 W, die
// Wärmepumpe läuft 05:00 bis 06:30 mit zusätzlich 2000 W, danach 600 W Haus.
// Gerät und Startart kommen von außen, damit Regel und Handgriff gleich aussehen.
func baseRuleDay(day time.Time, dev *DeviceDay) DayFile {
var load [dayQuarters]float32
for q := range load {
switch {
case q >= 27:
load[q] = 600
case q >= 20 && q <= 25:
load[q] = 2100
default:
load[q] = 100
}
}
f := DayFile{V: dayFileVersion, Day: day.Format(dayLayout), Devices: map[string]*DeviceDay{"heatpump": dev},
Events: []EventRec{}, Actions: []ActionRec{}}
for q := range load {
f.Site.Seen[q] = 1
f.Site.LoadTotal[q] = load[q]
}
return f
}

// baseRuleDays sind 14 gleiche Tage ab Montag, 5. Januar 2026.
func baseRuleDays(t *testing.T, loc *time.Location, dev func() *DeviceDay) []DayFile {
t.Helper()
start := time.Date(2026, 1, 5, 0, 0, 0, 0, loc)
var days []DayFile
for i := 0; i < 14; i++ {
days = append(days, baseRuleDay(start.AddDate(0, 0, i), dev()))
}
return days
}

func TestDayStartIgnoresRuleStartedHeatPump(t *testing.T) {
loc := berlinLoc(t)
days := baseRuleDays(t, loc, func() *DeviceDay {
dd := &DeviceDay{}
for q := 20; q <= 25; q++ {
dd.OnMin[q] = 15
dd.AvgW[q] = 2000
}
dd.Rule[20] = 1
return dd
})
now := time.Date(2026, 2, 1, 12, 0, 0, 0, loc)
base := BuildBaseAt(days, loc, now)
g := base.DayType["2026-01-06"]
if got := base.DayStart[g]; math.Abs(got-405) > 1 {
t.Errorf("day start = %.1f, want 405 (06:45), not the rule started 05:00", got)
}
}

func TestDayStartKeepsHandStartedDevice(t *testing.T) {
loc := berlinLoc(t)
days := baseRuleDays(t, loc, func() *DeviceDay {
dd := &DeviceDay{}
for q := 20; q <= 25; q++ {
dd.OnMin[q] = 15
dd.AvgW[q] = 2000
}
dd.Hand[20] = 1
return dd
})
now := time.Date(2026, 2, 1, 12, 0, 0, 0, loc)
base := BuildBaseAt(days, loc, now)
g := base.DayType["2026-01-06"]
if got := base.DayStart[g]; math.Abs(got-300) > 1 {
t.Errorf("day start = %.1f, want 300 (05:00) for a hand started device", got)
}
}

func TestRuleRunWStopsAtOff(t *testing.T) {
var dd DeviceDay
dd.OnMin[1], dd.OnMin[2] = 15, 15
dd.Rule[1] = 1
dd.AvgW[1], dd.AvgW[2] = 2000, 2000
w := ruleRunW(&dd)
for q := range w {
want := 0.0
if q == 1 || q == 2 {
want = 2000
}
if w[q] != want {
t.Errorf("ruleW[%d] = %.0f, want %.0f", q, w[q], want)
}
}
}

func TestRuleRunWStartsAtMidnight(t *testing.T) {
// Ein Lauf in Viertelstunde 0 startet dort. Eine Regel in 0 zählt.
var dd DeviceDay
dd.OnMin[0], dd.OnMin[1] = 15, 15
dd.Rule[0] = 1
dd.AvgW[0], dd.AvgW[1] = 2000, 2000
w := ruleRunW(&dd)
for q := range w {
want := 0.0
if q == 0 || q == 1 {
want = 2000
}
if w[q] != want {
t.Errorf("with rule: ruleW[%d] = %.0f, want %.0f", q, w[q], want)
}
}
// Ohne Regel in Viertelstunde 0 ist der Lauf vor Mitternacht begonnen.
dd.Rule[0] = 0
w = ruleRunW(&dd)
for q := range w {
if w[q] != 0 {
t.Errorf("without rule: ruleW[%d] = %.0f, want 0", q, w[q])
}
}
}
4 changes: 2 additions & 2 deletions dashboard/internal/autolearn/demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func TestDemoShadeCyclesAndSurplus(t *testing.T) {
}
ctx := context.Background()

shade := NewShadeDetector(func() *Raster { return raster }, func() (PVModel, bool) { return model, true })
shade := NewShadeDetector(func() *Raster { return raster }, shadeStore(t, model))
var shades []string
for _, c := range shade.Run(ctx, in, "") {
shades = append(shades, c.Finding.ID)
Expand Down Expand Up @@ -694,7 +694,7 @@ func TestDemoShadeCurveSkipsTheRunningDay(t *testing.T) {
in.Days = days
raster := DemoPVRaster(now, demoLat, demoLon)
model := DemoPVModel(raster)
shade := NewShadeDetector(func() *Raster { return raster }, func() (PVModel, bool) { return model, true })
shade := NewShadeDetector(func() *Raster { return raster }, shadeStore(t, model))
cands := shade.Run(context.Background(), in, "")
if len(cands) == 0 {
t.Fatal("demo shows no shade")
Expand Down
Loading
Loading