From 153b1b61b0638f429d103d423e383bee19cfe309 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 27 Apr 2025 14:07:26 +0200 Subject: [PATCH] Loadpoint: allow fine-grained battery boost (#19385) --- core/loadpoint.go | 19 +++++++++++++------ core/loadpoint_test.go | 2 +- core/site.go | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index cdd72aeeb..80f0cf8b2 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -20,6 +20,7 @@ import ( "github.com/evcc-io/evcc/core/planner" "github.com/evcc-io/evcc/core/session" "github.com/evcc-io/evcc/core/settings" + "github.com/evcc-io/evcc/core/site" "github.com/evcc-io/evcc/core/soc" "github.com/evcc-io/evcc/core/vehicle" "github.com/evcc-io/evcc/core/wrapper" @@ -74,8 +75,9 @@ type Task = func() // Loadpoint is responsible for controlling charge depending on // Soc needs and power availability. type Loadpoint struct { - clock clock.Clock // mockable time - bus evbus.Bus // event bus + clock clock.Clock // mockable time + bus evbus.Bus // event bus + site site.API pushChan chan<- push.Event // notifications uiChan chan<- util.Param // client push messages lpChan chan<- *Loadpoint // update requests @@ -588,7 +590,8 @@ func (lp *Loadpoint) defaultMode() { } // Prepare loadpoint configuration by adding missing helper elements -func (lp *Loadpoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Event, lpChan chan<- *Loadpoint) { +func (lp *Loadpoint) Prepare(site site.API, uiChan chan<- util.Param, pushChan chan<- push.Event, lpChan chan<- *Loadpoint) { + lp.site = site lp.uiChan = uiChan lp.pushChan = pushChan lp.lpChan = lpChan @@ -1325,8 +1328,12 @@ func (lp *Loadpoint) boostPower(batteryBoostPower float64) float64 { return 0 } - // push demand to drain battery - delta := lp.EffectiveStepPower() + // push demand to drain battery (at least 100W) + delta := math.Max(100, math.Abs(lp.site.GetResidualPower())) + + if lp.coarseCurrent() { + delta = math.Max(delta, lp.EffectiveStepPower()) + } // start boosting by setting maximum power if boost == boostStart { @@ -1341,7 +1348,7 @@ func (lp *Loadpoint) boostPower(batteryBoostPower float64) float64 { } } - res := batteryBoostPower + delta + res := batteryBoostPower + delta + lp.site.GetResidualPower() lp.log.DEBUG.Printf("pv charge battery boost: %.0fW = -%.0fW battery - %.0fW boost", -res, batteryBoostPower, delta) return res diff --git a/core/loadpoint_test.go b/core/loadpoint_test.go index c435bf203..68aa9347d 100644 --- a/core/loadpoint_test.go +++ b/core/loadpoint_test.go @@ -82,7 +82,7 @@ func attachListeners(t *testing.T, lp *Loadpoint) { } uiChan, pushChan, lpChan := createChannels(t) - lp.Prepare(uiChan, pushChan, lpChan) + lp.Prepare(new(Site), uiChan, pushChan, lpChan) } func TestNew(t *testing.T) { diff --git a/core/site.go b/core/site.go index 922b47e34..3807e1329 100644 --- a/core/site.go +++ b/core/site.go @@ -1022,7 +1022,7 @@ func (site *Site) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Event) } }(id) - lp.Prepare(lpUIChan, lpPushChan, site.lpUpdateChan) + lp.Prepare(site, lpUIChan, lpPushChan, site.lpUpdateChan) } }