Skip to content

Commit

Permalink
added configuration option to set static output limit
Browse files Browse the repository at this point in the history
  • Loading branch information
vaterlangen committed Sep 26, 2024
1 parent a7aa5e3 commit cc601d2
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ struct BATTERY_CONFIG_T {
uint16_t ZendureMaxOutput;
bool ZendureAutoShutdown;
bool ZendureForceLimit;
uint16_t ZendureOutputLimit;
};
using BatteryConfig = struct BATTERY_CONFIG_T;

Expand Down
1 change: 1 addition & 0 deletions include/ZendureBattery.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ZendureBattery : public BatteryProvider {
protected:
void timesync();
static String parseVersion(uint32_t version);
uint16_t calcOutputLimit(uint16_t limit);

private:
void calculateEfficiency();
Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
#define BATTERY_ZENDURE_MAX_OUTPUT 800
#define BATTERY_ZENDURE_AUTO_SHUTDOWN 1
#define BATTERY_ZENDURE_FORCE_LIMIT 0
#define BATTERY_ZENDURE_OUTPUT_LIMIT BATTERY_ZENDURE_MAX_OUTPUT

#define HUAWEI_ENABLED false
#define HUAWEI_CAN_CONTROLLER_FREQUENCY 8000000UL
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void ConfigurationClass::serializeBatteryConfig(BatteryConfig const& source, Jso
target["zendure_max_output"] = config.Battery.ZendureMaxOutput;
target["zendure_auto_shutdown"] = config.Battery.ZendureAutoShutdown;
target["zendure_force_limit"] = config.Battery.ZendureForceLimit;
target["zendure_output_limit"] = config.Battery.ZendureOutputLimit;
}

bool ConfigurationClass::write()
Expand Down Expand Up @@ -400,6 +401,7 @@ void ConfigurationClass::deserializeBatteryConfig(JsonObject const& source, Batt
target.ZendureMaxOutput = source["zendure_max_output"] | BATTERY_ZENDURE_MAX_OUTPUT;
target.ZendureAutoShutdown = source["zendure_auto_shutdown"] | BATTERY_ZENDURE_AUTO_SHUTDOWN;
target.ZendureForceLimit = source["zendure_force_limit"] | BATTERY_ZENDURE_FORCE_LIMIT;
target.ZendureOutputLimit = source["zendure_output_limit"] | BATTERY_ZENDURE_OUTPUT_LIMIT;
}

bool ConfigurationClass::read()
Expand Down
19 changes: 13 additions & 6 deletions src/ZendureBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool ZendureBattery::init(bool verboseLogging)
prop[ZENDURE_REPORT_MAX_SOC] = config.Battery.ZendureMaxSoC * 10;
prop[ZENDURE_REPORT_MIN_SOC] = config.Battery.ZendureMinSoC * 10;
if (config.Battery.ZendureForceLimit){
prop[ZENDURE_REPORT_OUTPUT_LIMIT] = config.Battery.ZendureMaxOutput;
prop[ZENDURE_REPORT_OUTPUT_LIMIT] = calcOutputLimit(min(config.Battery.ZendureMaxOutput, config.Battery.ZendureOutputLimit));
}
prop[ZENDURE_REPORT_INVERSE_MAX_POWER] = config.Battery.ZendureMaxOutput;
prop[ZENDURE_REPORT_SMART_MODE] = 0; // should be disabled
Expand Down Expand Up @@ -196,18 +196,25 @@ void ZendureBattery::loop()
}
}

uint16_t ZendureBattery::calcOutputLimit(uint16_t limit)
{
if (limit >= 100 || limit == 0){
return limit;
}

uint16_t base = limit / 30U;
uint16_t remain = (limit % 30U) / 15U;
return 30 * base + 30 * remain;
}

uint16_t ZendureBattery::setOutputLimit(uint16_t limit)
{
if (_topicWrite.isEmpty()) {
return _stats->_output_limit;
}

if (_stats->_output_limit != limit){
if (limit < 100 && limit != 0){
uint16_t base = limit / 30U;
uint16_t remain = (limit % 30U) / 15U;
limit = 30 * base + 30 * remain;
}
limit = calcOutputLimit(limit);
MqttSettings.publishGeneric(_topicWrite, "{\"properties\": {\"" ZENDURE_REPORT_OUTPUT_LIMIT "\": " + String(limit) + "} }", false, 0);
}

Expand Down
5 changes: 3 additions & 2 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,12 @@
"ZendureBypassModeAutomatic": "Automatisch",
"ZendureBypassModeAlwaysOff": "Dauerhaft Ausgeschaltet",
"ZendureBypassModeAlwaysOn": "Dauerhaft Eingeschaltet",
"ZendureMaxOutput": "Limitierung Ausgangsleistung",
"ZendureMaxOutput": "Wechselrichter Eingangsleistung",
"ZendureAutoShutdown": "Automatisches Herunterfahren",
"ZendureAutoShutdownDescription": "Das Batteriemanagementsystem wird bei Fehlender Ladespannung nach erreichen der unteren Entladegrenze automatisch heruntergefahren",
"ZendureForceLimit": "Ausgangsleistung Vorgeben",
"ZendureForceLimitDescription": "Die angegeben Ausgangsleistung auch als Sollwert vorgeben. ACHTUNG: Damit ist keine dynamisch Steuerung mehr möglich!",
"ZendureForceLimitDescription": "Ausgangsleistung fest vorgeben. ACHTUNG: Damit ist keine dynamisch Steuerung mehr möglich!",
"ZendureOutputLimit": "Ausgangsleistung",
"Percent": "%",
"Watt": "W"
},
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,12 @@
"ZendureBypassModeAutomatic": "Automatic",
"ZendureBypassModeAlwaysOff": "Always Off",
"ZendureBypassModeAlwaysOn": "Always On",
"ZendureMaxOutput": "Maximum output power",
"ZendureMaxOutput": "Inverter input power",
"ZendureAutoShutdown": "Automatic shutdown",
"ZendureAutoShutdownDescription": "If no charge voltage is available, the battery managent system will be shutdown after reaching the minimum charge level",
"ZendureForceLimit": "Force Setpoint",
"ZendureForceLimitDescription": "Also use given output power as setpoint. WARNING: This prevents dynmic control!",
"ZendureForceLimitDescription": "Use fixed output power. WARNING: This prevents dynamic control!",
"ZendureOutputLimit": "Output power",
"Percent": "%",
"Watt": "W"
},
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,12 @@
"ZendureBypassModeAutomatic": "Automatic",
"ZendureBypassModeAlwaysOff": "Always Off",
"ZendureBypassModeAlwaysOn": "Always On",
"ZendureMaxOutput": "Maximum output power",
"ZendureMaxOutput": "Inverter input power",
"ZendureAutoShutdown": "Automatic shutdown",
"ZendureAutoShutdownDescription": "If no charge voltage is available, the battery managent system will be shutdown after reaching the minimum charge level",
"ZendureForceLimit": "Force Setpoint",
"ZendureForceLimitDescription": "Also use given output power as setpoint. WARNING: This prevents dynmic control!",
"ZendureForceLimitDescription": "Use fixed output power. WARNING: This prevents dynamic control!",
"ZendureOutputLimit": "Output power",
"Percent": "%",
"Watt": "W"
},
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 @@ -24,4 +24,5 @@ export interface BatteryConfig {
zendure_max_output: number;
zendure_auto_shutdown: boolean;
zendure_force_limit: boolean;
zendure_output_limit: number;
}
14 changes: 14 additions & 0 deletions webapp/src/views/BatteryAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@
:tooltip="$t('batteryadmin.ZendureForceLimitDescription')"
/>

<InputElement
v-if="batteryConfigList.zendure_force_limit"
:label="$t('batteryadmin.ZendureOutputLimit')"
v-model="batteryConfigList.zendure_output_limit"
type="number"
min="0"
max="1200"
step="1"
:postfix="$t('batteryadmin.Watt')"
/>

<InputElement
:label="$t('batteryadmin.ZendureMinSoc')"
v-model="batteryConfigList.zendure_soc_min"
Expand Down Expand Up @@ -363,6 +374,9 @@ export default defineComponent({
{ key: 1, value: 'AlwaysOff' },
{ key: 2, value: 'AlwaysOn' },
],
//zendureOutputLimitRule: [
// value:number => (value >= 100 || value == 0 || value == 30 || value == 60 || value == 90) || 'Value must be 0,30,60,90 or >= 100'
//],
};
},
created() {
Expand Down

0 comments on commit cc601d2

Please sign in to comment.