Fix green share calculation (#11545)
This commit is contained in:
parent
72b4a1d96d
commit
2471d94a09
2 changed files with 14 additions and 5 deletions
|
|
@ -790,8 +790,11 @@ func (site *Site) update(lp Updater) {
|
|||
homePower = max(homePower, 0)
|
||||
site.publish(keys.HomePower, homePower)
|
||||
|
||||
// add battery charging power to homePower to ignore all consumption which does not occur on loadpoints
|
||||
// fix for: https://github.com/evcc-io/evcc/issues/11032
|
||||
nonChargePower := homePower + max(0, -site.batteryPower)
|
||||
greenShareHome := site.greenShare(0, homePower)
|
||||
greenShareLoadpoints := site.greenShare(homePower, homePower+totalChargePower)
|
||||
greenShareLoadpoints := site.greenShare(nonChargePower, nonChargePower+totalChargePower)
|
||||
|
||||
lp.Update(sitePower, smartCostActive, batteryBuffered, batteryStart, greenShareLoadpoints, site.effectivePrice(greenShareLoadpoints), site.effectiveCo2(greenShareLoadpoints))
|
||||
|
||||
|
|
|
|||
|
|
@ -105,12 +105,17 @@ func TestGreenShare(t *testing.T) {
|
|||
{
|
||||
"half grid, half pv, battery charge, no lp",
|
||||
1000, 1000, -1000, 1000, 0,
|
||||
1, 1, 0,
|
||||
0.5, 1, 0,
|
||||
},
|
||||
{
|
||||
"half grid, half pv, battery charge, home, lp",
|
||||
1000, 1000, -1000, 500, 500,
|
||||
1, 1, 1,
|
||||
0.5, 1, 0,
|
||||
},
|
||||
{
|
||||
"pv ac limited, battery charge & grid import",
|
||||
1000, 3000, -1000, 1000, 2000,
|
||||
0.75, 1, 0.5,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +128,8 @@ func TestGreenShare(t *testing.T) {
|
|||
batteryPower: tc.battery,
|
||||
}
|
||||
|
||||
greenShareTotal := s.greenShare(0, tc.home+tc.lp)
|
||||
totalPower := tc.grid + tc.pv + max(0, tc.battery)
|
||||
greenShareTotal := s.greenShare(0, totalPower)
|
||||
if greenShareTotal != tc.greenShareTotal {
|
||||
t.Errorf("greenShareTotal wanted %.3f, got %.3f", tc.greenShareTotal, greenShareTotal)
|
||||
}
|
||||
|
|
@ -131,7 +137,7 @@ func TestGreenShare(t *testing.T) {
|
|||
if greenShareHome != tc.greenShareHome {
|
||||
t.Errorf("greenShareHome wanted %.3f, got %.3f", tc.greenShareHome, greenShareHome)
|
||||
}
|
||||
greenShareLoadpoints := s.greenShare(tc.home, tc.home+tc.lp)
|
||||
greenShareLoadpoints := s.greenShare(tc.home+max(0, -tc.battery), totalPower)
|
||||
if greenShareLoadpoints != tc.greenShareLoadpoints {
|
||||
t.Errorf("greenShareLoadpoints wanted %.3f, got %.3f", tc.greenShareLoadpoints, greenShareLoadpoints)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue