Skip to content

Commit

Permalink
Limit Battery discharge to base load below 70% SoC.
Browse files Browse the repository at this point in the history
TODO: Configurable threshold.

This assumes the Battery will always fully discharge overnight and is
intended to reduce the discharge speed so the average SoC is closer to
50% for longer battery life.
  • Loading branch information
ranma committed Sep 22, 2024
1 parent 6fd47aa commit 3fa02bf
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,12 @@ int32_t PowerLimiterClass::getSolarPower()

int32_t PowerLimiterClass::getBatteryDischargeLimit()
{
auto currentLimit = Battery.getDischargeCurrentLimit();
auto const& config = Configuration.get();
float currentLimit = Battery.getDischargeCurrentLimit();
float batterySoC = Battery.getStats()->getSoC();
float inverterEfficiencyFactor = getInverterEfficiency(_inverter);
float baseLoadAC = config.PowerLimiter.BaseLoadLimit;
float baseLoadDC = baseLoadAC / inverterEfficiencyFactor;

if (currentLimit == FLT_MAX) {
// the returned value is arbitrary, as long as it's
Expand All @@ -912,11 +917,17 @@ int32_t PowerLimiterClass::getBatteryDischargeLimit()
// This uses inverter voltage since there is a voltage drop between
// battery and inverter, so since we are regulating the inverter
// power we should use its voltage.
auto const& config = Configuration.get();
auto channel = static_cast<ChannelNum_t>(config.PowerLimiter.InverterChannelId);
float inverterVoltage = _inverter->Statistics()->getChannelFieldValue(TYPE_DC, channel, FLD_UDC);
float dcPowerLimit = inverterVoltage * currentLimit;

if (batterySoC < 70 && dcPowerLimit > baseLoadDC) {
MessageOutput.printf("[DPL::getBatteryDischargeLimit] Limit reduced by SoC to: %f\r\n",
baseLoadDC);
dcPowerLimit = baseLoadDC;
}

return static_cast<int32_t>(inverterVoltage * currentLimit);
return static_cast<int32_t>(dcPowerLimit);
}

float PowerLimiterClass::getLoadCorrectedVoltage()
Expand Down

0 comments on commit 3fa02bf

Please sign in to comment.