From fc3be70251ef377c8b50e575133f926128bb310c Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 20 Jul 2020 12:52:16 +0200 Subject: [PATCH] Fix target current calcuation by taking actual charging mode into account --- core/loadpoint.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index c9d2f668a..15062f0e7 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -297,10 +297,14 @@ func (lp *LoadPoint) detectPhases() { // maxCurrent calculates the maximum target current for PV mode func (lp *LoadPoint) maxCurrent(mode api.ChargeMode, sitePower float64) int64 { // calculate target charge current from delta power and actual current + effectiveCurrent := lp.handler.TargetCurrent() + if lp.status != api.StatusC { + effectiveCurrent = 0 + } deltaCurrent := powerToCurrent(-sitePower, lp.Phases) - targetCurrent := clamp(lp.handler.TargetCurrent()+deltaCurrent, 0, lp.MaxCurrent) + targetCurrent := clamp(effectiveCurrent+deltaCurrent, 0, lp.MaxCurrent) - lp.log.DEBUG.Printf("max charge current: %dA = %dA + %dA (%.0fW @ %dp)", targetCurrent, lp.handler.TargetCurrent(), deltaCurrent, sitePower, lp.Phases) + lp.log.DEBUG.Printf("max charge current: %dA = %dA + %dA (%.0fW @ %dp)", targetCurrent, effectiveCurrent, deltaCurrent, sitePower, lp.Phases) // in MinPV mode return at least minCurrent if mode == api.ModeMinPV && targetCurrent < lp.MinCurrent {