From 4f0385285cd0e53f812889daa44179af212fc6fe Mon Sep 17 00:00:00 2001 From: PhilJaro <122352327+PhilJaro@users.noreply.github.com> Date: Sun, 17 Mar 2024 18:31:11 +0100 Subject: [PATCH] add new Victron SmartShunt values to liveView and MQTT (HASS) --- include/BatteryStats.h | 3 +++ src/BatteryStats.cpp | 10 +++++++++- src/MqttHandleBatteryHass.cpp | 8 ++++++++ webapp/src/locales/de.json | 5 ++++- webapp/src/locales/en.json | 5 ++++- webapp/src/locales/fr.json | 7 +++++-- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/BatteryStats.h b/include/BatteryStats.h index 2a1ee4a63..86bfa94d7 100644 --- a/include/BatteryStats.h +++ b/include/BatteryStats.h @@ -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; diff --git a/src/BatteryStats.cpp b/src/BatteryStats.cpp index 5a5c4a6a5..b924f64ae 100644 --- a/src/BatteryStats.cpp +++ b/src/BatteryStats.cpp @@ -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(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; @@ -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); } @@ -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)); } diff --git a/src/MqttHandleBatteryHass.cpp b/src/MqttHandleBatteryHass.cpp index 8dc0b1cf6..96428ea35 100644 --- a/src/MqttHandleBatteryHass.cpp +++ b/src/MqttHandleBatteryHass.cpp @@ -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; } diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index 29523f747..d22194548 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -901,6 +901,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" } } diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index 177d28bc9..5c3a82518 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -908,6 +908,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" } } diff --git a/webapp/src/locales/fr.json b/webapp/src/locales/fr.json index cf8e3a8df..d7077b7d2 100644 --- a/webapp/src/locales/fr.json +++ b/webapp/src/locales/fr.json @@ -816,7 +816,7 @@ "Close": "close", "SetVoltageLimit": "Voltage limit:", "SetCurrentLimit": "Current limit:", - "CurrentLimit": "Current limit:" + "CurrentLimit": "Current limit:" }, "acchargeradmin": { "ChargerSettings": "AC Charger Settings", @@ -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" } }