Skip to content

Commit

Permalink
Feature: support for Huawei target power consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteSchm authored Apr 24, 2024
1 parent 74330a5 commit f0df583
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ struct CONFIG_T {
float Auto_Power_Lower_Power_Limit;
float Auto_Power_Upper_Power_Limit;
uint8_t Auto_Power_Stop_BatterySoC_Threshold;
float Auto_Power_Target_Power_Consumption;
} Huawei;


Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@
#define HUAWEI_AUTO_POWER_LOWER_POWER_LIMIT 150
#define HUAWEI_AUTO_POWER_UPPER_POWER_LIMIT 2000
#define HUAWEI_AUTO_POWER_STOP_BATTERYSOC_THRESHOLD 95
#define HUAWEI_AUTO_POWER_TARGET_POWER_CONSUMPTION 0

#define VERBOSE_LOGGING true
2 changes: 2 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ bool ConfigurationClass::write()
huawei["lower_power_limit"] = config.Huawei.Auto_Power_Lower_Power_Limit;
huawei["upper_power_limit"] = config.Huawei.Auto_Power_Upper_Power_Limit;
huawei["stop_batterysoc_threshold"] = config.Huawei.Auto_Power_Stop_BatterySoC_Threshold;
huawei["target_power_consumption"] = config.Huawei.Auto_Power_Target_Power_Consumption;

// Serialize JSON to file
if (serializeJson(doc, f) == 0) {
Expand Down Expand Up @@ -482,6 +483,7 @@ bool ConfigurationClass::read()
config.Huawei.Auto_Power_Lower_Power_Limit = huawei["lower_power_limit"] | HUAWEI_AUTO_POWER_LOWER_POWER_LIMIT;
config.Huawei.Auto_Power_Upper_Power_Limit = huawei["upper_power_limit"] | HUAWEI_AUTO_POWER_UPPER_POWER_LIMIT;
config.Huawei.Auto_Power_Stop_BatterySoC_Threshold = huawei["stop_batterysoc_threshold"] | HUAWEI_AUTO_POWER_STOP_BATTERYSOC_THRESHOLD;
config.Huawei.Auto_Power_Target_Power_Consumption = huawei["target_power_consumption"] | HUAWEI_AUTO_POWER_TARGET_POWER_CONSUMPTION;

f.close();
return true;
Expand Down
7 changes: 5 additions & 2 deletions src/Huawei_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ void HuaweiCanClass::loop()

// Calculate new power limit
float newPowerLimit = -1 * round(PowerMeter.getPowerTotal());
newPowerLimit += _rp.output_power;
float efficiency = (_rp.efficiency > 0.5 ? _rp.efficiency : 1.0);

// Powerlimit is the requested output power + permissable Grid consumption factoring in the efficiency factor
newPowerLimit += _rp.output_power + config.Huawei.Auto_Power_Target_Power_Consumption / efficiency;

if (verboseLogging){
MessageOutput.printf("[HuaweiCanClass::loop] newPowerLimit: %f, output_power: %f \r\n", newPowerLimit, _rp.output_power);
}
Expand Down Expand Up @@ -424,7 +428,6 @@ void HuaweiCanClass::loop()
}

// Calculate output current
float efficiency = (_rp.efficiency > 0.5 ? _rp.efficiency : 1.0);
float calculatedCurrent = efficiency * (newPowerLimit / _rp.output_voltage);

// Limit output current to value requested by BMS
Expand Down
3 changes: 3 additions & 0 deletions src/WebApi_Huawei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void WebApiHuaweiClass::onAdminGet(AsyncWebServerRequest* request)
root["lower_power_limit"] = config.Huawei.Auto_Power_Lower_Power_Limit;
root["upper_power_limit"] = config.Huawei.Auto_Power_Upper_Power_Limit;
root["stop_batterysoc_threshold"] = config.Huawei.Auto_Power_Stop_BatterySoC_Threshold;
root["target_power_consumption"] = config.Huawei.Auto_Power_Target_Power_Consumption;

response->setLength();
request->send(response);
Expand Down Expand Up @@ -266,6 +267,8 @@ void WebApiHuaweiClass::onAdminPost(AsyncWebServerRequest* request)
config.Huawei.Auto_Power_Lower_Power_Limit = root["lower_power_limit"].as<float>();
config.Huawei.Auto_Power_Upper_Power_Limit = root["upper_power_limit"].as<float>();
config.Huawei.Auto_Power_Stop_BatterySoC_Threshold = root["stop_batterysoc_threshold"];
config.Huawei.Auto_Power_Target_Power_Consumption = root["target_power_consumption"];

WebApi.writeConfig(retMsg);

response->setLength();
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,15 @@
"enableVoltageLimit": "Start Spannungslimit",
"stopVoltageLimitHint": "Maximal Spannung des Ladegeräts. Entspricht der geünschten Ladeschlussspannung der Batterie. Verwendet für die Automatische Leistungssteuerung und beim Notfallladen",
"enableVoltageLimitHint": "Die automatische Leistungssteuerung wird deaktiviert wenn die Ausgangsspannung über diesem Wert liegt und wenn gleichzeitig die Ausgangsleistung unter die minimale Leistung fällt.\nDie automatische Leistungssteuerung wird re-aktiveiert wenn die Batteriespannung unter diesen Wert fällt.",
"maxPowerLimitHint": "Maximale Ausgangsleistung. Verwendet für die Automatische Leistungssteuerung und beim Notfallladen",
"upperPowerLimitHint": "Maximale Ausgangsleistung. Verwendet für die Automatische Leistungssteuerung und beim Notfallladen",
"lowerPowerLimit": "Minimale Leistung",
"upperPowerLimit": "Maximale Leistung",
"StopBatterySoCThreshold": "Laden bei SoC beenden",
"StopBatterySoCThresholdHint": "Zur Verlängerung der Akku-Lebensdauer kann der Ladevorgang bei einem bestimmten SoC gestoppt werden.\nHinweis: Manche LiFePO-Akkus müssen gelegentlich voll geladen werden, um die SoC-Anzeige akkurat zu halten.",
"Seconds": "@:base.Seconds",
"EnableEmergencyCharge": "Notfallladen: Batterie wird mit maximaler Leistung geladen wenn durch das Batterie BMS angefordert"
"EnableEmergencyCharge": "Notfallladen: Batterie wird mit maximaler Leistung geladen wenn durch das Batterie BMS angefordert",
"targetPowerConsumption": "Angestrebter Netzbezug",
"targetPowerConsumptionHint": "Bei postiven Werten wird die eingestellte Leistung aus dem Stromnetz bezogen. Bei negativen Werten wird das Netzteil vorzeitig abgeschaltet."
},
"battery": {
"battery": "Batterie",
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -859,13 +859,15 @@
"enableVoltageLimit": "Re-enable voltage limit",
"stopVoltageLimitHint": "Maximum charger voltage. Equals battery charge voltage limit. Used for automatic power control and when emergency charging",
"enableVoltageLimitHint": "Automatic power control is disabled if the output voltage is higher then this value and if the output power drops below the minimum output power limit (set below).\nAutomatic power control is re-enabled if the battery voltage drops below the value set in this field.",
"maxPowerLimitHint": "Maximum output power. Used for automatic power control and when emergency charging",
"upperPowerLimitHint": "Maximum output power. Used for automatic power control and when emergency charging",
"lowerPowerLimit": "Minimum output power",
"upperPowerLimit": "Maximum output power",
"StopBatterySoCThreshold": "Stop charging at SoC",
"StopBatterySoCThresholdHint": "To prolong the battery's lifespan, charging can be stopped at a certain SoC level.\nHint: In order to keep the SoC reading accurate, some LiFePO cells must be charged to full capacity regularly.",
"Seconds": "@:base.Seconds",
"EnableEmergencyCharge": "Emergency charge. Battery charged with maximum power if requested by Battery BMS"
"EnableEmergencyCharge": "Emergency charge. Battery charged with maximum power if requested by Battery BMS",
"targetPowerConsumption": "Target power consumption",
"targetPowerConsumptionHint": "Postitive values use grid power to charge the battery. Negative values result in early shutdown"
},
"battery": {
"battery": "Battery",
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -847,13 +847,15 @@
"enableVoltageLimit": "Re-enable voltage limit",
"stopVoltageLimitHint": "Maximum charger voltage. Equals battery charge voltage limit. Used for automatic power control and when emergency charging",
"enableVoltageLimitHint": "Automatic power control is disabled if the output voltage is higher then this value and if the output power drops below the minimum output power limit (set below).\nAutomatic power control is re-enabled if the battery voltage drops below the value set in this field.",
"maxPowerLimitHint": "Maximum output power. Used for automatic power control and when emergency charging",
"upperPowerLimitHint": "Maximum output power. Used for automatic power control and when emergency charging",
"lowerPowerLimit": "Minimum output power",
"upperPowerLimit": "Maximum output power",
"StopBatterySoCThreshold": "Stop charging at SoC",
"StopBatterySoCThresholdHint": "To prolong the battery's lifespan, charging can be stopped at a certain SoC level.\nHint: In order to keep the SoC reading accurate, some LiFePO cells must be charged to full capacity regularly.",
"Seconds": "@:base.Seconds",
"EnableEmergencyCharge": "Emergency charge. Battery charged with maximum power if requested by Battery BMS"
"EnableEmergencyCharge": "Emergency charge. Battery charged with maximum power if requested by Battery BMS",
"targetPowerConsumption": "Target power consumption",
"targetPowerConsumptionHint": "Postitive values use grid power to charge the battery. Negative values result in early shutdown"
},
"battery": {
"battery": "Battery",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/types/AcChargerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface AcChargerConfig {
upper_power_limit: number;
emergency_charge_enabled: boolean;
stop_batterysoc_threshold: number;
target_power_consumption: number;
}
16 changes: 14 additions & 2 deletions webapp/src/views/AcChargerAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,28 @@
</div>
</div>
<label for="upperPowerLimit" class="col-sm-2 col-form-label">{{ $t('acchargeradmin.upperPowerLimit') }}:
<BIconInfoCircle v-tooltip :title="$t('acchargeradmin.maxPowerLimitHint')" />
<BIconInfoCircle v-tooltip :title="$t('acchargeradmin.upperPowerLimitHint')" />
</label>
<div class="col-sm-10">
<div class="input-group">
<input type="number" class="form-control" id="upperPowerLimit"
placeholder="2000" v-model="acChargerConfigList.upper_power_limit"
aria-describedby="lowerPowerLimitDescription" min="100" max="3000" required/>
aria-describedby="upperPowerLimitDescription" min="100" max="3000" required/>
<span class="input-group-text" id="upperPowerLimitDescription">W</span>
</div>
</div>
<label for="targetPowerConsumption" class="col-sm-2 col-form-label">{{ $t('acchargeradmin.targetPowerConsumption') }}:
<BIconInfoCircle v-tooltip :title="$t('acchargeradmin.targetPowerConsumptionHint')" />
</label>
<div class="col-sm-10">
<div class="input-group">
<input type="number" class="form-control" id="targetPowerConsumption"
placeholder="0" v-model="acChargerConfigList.target_power_consumption"
aria-describedby="targetPowerConsumptionDescription" min="-3000" max="3000" required/>
<span class="input-group-text" id="targetPowerConsumptionDescription">W</span>
</div>
</div>

</div>
</CardElement>
<CardElement :text="$t('acchargeradmin.BatterySoCLimits')" textVariant="text-bg-primary" add-space
Expand Down

0 comments on commit f0df583

Please sign in to comment.