Skip to content

Commit

Permalink
Add SoC threshold for battery current limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ranma committed Sep 28, 2024
1 parent aa159fd commit 53070c8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
#define BATTERY_JKBMS_POLLING_INTERVAL 5
#define BATTERY_ENABLE_DISCHARGE_CURRENT_LIMIT false
#define BATTERY_DISCHARGE_CURRENT_LIMIT 0
#define BATTERY_DISCHARGE_CURRENT_LIMIT_BELOW_SOC 100
#define BATTERY_USE_BATTERY_REPORTED_DISCHARGE_CURRENT_LIMIT false

#define HUAWEI_ENABLED false
Expand Down
7 changes: 7 additions & 0 deletions src/Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<b>Hinweis:</b> 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",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<b>Hint:</b> 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",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/types/BatteryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/views/BatteryAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@
postfix="A"
/>

<InputElement
:label="$t('batteryadmin.DischargeCurrentLimitBelowSoc')"
v-model="batteryConfigList.discharge_current_limit_below_soc"
type="number"
min="0"
max="100"
step="0.1"
postfix="%"
/>

<InputElement
:label="$t('batteryadmin.UseBatteryReportedDischargeCurrentLimit')"
v-model="batteryConfigList.use_battery_reported_discharge_current_limit"
Expand Down

0 comments on commit 53070c8

Please sign in to comment.