From 3862fcb85a7b84ed8b921466592b6aaf70743781 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Fri, 4 Nov 2022 11:36:13 +0100 Subject: [PATCH] Publish savings data on startup (#5048) --- core/savings.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/savings.go b/core/savings.go index 857268589..9cf181ccb 100644 --- a/core/savings.go +++ b/core/savings.go @@ -31,6 +31,7 @@ type Savings struct { selfConsumptionCharged float64 // Self-produced energy charged since startup (kWh) selfConsumptionCost float64 // Running total of charged self-produced energy cost (e.g. EUR) lastGridPrice, lastFeedInPrice float64 // Stores the last published grid price. Needed to detect price changes (Awattar, ..) + hasPublished bool // Has initial publish happened? } func NewSavings(tariffs tariff.Tariffs) *Savings { @@ -152,7 +153,7 @@ func (s *Savings) Update(p publisher, gridPower, pvPower, batteryPower, chargePo defer func() { s.updated = s.clock.Now() }() // no charging, no need to update - if chargePower == 0 { + if chargePower == 0 && s.hasPublished { return 0, 0 } @@ -175,6 +176,7 @@ func (s *Savings) Update(p publisher, gridPower, pvPower, batteryPower, chargePo p.publish("savingsSelfConsumptionPercent", s.SelfConsumptionPercent()) p.publish("savingsEffectivePrice", s.EffectivePrice()) p.publish("savingsAmount", s.SavingsAmount()) + s.hasPublished = true s.save()