Skip to content

Commit

Permalink
add new Victron SmartShunt values to liveView and MQTT (HASS)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJaro authored and schlimmchen committed Mar 17, 2024
1 parent 9003267 commit bcee6cf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
3 changes: 3 additions & 0 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class VictronSmartShuntStats : public BatteryStats {
float _chargedEnergy;
float _dischargedEnergy;
String _modelName;
int32_t _instantaneousPower;
float _consumedAmpHours;
int32_t _lastFullCharge;

bool _alarmLowVoltage;
bool _alarmHighVoltage;
Expand Down
10 changes: 9 additions & 1 deletion src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ void VictronSmartShuntStats::updateFrom(VeDirectShuntController::veShuntStruct c
_manufacturer = "Victron " + _modelName;
_temperature = shuntData.T;
_tempPresent = shuntData.tempPresent;

_instantaneousPower = shuntData.P;
_consumedAmpHours = static_cast<float>(shuntData.CE) / 1000;
_lastFullCharge = shuntData.H9 / 60;
// shuntData.AR is a bitfield, so we need to check each bit individually
_alarmLowVoltage = shuntData.AR & 1;
_alarmHighVoltage = shuntData.AR & 2;
Expand All @@ -403,6 +405,9 @@ void VictronSmartShuntStats::getLiveViewData(JsonVariant& root) const {
addLiveViewValue(root, "chargeCycles", _chargeCycles, "", 0);
addLiveViewValue(root, "chargedEnergy", _chargedEnergy, "kWh", 2);
addLiveViewValue(root, "dischargedEnergy", _dischargedEnergy, "kWh", 2);
addLiveViewValue(root, "instantaneousPower", _instantaneousPower, "W", 0);
addLiveViewValue(root, "consumedAmpHours", _consumedAmpHours, "Ah", 3);
addLiveViewValue(root, "lastFullCharge", _lastFullCharge, "min", 0);
if (_tempPresent) {
addLiveViewValue(root, "temperature", _temperature, "°C", 0);
}
Expand All @@ -421,4 +426,7 @@ void VictronSmartShuntStats::mqttPublish() const {
MqttSettings.publish(F("battery/chargeCycles"), String(_chargeCycles));
MqttSettings.publish(F("battery/chargedEnergy"), String(_chargedEnergy));
MqttSettings.publish(F("battery/dischargedEnergy"), String(_dischargedEnergy));
MqttSettings.publish(F("battery/instantaneousPower"), String(_instantaneousPower));
MqttSettings.publish(F("battery/consumedAmpHours"), String(_consumedAmpHours));
MqttSettings.publish(F("battery/lastFullCharge"), String(_lastFullCharge));
}
8 changes: 8 additions & 0 deletions src/MqttHandleBatteryHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ void MqttHandleBatteryHassClass::loop()
case 2: // SoC from MQTT
break;
case 3: // Victron SmartShunt
publishSensor("Voltage", "mdi:battery-charging", "voltage", "voltage", "measurement", "V");
publishSensor("Current", "mdi:current-dc", "current", "current", "measurement", "A");
publishSensor("Instantaneous Power", NULL, "instantaneousPower", "power", "measurement", "W");
publishSensor("Charged Energy", NULL, "chargedEnergy", "energy", "total_increasing", "kWh");
publishSensor("Discharged Energy", NULL, "dischargedEnergy", "energy", "total_increasing", "kWh");
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");
break;
}

Expand Down
7 changes: 5 additions & 2 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@
"Close": "Schließen",
"SetVoltageLimit": "Spannungslimit:",
"SetCurrentLimit": "Stromlimit:",
"CurrentLimit": "Aktuelles Limit: "
"CurrentLimit": "Aktuelles Limit: "
},
"acchargeradmin": {
"ChargerSettings": "AC Ladegerät Einstellungen",
Expand Down Expand Up @@ -900,6 +900,9 @@
"bmsInternal": "BMS intern",
"chargeCycles": "Ladezyklen",
"chargedEnergy": "Geladene Energie",
"dischargedEnergy": "Entladene Energie"
"dischargedEnergy": "Entladene Energie",
"instantaneousPower": "Aktuelle Leistung",
"consumedAmpHours": "Verbrauche Amperestunden",
"lastFullCharge": "Letztes mal Vollgeladen"
}
}
7 changes: 5 additions & 2 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@
"Close": "close",
"SetVoltageLimit": "Voltage limit:",
"SetCurrentLimit": "Current limit:",
"CurrentLimit": "Current limit:"
"CurrentLimit": "Current limit:"
},
"acchargeradmin": {
"ChargerSettings": "AC Charger Settings",
Expand Down Expand Up @@ -907,6 +907,9 @@
"bmsInternal": "BMS internal",
"chargeCycles": "Charge cycles",
"chargedEnergy": "Charged energy",
"dischargedEnergy": "Discharged energy"
"dischargedEnergy": "Discharged energy",
"instantaneousPower": "Instantaneous Power",
"consumedAmpHours": "Consumed Amp Hours",
"lastFullCharge": "Last full Charge"
}
}
7 changes: 5 additions & 2 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@
"Close": "close",
"SetVoltageLimit": "Voltage limit:",
"SetCurrentLimit": "Current limit:",
"CurrentLimit": "Current limit:"
"CurrentLimit": "Current limit:"
},
"acchargeradmin": {
"ChargerSettings": "AC Charger Settings",
Expand Down Expand Up @@ -899,6 +899,9 @@
"bmsInternal": "BMS internal",
"chargeCycles": "Charge cycles",
"chargedEnergy": "Charged energy",
"dischargedEnergy": "Discharged energy"
"dischargedEnergy": "Discharged energy",
"instantaneousPower": "Instantaneous Power",
"consumedAmpHours": "Consumed Amp Hours",
"lastFullCharge": "Last full Charge"
}
}

0 comments on commit bcee6cf

Please sign in to comment.