mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2026-05-18 13:17:21 +02:00
Feature: add VE.Direct "load current" to live view, MQTT, and HASS (#1367)
use label "Virtual load output state" if LOAD=true and IL=false
This commit is contained in:
@@ -22,11 +22,13 @@ void VeDirectMpptController::init(int8_t rx, int8_t tx, Print* msgOut,
|
||||
bool VeDirectMpptController::processTextDataDerived(std::string const& name, std::string const& value)
|
||||
{
|
||||
if (name == "IL") {
|
||||
_tmpFrame.loadCurrent_IL_mA = atol(value.c_str());
|
||||
_tmpFrame.loadCurrent_IL_mA.second = atol(value.c_str());
|
||||
_tmpFrame.loadCurrent_IL_mA.first = millis();
|
||||
return true;
|
||||
}
|
||||
if (name == "LOAD") {
|
||||
_tmpFrame.loadOutputState_LOAD = (value == "ON");
|
||||
_tmpFrame.loadOutputState_LOAD.second = (value == "ON");
|
||||
_tmpFrame.loadOutputState_LOAD.first = millis();
|
||||
return true;
|
||||
}
|
||||
if (name == "CS") {
|
||||
@@ -97,7 +99,8 @@ void VeDirectMpptController::frameValidEvent() {
|
||||
}
|
||||
|
||||
// calculation of the MPPT efficiency
|
||||
float totalPower_W = (_tmpFrame.loadCurrent_IL_mA / 1000.0f + _tmpFrame.batteryCurrent_I_mA / 1000.0f) * _tmpFrame.batteryVoltage_V_mV /1000.0f;
|
||||
float loadCurrent = (_tmpFrame.loadCurrent_IL_mA.first > 0) ? _tmpFrame.loadCurrent_IL_mA.second / 1000.0f : 0.0f;
|
||||
float totalPower_W = (loadCurrent + _tmpFrame.batteryCurrent_I_mA / 1000.0f) * _tmpFrame.batteryVoltage_V_mV / 1000.0f;
|
||||
if (_tmpFrame.panelPower_PPV_W > 0) {
|
||||
_efficiency.addNumber(totalPower_W * 100.0f / _tmpFrame.panelPower_PPV_W);
|
||||
_tmpFrame.mpptEfficiency_Percent = _efficiency.getAverage();
|
||||
@@ -117,16 +120,19 @@ void VeDirectMpptController::loop()
|
||||
// Second we read Text- and HEX-Messages
|
||||
VeDirectFrameHandler::loop();
|
||||
|
||||
// Third we check if HEX-Data is outdated
|
||||
// Note: Room for improvement, longer data valid time for slow changing values?
|
||||
if (!isHexCommandPossible()) { return; }
|
||||
|
||||
auto resetTimestamp = [this](auto& pair) {
|
||||
if (pair.first > 0 && (millis() - pair.first) > (10 * 1000)) {
|
||||
pair.first = 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Check if optional TEXT-Data is outdated
|
||||
resetTimestamp(_tmpFrame.loadOutputState_LOAD);
|
||||
resetTimestamp(_tmpFrame.loadCurrent_IL_mA);
|
||||
|
||||
// Third we check if HEX-Data is outdated
|
||||
if (!isHexCommandPossible()) { return; }
|
||||
resetTimestamp(_tmpFrame.MpptTemperatureMilliCelsius);
|
||||
resetTimestamp(_tmpFrame.SmartBatterySenseTemperatureMilliCelsius);
|
||||
resetTimestamp(_tmpFrame.NetworkTotalDcInputPowerMilliWatts);
|
||||
@@ -337,4 +343,4 @@ void VeDirectMpptController::sendNextHexCommandFromQueue(void) {
|
||||
prio = false; // second loop for low prio commands
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user