Publish savings data on startup (#5048)
This commit is contained in:
parent
03c04b1a67
commit
3862fcb85a
1 changed files with 3 additions and 1 deletions
|
|
@ -31,6 +31,7 @@ type Savings struct {
|
||||||
selfConsumptionCharged float64 // Self-produced energy charged since startup (kWh)
|
selfConsumptionCharged float64 // Self-produced energy charged since startup (kWh)
|
||||||
selfConsumptionCost float64 // Running total of charged self-produced energy cost (e.g. EUR)
|
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, ..)
|
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 {
|
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() }()
|
defer func() { s.updated = s.clock.Now() }()
|
||||||
|
|
||||||
// no charging, no need to update
|
// no charging, no need to update
|
||||||
if chargePower == 0 {
|
if chargePower == 0 && s.hasPublished {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,6 +176,7 @@ func (s *Savings) Update(p publisher, gridPower, pvPower, batteryPower, chargePo
|
||||||
p.publish("savingsSelfConsumptionPercent", s.SelfConsumptionPercent())
|
p.publish("savingsSelfConsumptionPercent", s.SelfConsumptionPercent())
|
||||||
p.publish("savingsEffectivePrice", s.EffectivePrice())
|
p.publish("savingsEffectivePrice", s.EffectivePrice())
|
||||||
p.publish("savingsAmount", s.SavingsAmount())
|
p.publish("savingsAmount", s.SavingsAmount())
|
||||||
|
s.hasPublished = true
|
||||||
|
|
||||||
s.save()
|
s.save()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue