From 7b40650b59f392f1d2cdc7a3b0433d7a731777e5 Mon Sep 17 00:00:00 2001 From: steff393 Date: Sat, 20 May 2023 22:04:59 +0200 Subject: [PATCH] Add cfgPvMinTime for a minimum charging time --- src/globalConfig.cpp | 8 +++++--- src/globalConfig.h | 5 +++-- src/pvAlgo.cpp | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/globalConfig.cpp b/src/globalConfig.cpp index 1f8bd41..a11097c 100644 --- a/src/globalConfig.cpp +++ b/src/globalConfig.cpp @@ -39,8 +39,9 @@ uint8_t cfgPvLimStart; // PV charging: Target current needed for uint8_t cfgPvLimStop; // PV charging: Target current to stop charging when below (in 0.1A) uint8_t cfgPvPhFactor; // PV charging: Power/Current factor, e.g. 69: 1A equals 690W at 3phases, 23: 1A equals 230W at 1phase uint16_t cfgPvOffset; // PV charging: Offset for the available power calculation (in W); can be used to assure that no/less current is consumed from net -uint8_t cfgPvInvert; // Invert the watt value (pos./neg.) -uint16_t cfgTotalCurrMax; // Total current limit for load management (in 0.1A) +uint8_t cfgPvInvert; // PV charging: Invert the watt value (pos./neg.) +uint8_t cfgPvMinTime; // PV charging: Minimum activation time (in minutes), 0 to disable +uint16_t cfgTotalCurrMax; // Total current limit for load management (in 0.1A) - !! Additional fuse mandatory !! uint8_t cfgHwVersion; // Selection of the used HW uint8_t cfgWifiSleepMode; // Set sleep type for power saving, recomendation is 255 (=no influence) or 0 (=WIFI_NONE_SLEEP) uint8_t cfgLoopDelay; // Delay [ms] at end of main loop, might have an impact on web server reactivitiy, default: 255 = inactive @@ -146,7 +147,8 @@ void loadConfig() { cfgPvLimStop = doc["cfgPvLimStop"] | 50; cfgPvPhFactor = doc["cfgPvPhFactor"] | 69; cfgPvOffset = doc["cfgPvOffset"] | 0UL; - cfgPvInvert = doc["cfgPvInvert"] | 0UL; + cfgPvInvert = doc["cfgPvInvert"] | 0L; + cfgPvMinTime = doc["cfgPvMinTime"] | 0L; cfgTotalCurrMax = doc["cfgTotalCurrMax"] | 0UL; cfgHwVersion = doc["cfgHwVersion"] | 15; cfgWifiSleepMode = doc["cfgWifiSleepMode"] | 0; diff --git a/src/globalConfig.h b/src/globalConfig.h index e8b101f..9400baf 100644 --- a/src/globalConfig.h +++ b/src/globalConfig.h @@ -50,8 +50,9 @@ extern uint8_t cfgPvLimStart; // PV charging: Target current need extern uint8_t cfgPvLimStop; // PV charging: Target current to stop charging when below (in 0.1A) extern uint8_t cfgPvPhFactor; // PV charging: Power/Current factor, e.g. 69: 1A equals 690W at 3phases, 23: 1A equals 230W at 1phase extern uint16_t cfgPvOffset; // PV charging: Offset for the available power calculation (in W); can be used to assure that no/less current is consumed from net -extern uint8_t cfgPvInvert; // Invert the watt value (pos./neg.) -extern uint16_t cfgTotalCurrMax; // Total current limit for load management (in 0.1A) +extern uint8_t cfgPvInvert; // PV charging: Invert the watt value (pos./neg.) +extern uint8_t cfgPvMinTime; // PV charging: Minimum activation time (in minutes), 0 to disable +extern uint16_t cfgTotalCurrMax; // Total current limit for load management (in 0.1A) - !! Additional fuse mandatory !! extern uint8_t cfgHwVersion; // Selection of the used HW extern uint8_t cfgWifiSleepMode; // Set sleep type for power saving, recomendation is 255 (=no influence) or 0 (=WIFI_NONE_SLEEP) extern uint8_t cfgLoopDelay; // Delay [ms] at end of main loop, might have an impact on web server reactivitiy, default: 255 = inactive diff --git a/src/pvAlgo.cpp b/src/pvAlgo.cpp index ef8b2f2..7000c7f 100644 --- a/src/pvAlgo.cpp +++ b/src/pvAlgo.cpp @@ -18,7 +18,9 @@ const uint8_t m = 11; #define BOXID 0 // only 1 box supported RTCVars rtc; // used to memorize a few global variables over reset (not for cold boot / power on reset) -static uint32_t lastHandleCall = 0; + +static uint32_t lastCall = 0; +static uint32_t lastActivation = 0; // timestamp of the recent switch-on (#71), to avoid to frequent on/off static int32_t watt = 0; // power from powerfox API (neg. = 'Einspeisung', pos. = 'Bezug') static int32_t availPowerPrev = 0; // availPower from previous cycle static pvMode_t pvMode = PV_OFF; @@ -51,7 +53,8 @@ void pvAlgo() { targetCurr = 0; // MIN+PV, don't switch off, but ... - if (pvMode == PV_MIN_PV) { + if ((pvMode == PV_MIN_PV) || + (cfgPvMinTime != 0 && lastActivation != 0 && (millis() - lastActivation < ((uint32_t)cfgPvMinTime) * 60 * 1000))) { // also if MinTime not elapsed (#71) targetCurr = content[BOXID][16]; // ... set minimal current configured in box } } @@ -64,6 +67,11 @@ void pvAlgo() { targetCurr = CURR_ABS_MAX; } } + + if (actualCurr == 0 && targetCurr >= CURR_ABS_MIN) { + // switch on => remember timestamp for cfgPvMinTime (#71) + lastActivation = millis(); + } } else { // no car connected targetCurr = 0; @@ -109,11 +117,11 @@ void pv_setup() { void pv_loop() { - if ((millis() - lastHandleCall < (uint16_t)cfgPvCycleTime * 1000) || // avoid unnecessary frequent calls + if ((millis() - lastCall < (uint16_t)cfgPvCycleTime * 1000) || // avoid unnecessary frequent calls (pvMode == PV_DISABLED)) { return; } - lastHandleCall = millis(); + lastCall = millis(); // Call algo if (pvMode > PV_OFF) { // PV algo active @@ -149,5 +157,5 @@ pvMode_t pv_getMode() { void pv_setMode(pvMode_t val) { pvMode = val; rtc.saveToRTC(); // memorize over reset - lastHandleCall = 0; // make sure to call pv_Algo() in the next pv_loop() call + lastCall = 0; // make sure to call pv_Algo() in the next pv_loop() call }