From 0fd7b75e83e8cec260fb1826eab1802300dead02 Mon Sep 17 00:00:00 2001 From: helgeerbe Date: Mon, 12 Jun 2023 13:06:31 +0200 Subject: [PATCH] Fix(Power Limiter): hysteresis is not repected properly --- src/PowerLimiter.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PowerLimiter.cpp b/src/PowerLimiter.cpp index 71a6f6d1..08ac0b40 100644 --- a/src/PowerLimiter.cpp +++ b/src/PowerLimiter.cpp @@ -244,6 +244,7 @@ int32_t PowerLimiterClass::calcPowerLimit(std::shared_ptr inve { CONFIG_T& config = Configuration.get(); + int32_t acPower = 0; int32_t newPowerLimit = round(PowerMeter.getPowerTotal()); if (!solarPowerEnabled && !batteryDischargeEnabled) { @@ -256,8 +257,8 @@ int32_t PowerLimiterClass::calcPowerLimit(std::shared_ptr inve // the produced power of this inverter has also to be taken into account. // We don't use FLD_PAC from the statistics, because that // data might be too old and unreliable. - float acPower = inverter->Statistics()->getChannelFieldValue(TYPE_AC, (ChannelNum_t) config.PowerLimiter_InverterChannelId, FLD_PAC); - newPowerLimit += static_cast(acPower); + acPower = static_cast(inverter->Statistics()->getChannelFieldValue(TYPE_AC, (ChannelNum_t) config.PowerLimiter_InverterChannelId, FLD_PAC)); + newPowerLimit += acPower; } // We're not trying to hit 0 exactly but take an offset into account @@ -268,8 +269,8 @@ int32_t PowerLimiterClass::calcPowerLimit(std::shared_ptr inve // Check if the new value is within the limits of the hysteresis and // if we can discharge the battery // If things did not change much we just use the old setting - if (newPowerLimit >= (-config.PowerLimiter_TargetPowerConsumptionHysteresis) && - newPowerLimit <= (+config.PowerLimiter_TargetPowerConsumptionHysteresis) && + if ((newPowerLimit - acPower) >= (-config.PowerLimiter_TargetPowerConsumptionHysteresis) && + (newPowerLimit - acPower) <= (+config.PowerLimiter_TargetPowerConsumptionHysteresis) && batteryDischargeEnabled ) { MessageOutput.println("[PowerLimiterClass::loop] reusing old limit"); return _lastRequestedPowerLimit;