Skip to content

Commit

Permalink
Feature: SmartShunt: process midpoint voltage and deviation
Browse files Browse the repository at this point in the history
  • Loading branch information
swingstate authored and schlimmchen committed May 31, 2024
1 parent 63370e8 commit 561f4be
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class VictronSmartShuntStats : public BatteryStats {
float _dischargedEnergy;
String _modelName;
int32_t _instantaneousPower;
float _midpointVoltage;
float _midpointDeviation;
float _consumedAmpHours;
int32_t _lastFullCharge;

Expand Down
2 changes: 2 additions & 0 deletions lib/VeDirectFrameHandler/VeDirectData.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ struct veShuntStruct : veStruct {
int32_t H16; // Maximum auxiliary (battery) voltage
int32_t H17; // Amount of discharged energy
int32_t H18; // Amount of charged energy
int32_t VM; // Mid-point voltage of the battery bank
int32_t DM; // Mid-point deviation of the battery bank
int8_t dcMonitorMode_MON; // DC monitor mode
};

Expand Down
8 changes: 8 additions & 0 deletions lib/VeDirectFrameHandler/VeDirectShuntController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ bool VeDirectShuntController::processTextDataDerived(std::string const& name, st
_tmpFrame.H17 = atoi(value.c_str());
return true;
}
if (name == "VM") {
_tmpFrame.VM = atoi(value.c_str());
return true;
}
if (name == "DM") {
_tmpFrame.DM = atoi(value.c_str());
return true;
}
if (name == "H18") {
_tmpFrame.H18 = atoi(value.c_str());
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ void VictronSmartShuntStats::updateFrom(VeDirectShuntController::data_t const& s
_manufacturer = "Victron " + _modelName;
_temperature = shuntData.T;
_tempPresent = shuntData.tempPresent;
_midpointVoltage = static_cast<float>(shuntData.VM) / 1000;
_midpointDeviation = static_cast<float>(shuntData.DM) / 10;
_instantaneousPower = shuntData.P;
_consumedAmpHours = static_cast<float>(shuntData.CE) / 1000;
_lastFullCharge = shuntData.H9 / 60;
Expand All @@ -414,6 +416,8 @@ void VictronSmartShuntStats::getLiveViewData(JsonVariant& root) const {
addLiveViewValue(root, "dischargedEnergy", _dischargedEnergy, "kWh", 2);
addLiveViewValue(root, "instantaneousPower", _instantaneousPower, "W", 0);
addLiveViewValue(root, "consumedAmpHours", _consumedAmpHours, "Ah", 3);
addLiveViewValue(root, "midpointVoltage", _midpointVoltage, "V", 2);
addLiveViewValue(root, "midpointDeviation", _midpointDeviation, "%", 1);
addLiveViewValue(root, "lastFullCharge", _lastFullCharge, "min", 0);
if (_tempPresent) {
addLiveViewValue(root, "temperature", _temperature, "°C", 0);
Expand All @@ -436,4 +440,6 @@ void VictronSmartShuntStats::mqttPublish() const {
MqttSettings.publish("battery/instantaneousPower", String(_instantaneousPower));
MqttSettings.publish("battery/consumedAmpHours", String(_consumedAmpHours));
MqttSettings.publish("battery/lastFullCharge", String(_lastFullCharge));
MqttSettings.publish("battery/midpointVoltage", String(_midpointVoltage));
MqttSettings.publish("battery/midpointDeviation", String(_midpointDeviation));
}
2 changes: 2 additions & 0 deletions src/MqttHandleBatteryHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void MqttHandleBatteryHassClass::loop()
publishSensor("Charge Cycles", "mdi:counter", "chargeCycles");
publishSensor("Consumed Amp Hours", NULL, "consumedAmpHours", NULL, "measurement", "Ah");
publishSensor("Last Full Charge", "mdi:timelapse", "lastFullCharge", NULL, NULL, "min");
publishSensor("Midpoint Voltage", NULL, "midpointVoltage", "voltage", "measurement", "V");
publishSensor("Midpoint Deviation", NULL, "midpointDeviation", "battery", "measurement", "%");
break;
}

Expand Down
2 changes: 2 additions & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@
"dischargedEnergy": "Entladene Energie",
"instantaneousPower": "Aktuelle Leistung",
"consumedAmpHours": "Verbrauchte Amperestunden",
"midpointVoltage": "Mittelpunktspannung",
"midpointDeviation": "Mittelpunktsabweichung",
"lastFullCharge": "Letztes mal Vollgeladen"
}
}
2 changes: 2 additions & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,8 @@
"dischargedEnergy": "Discharged energy",
"instantaneousPower": "Instantaneous Power",
"consumedAmpHours": "Consumed Amp Hours",
"midpointVoltage": "Midpoint Voltage",
"midpointDeviation": "Midpoint Deviation",
"lastFullCharge": "Last full Charge"
}
}
2 changes: 2 additions & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@
"dischargedEnergy": "Discharged energy",
"instantaneousPower": "Instantaneous Power",
"consumedAmpHours": "Consumed Amp Hours",
"midpointVoltage": "Midpoint Voltage",
"midpointDeviation": "Midpoint Deviation",
"lastFullCharge": "Last full Charge"
}
}

0 comments on commit 561f4be

Please sign in to comment.