Skip to content

Commit

Permalink
Merge branch 'pr/schlimmchen/287' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Jul 2, 2023
2 parents 99876d7 + 9aeb158 commit afd8790
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 131 deletions.
49 changes: 34 additions & 15 deletions include/PowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
#define PL_MODE_FULL_DISABLE 1
#define PL_MODE_SOLAR_PT_ONLY 2


typedef enum {
SHUTDOWN = 0,
ACTIVE
} plStates;

typedef enum {
EMPTY_WHEN_FULL= 0,
EMPTY_AT_NIGHT
Expand All @@ -30,33 +24,58 @@ typedef enum {

class PowerLimiterClass {
public:
enum class Status : unsigned {
Initializing,
DisabledByConfig,
DisabledByMqtt,
PowerMeterDisabled,
PowerMeterTimeout,
PowerMeterPending,
InverterInvalid,
InverterChanged,
InverterOffline,
InverterCommandsDisabled,
InverterLimitPending,
InverterPowerCmdPending,
InverterStatsPending,
UnconditionalSolarPassthrough,
NoVeDirect,
Settling,
Stable,
LowerLimitUndercut
};

void init();
void loop();
uint8_t getPowerLimiterState();
int32_t getLastRequestedPowewrLimit();
int32_t getLastRequestedPowerLimit();
void setMode(uint8_t mode);
bool getMode();
void calcNextInverterRestart();

private:
uint32_t _lastLoop = 0;
int32_t _lastRequestedPowerLimit = 0;
uint32_t _lastLimitSetTime = 0;
plStates _plState;
bool _shutdownInProgress;
Status _lastStatus = Status::Initializing;
uint32_t _lastStatusPrinted = 0;
uint32_t _lastCalculation = 0;
uint32_t _calculationBackoffMs = 0;
uint8_t _mode = PL_MODE_ENABLE_NORMAL_OP;
std::shared_ptr<InverterAbstract> _inverter = nullptr;
bool _batteryDischargeEnabled = false;
uint32_t _nextInverterRestart = 0; // Values: 0->not calculated / 1->no restart configured / >1->time of next inverter restart in millis()
uint32_t _nextCalculateCheck = 5000; // time in millis for next NTP check to calulate restart
bool _fullSolarPassThroughEnabled = false;

float _powerMeter1Power;
float _powerMeter2Power;
float _powerMeter3Power;

std::string const& getStatusText(Status status);
void announceStatus(Status status);
void shutdown(Status status);
int32_t inverterPowerDcToAc(std::shared_ptr<InverterAbstract> inverter, int32_t dcPower);
void unconditionalSolarPassthrough(std::shared_ptr<InverterAbstract> inverter);
bool canUseDirectSolarPower();
int32_t calcPowerLimit(std::shared_ptr<InverterAbstract> inverter, bool solarPowerEnabled, bool batteryDischargeEnabled);
void commitPowerLimit(std::shared_ptr<InverterAbstract> inverter, int32_t limit, bool enablePowerProduction);
void setNewPowerLimit(std::shared_ptr<InverterAbstract> inverter, int32_t newPowerLimit);
bool setNewPowerLimit(std::shared_ptr<InverterAbstract> inverter, int32_t newPowerLimit);
int32_t getSolarChargePower();
float getLoadCorrectedVoltage(std::shared_ptr<InverterAbstract> inverter);
bool isStartThresholdReached(std::shared_ptr<InverterAbstract> inverter);
Expand Down
8 changes: 8 additions & 0 deletions lib/Hoymiles/src/inverters/HM_Abstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ bool HM_Abstract::sendActivePowerControlRequest(float limit, PowerLimitControlTy
return false;
}

if (CMD_PENDING == SystemConfigPara()->getLastLimitCommandSuccess()) {
return false;
}

if (type == PowerLimitControlType::RelativNonPersistent || type == PowerLimitControlType::RelativPersistent) {
limit = min<float>(100, limit);
}
Expand All @@ -147,6 +151,10 @@ bool HM_Abstract::sendPowerControlRequest(bool turnOn)
return false;
}

if (CMD_PENDING == PowerCommand()->getLastPowerCommandSuccess()) {
return false;
}

if (turnOn) {
_powerState = 1;
} else {
Expand Down
Loading

0 comments on commit afd8790

Please sign in to comment.