diff --git a/src/PowerLimiter.cpp b/src/PowerLimiter.cpp index 96c44ba72..252ceb5d6 100644 --- a/src/PowerLimiter.cpp +++ b/src/PowerLimiter.cpp @@ -527,23 +527,27 @@ int32_t PowerLimiterClass::calcPowerLimit(std::shared_ptr inve /** * updates the inverter state (power production and limit). returns true if a - * change to its state was requested. - * - * TODO(schlimmchen): there is no guarantee that the limit update will complete - * successfully before the power control request enabled the inverter. this - * should be a two-step process, where the limit is updated und repeated until - * set as desired, and then the inverter is started. + * change to its state was requested. this function only requests one change + * (limit value or production on/off) at a time. */ bool PowerLimiterClass::commitPowerLimit(std::shared_ptr inverter, int32_t newLimitAbs, bool enablePowerProduction) { - bool change = false; - // disable power production as soon as possible. // setting the power limit is less important. if (!enablePowerProduction && inverter->isProducing()) { MessageOutput.println("[DPL::commitPowerLimit] Stopping inverter..."); inverter->sendPowerControlRequest(false); - change = true; + return true; + } + + auto const& config = Configuration.get(); + + // make sure that the inverter starts up with its limit set to the lower + // power limit. if the DPL was in control of the inverter and if the DPL + // shut down the inverter previously, the limit should already be set to + // this value (unless a transmit error occurred). + if (enablePowerProduction && !inverter->isProducing()) { + newLimitAbs = config.PowerLimiter.LowerPowerLimit; } // early in the loop we make it a pre-requisite that this @@ -554,7 +558,6 @@ bool PowerLimiterClass::commitPowerLimit(std::shared_ptr inver auto currentLimitAbs = static_cast(currentLimitPercent * maxPower / 100); auto diff = std::abs(currentLimitAbs - newLimitAbs); - auto const& config = Configuration.get(); auto hysteresis = config.PowerLimiter.TargetPowerConsumptionHysteresis; if (hysteresis < (maxPower / 100)) { @@ -574,7 +577,7 @@ bool PowerLimiterClass::commitPowerLimit(std::shared_ptr inver PowerLimitControlType::AbsolutNonPersistent); _lastRequestedPowerLimit = newLimitAbs; - change = true; + return true; } // enable power production only after setting the desired limit, @@ -582,10 +585,10 @@ bool PowerLimiterClass::commitPowerLimit(std::shared_ptr inver if (enablePowerProduction && !inverter->isProducing()) { MessageOutput.println("[DPL::commitPowerLimit] Starting up inverter..."); inverter->sendPowerControlRequest(true); - change = true; + return true; } - return change; + return false; } /**