From 242613d918db9e1a949222465a062e8fadc07113 Mon Sep 17 00:00:00 2001 From: Tobias Diedrich Date: Sat, 28 Sep 2024 16:40:34 +0200 Subject: [PATCH] Add SoC threshold for battery current limit. --- include/Configuration.h | 1 + include/defaults.h | 1 + src/Battery.cpp | 7 +++++++ src/Configuration.cpp | 2 ++ webapp/src/locales/de.json | 1 + webapp/src/locales/en.json | 1 + webapp/src/types/BatteryConfig.ts | 1 + webapp/src/views/BatteryAdminView.vue | 10 ++++++++++ 8 files changed, 24 insertions(+) diff --git a/include/Configuration.h b/include/Configuration.h index 3b99c38bb..d741ffe25 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -145,6 +145,7 @@ struct BATTERY_CONFIG_T { BatteryVoltageUnit MqttVoltageUnit; bool EnableDischargeCurrentLimit; float DischargeCurrentLimit; + float DischargeCurrentLimitBelowSoc; bool UseBatteryReportedDischargeCurrentLimit; char MqttDischargeCurrentTopic[MQTT_MAX_TOPIC_STRLEN + 1]; char MqttDischargeCurrentJsonPath[BATTERY_JSON_MAX_PATH_STRLEN + 1]; diff --git a/include/defaults.h b/include/defaults.h index 2ab8ec9e8..53058128a 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -156,6 +156,7 @@ #define BATTERY_JKBMS_POLLING_INTERVAL 5 #define BATTERY_ENABLE_DISCHARGE_CURRENT_LIMIT false #define BATTERY_DISCHARGE_CURRENT_LIMIT 0.0 +#define BATTERY_DISCHARGE_CURRENT_LIMIT_BELOW_SOC 100.0 #define BATTERY_USE_BATTERY_REPORTED_DISCHARGE_CURRENT_LIMIT false #define HUAWEI_ENABLED false diff --git a/src/Battery.cpp b/src/Battery.cpp index e10abb1fa..842603fdf 100644 --- a/src/Battery.cpp +++ b/src/Battery.cpp @@ -91,8 +91,15 @@ float BatteryClass::getDischargeCurrentLimit() if (!config.Battery.EnableDischargeCurrentLimit) { return FLT_MAX; } auto dischargeCurrentLimit = config.Battery.DischargeCurrentLimit; + auto dischargeCurrentLimitBelowSoc = config.Battery.DischargeCurrentLimitBelowSoc; auto dischargeCurrentValid = dischargeCurrentLimit > 0.0f; + auto statsSoC = getStats()->getSoC(); + auto statsSoCValid = getStats()->getSoCAgeSeconds() <= 60; + if (statsSoCValid && statsSoC > dischargeCurrentLimitBelowSoc) { + dischargeCurrentValid = false; + } + auto statsCurrentLimit = getStats()->getDischargeCurrentLimit(); auto statsLimitValid = config.Battery.UseBatteryReportedDischargeCurrentLimit && statsCurrentLimit >= 0.0f diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 61ee7758d..6a55c9e69 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -88,6 +88,7 @@ void ConfigurationClass::serializeBatteryConfig(BatteryConfig const& source, Jso target["mqtt_voltage_unit"] = config.Battery.MqttVoltageUnit; target["enable_discharge_current_limit"] = config.Battery.EnableDischargeCurrentLimit; target["discharge_current_limit"] = config.Battery.DischargeCurrentLimit; + target["discharge_current_limit_below_soc"] = config.Battery.DischargeCurrentLimitBelowSoc; target["use_battery_reported_discharge_current_limit"] = config.Battery.UseBatteryReportedDischargeCurrentLimit; target["mqtt_discharge_current_topic"] = config.Battery.MqttDischargeCurrentTopic; target["mqtt_discharge_current_json_path"] = config.Battery.MqttDischargeCurrentJsonPath; @@ -383,6 +384,7 @@ void ConfigurationClass::deserializeBatteryConfig(JsonObject const& source, Batt target.MqttVoltageUnit = source["mqtt_voltage_unit"] | BatteryVoltageUnit::Volts; target.EnableDischargeCurrentLimit = source["enable_discharge_current_limit"] | BATTERY_ENABLE_DISCHARGE_CURRENT_LIMIT; target.DischargeCurrentLimit = source["discharge_current_limit"] | BATTERY_DISCHARGE_CURRENT_LIMIT; + target.DischargeCurrentLimitBelowSoc = source["discharge_current_limit_below_soc"] | BATTERY_DISCHARGE_CURRENT_LIMIT_BELOW_SOC; target.UseBatteryReportedDischargeCurrentLimit = source["use_battery_reported_discharge_current_limit"] | BATTERY_USE_BATTERY_REPORTED_DISCHARGE_CURRENT_LIMIT; strlcpy(target.MqttDischargeCurrentTopic, source["mqtt_discharge_current_topic"] | "", sizeof(config.Battery.MqttDischargeCurrentTopic)); strlcpy(target.MqttDischargeCurrentJsonPath, source["mqtt_discharge_current_json_path"] | "", sizeof(config.Battery.MqttDischargeCurrentJsonPath)); diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index 140b18b0d..9446c5040 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -701,6 +701,7 @@ "DischargeCurrentLimitConfiguration": "Einstellungen Entladestromlimit", "LimitDischargeCurrent": "Entladestrom limitieren", "DischargeCurrentLimit": "max. Entladestrom", + "DischargeCurrentLimitBelowSoc": "Limitieren unter SoC", "UseBatteryReportedDischargeCurrentLimit": "Von der Batterie übermitteltes Limit verwenden", "BatteryReportedDischargeCurrentLimitInfo": "Hinweis: Das niedrigste Limit wird angewendet, wobei das von der Batterie übermittelte Entladestromlimit nur verwendet wird, wenn in der letzten Minute ein Update eingegangen ist; andernfalls dient das zuvor festgelegte Limit als Fallback.", "MqttDischargeCurrentTopic": "Topic für Entladestromlimit", diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index 9d1bebedc..d0370c774 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -704,6 +704,7 @@ "DischargeCurrentLimitConfiguration": "Discharge Current Limit Settings", "LimitDischargeCurrent": "Limit Discharge Current", "DischargeCurrentLimit": "max. Discharge Current", + "DischargeCurrentLimitBelowSoc": "Apply limit below SoC", "UseBatteryReportedDischargeCurrentLimit": "Use Battery-Reported limit", "BatteryReportedDischargeCurrentLimitInfo": "Hint: The lowest limit will be applied, with the battery-reported discharge current limit used only if an update was received in the last minute; otherwise, the previously specified limit will act as a fallback.", "MqttDischargeCurrentTopic": "Discharge Current Limit Value Topic", diff --git a/webapp/src/types/BatteryConfig.ts b/webapp/src/types/BatteryConfig.ts index a781b74a0..d546c6a20 100644 --- a/webapp/src/types/BatteryConfig.ts +++ b/webapp/src/types/BatteryConfig.ts @@ -11,6 +11,7 @@ export interface BatteryConfig { mqtt_voltage_unit: number; enable_discharge_current_limit: boolean; discharge_current_limit: number; + discharge_current_limit_below_soc: number; use_battery_reported_discharge_current_limit: boolean; mqtt_discharge_current_topic: string; mqtt_discharge_current_json_path: string; diff --git a/webapp/src/views/BatteryAdminView.vue b/webapp/src/views/BatteryAdminView.vue index 4a07357c7..00dc492a7 100644 --- a/webapp/src/views/BatteryAdminView.vue +++ b/webapp/src/views/BatteryAdminView.vue @@ -141,6 +141,16 @@ postfix="A" /> + +