there is no need to assume and hardcode a fixed efficiency for the Victron solar charger. the charger reports the voltage and current at its battery terminal, which can be used to calculate the charger's actual power output. the fallback to 100% for the efficiency of the Hoymiles inverter, in case it is not producing power, is too optimistic. this commit proposes to use 96.7% as the efficiency for that case, which is the peak efficiency for many (all?) Hoymiles inverters as per datasheet. that value should be closer to the real efficiency that will be achieved once the inverter is turned on.
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include "Configuration.h"
|
|
#include <espMqttClient.h>
|
|
#include <Arduino.h>
|
|
#include <Hoymiles.h>
|
|
#include <memory>
|
|
|
|
#define PL_UI_STATE_INACTIVE 0
|
|
#define PL_UI_STATE_CHARGING 1
|
|
#define PL_UI_STATE_USE_SOLAR_ONLY 2
|
|
#define PL_UI_STATE_USE_SOLAR_AND_BATTERY 3
|
|
|
|
#define PL_MODE_ENABLE_NORMAL_OP 0
|
|
#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
|
|
} batDrainStrategy;
|
|
|
|
|
|
class PowerLimiterClass {
|
|
public:
|
|
void init();
|
|
void loop();
|
|
uint8_t getPowerLimiterState();
|
|
int32_t getLastRequestedPowewrLimit();
|
|
void setMode(uint8_t mode);
|
|
bool getMode();
|
|
void calcNextInverterRestart();
|
|
|
|
private:
|
|
uint32_t _lastLoop = 0;
|
|
int32_t _lastRequestedPowerLimit = 0;
|
|
uint32_t _lastLimitSetTime = 0;
|
|
plStates _plState;
|
|
uint8_t _mode = PL_MODE_ENABLE_NORMAL_OP;
|
|
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;
|
|
|
|
bool canUseDirectSolarPower();
|
|
int32_t calcPowerLimit(std::shared_ptr<InverterAbstract> inverter, bool solarPowerEnabled, bool batteryDischargeEnabled);
|
|
void 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);
|
|
bool isStopThresholdReached(std::shared_ptr<InverterAbstract> inverter);
|
|
bool useFullSolarPassthrough(std::shared_ptr<InverterAbstract> inverter);
|
|
};
|
|
|
|
extern PowerLimiterClass PowerLimiter;
|