Skip to content

Commit

Permalink
Fix: allow management of DPL inverters while DPL is off
Browse files Browse the repository at this point in the history
we do allow to send limit updates and to start or stop the inverter
using the web UI or MQTT payloads or any other supported mean even if
this inverter is governed by the DPL, while the DPL is disabled. this
is also documented explicitly (see DPL mode MQTT docs).

after implementing support for multiple inverters, this behavior changed
unintentionally. this changeset makes sure that inverters are shut down
once when the DPL dis disabled, but are left alone afterwards for as
long as the DPL is disabled.
  • Loading branch information
schlimmchen committed Jan 12, 2025
1 parent bd2252e commit c1a318f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
3 changes: 2 additions & 1 deletion include/PowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class PowerLimiterClass {
std::pair<bool, uint32_t> _nextInverterRestart = { false, 0 };
bool _fullSolarPassThroughEnabled = false;
bool _verboseLogging = true;
bool _shutdownComplete = false;

frozen::string const& getStatusText(Status status);
void announceStatus(Status status);
bool shutdown(Status status);
bool isDisabled();
void reloadConfig();
std::pair<float, char const*> getInverterDcVoltage();
float getBatteryVoltage(bool log = false);
Expand Down
39 changes: 22 additions & 17 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,31 @@ void PowerLimiterClass::announceStatus(PowerLimiterClass::Status status)
_lastStatusPrinted = millis();
}

/**
* returns true if the inverters' state was changed or is about to change, i.e.,
* if any are actually in need of a shutdown. returns false otherwise, i.e., the
* inverters are already shut down.
*/
bool PowerLimiterClass::shutdown(PowerLimiterClass::Status status)
bool PowerLimiterClass::isDisabled()
{
announceStatus(status);
auto const& config = Configuration.get();

if (!config.PowerLimiter.Enabled) {
announceStatus(Status::DisabledByConfig);
}
else if (Mode::Disabled == _mode) {
announceStatus(Status::DisabledByMqtt);
}
else {
_shutdownComplete = false;
return false;
}

// we only shut down governed inverters once when the DPL is disabled by
// configuration or by the MQTT mode setting. afterwards, we leave the
// inverter(s) alone so they can be managed through other means.
if (_shutdownComplete) { return true; }

for (auto& upInv : _inverters) { upInv->standby(); }

return updateInverters();
_shutdownComplete = !updateInverters();

return true;
}

void PowerLimiterClass::reloadConfig()
Expand Down Expand Up @@ -157,15 +170,7 @@ void PowerLimiterClass::loop()
return announceStatus(Status::InverterCmdPending);
}

if (!config.PowerLimiter.Enabled) {
shutdown(Status::DisabledByConfig);
return;
}

if (Mode::Disabled == _mode) {
shutdown(Status::DisabledByMqtt);
return;
}
if (isDisabled()) { return; }

if (_reloadConfigFlag) {
reloadConfig();
Expand Down

0 comments on commit c1a318f

Please sign in to comment.