Skip to content

Commit

Permalink
Show battery temperature when sensor is present (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippsandhaus authored Oct 23, 2023
1 parent c5427de commit 8ba9048
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class VictronSmartShuntStats : public BatteryStats {
float _voltage;
float _current;
float _temperature;
bool _tempPresent;
uint8_t _chargeCycles;
uint32_t _timeToGo;
float _chargedEnergy;
Expand Down
1 change: 1 addition & 0 deletions lib/VeDirectFrameHandler/VeDirectShuntController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void VeDirectShuntController::textRxEvent(char* name, char* value)

if (strcmp(name, "T") == 0) {
_tmpFrame.T = atoi(value);
_tmpFrame.tempPresent = true;
}
else if (strcmp(name, "P") == 0) {
_tmpFrame.P = atoi(value);
Expand Down
1 change: 1 addition & 0 deletions lib/VeDirectFrameHandler/VeDirectShuntController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class VeDirectShuntController : public VeDirectFrameHandler {

struct veShuntStruct : veStruct {
int32_t T; // Battery temperature
bool tempPresent = false; // Battery temperature sensor is attached to the shunt
int32_t P; // Instantaneous power
int32_t CE; // Consumed Amp Hours
int32_t SOC; // State-of-charge
Expand Down
5 changes: 5 additions & 0 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ void VictronSmartShuntStats::updateFrom(VeDirectShuntController::veShuntStruct c
_chargedEnergy = shuntData.H18 / 100;
_dischargedEnergy = shuntData.H17 / 100;
_manufacturer = "Victron " + _modelName;
_temperature = shuntData.T;
_tempPresent = shuntData.tempPresent;

// shuntData.AR is a bitfield, so we need to check each bit individually
_alarmLowVoltage = shuntData.AR & 1;
Expand All @@ -235,6 +237,9 @@ void VictronSmartShuntStats::getLiveViewData(JsonVariant& root) const {
addLiveViewValue(root, "chargeCycles", _chargeCycles, "", 0);
addLiveViewValue(root, "chargedEnergy", _chargedEnergy, "KWh", 1);
addLiveViewValue(root, "dischargedEnergy", _dischargedEnergy, "KWh", 1);
if (_tempPresent) {
addLiveViewValue(root, "temperature", _temperature, "°C", 0);
}

addLiveViewAlarm(root, "lowVoltage", _alarmLowVoltage);
addLiveViewAlarm(root, "highVoltage", _alarmHighVoltage);
Expand Down

0 comments on commit 8ba9048

Please sign in to comment.