Fix phase detection unstable with estimated power usage

This commit is contained in:
andig 2022-01-02 13:56:42 +01:00
parent 1f1c062f99
commit 94b889707c

View file

@ -1196,10 +1196,11 @@ func (lp *LoadPoint) updateChargeCurrents() {
lp.chargeCurrents = nil
phaseMeter, ok := lp.chargeMeter.(api.MeterCurrent)
if !ok {
// guess active phases from power consumption
// assumes that chargePower has been updated before
// Guess active phases from power consumption. Assumes that chargePower has been
// updated before. Discussion in https://github.com/evcc-io/evcc/issues/2146 and
// https://github.com/evcc-io/evcc/issues/2177
if lp.charging() && lp.chargeCurrent > 0 {
phases := int(math.Round(lp.chargePower / Voltage / lp.chargeCurrent))
phases := int(math.Ceil(lp.chargePower/Voltage/lp.chargeCurrent - 0.05))
if phases >= 1 && phases <= 3 {
lp.activePhases = phases
lp.log.DEBUG.Printf("detected phases: %dp (%.1fA @ %.0fW)", lp.activePhases, lp.chargeCurrent, lp.chargePower)