sum savings to be dynamic pricing compatible (#2326)

This commit is contained in:
schenlap 2022-01-17 06:27:51 +01:00 • committed by GitHub
parent 0c2355036c
commit 1c7d8f3683
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,7 @@ type Savings struct {
updated time.Time // Time of last charged value update
gridCharged float64 // Grid energy charged since startup (kWh)
gridCost float64 // Running total of charged grid energy cost (e.g. EUR)
gridSavedCost float64 // Running total of saved cost from self consumption (e.g. EUR)
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, ..)
@ -68,7 +69,7 @@ func (s *Savings) EffectivePrice() float64 {
}
func (s *Savings) SavingsAmount() float64 {
return s.selfConsumptionCharged * (s.currentGridPrice() - s.currentFeedInPrice())
return s.gridSavedCost
}
func (s *Savings) shareOfSelfProducedEnergy(gridPower, pvPower, batteryPower float64) float64 {
@ -140,6 +141,7 @@ func (s *Savings) Update(p publisher, gridPower, pvPower, batteryPower, chargePo
s.gridCharged += addedGrid
s.gridCost += addedGrid * gridPrice
s.gridSavedCost += addedSelfConsumption * (gridPrice - feedinPrice)
s.selfConsumptionCharged += addedSelfConsumption
s.selfConsumptionCost += addedSelfConsumption * feedinPrice