Skip to content

Commit

Permalink
Extended Ve.Direct MQTT Details
Browse files Browse the repository at this point in the history
  • Loading branch information
swingstate committed Dec 19, 2023
1 parent fb2ca28 commit 1ab5300
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ platformio-device-monitor*.log
logs/device-monitor*.log
platformio_override.ini
.DS_Store
.DS_Store
14 changes: 9 additions & 5 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,19 @@ class VictronSmartShuntStats : public BatteryStats {
void updateFrom(VeDirectShuntController::veShuntStruct const& shuntData);

private:
float _voltage;
float _current;
float _temperature;
float_t _voltage;
float_t _current;
float_t _temperature;
bool _tempPresent;
uint8_t _chargeCycles;
uint32_t _timeToGo;
float _chargedEnergy;
float _dischargedEnergy;
float_t _chargedEnergy;
float_t _dischargedEnergy;
String _modelName;
float_t _midpointVoltage;
float_t _midpointDeviation;
float_t _instantaneousPower;
float_t _consumedAmpHours;

bool _alarmLowVoltage;
bool _alarmHighVoltage;
Expand Down
6 changes: 6 additions & 0 deletions lib/VeDirectFrameHandler/VeDirectShuntController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ void VeDirectShuntController::textRxEvent(char* name, char* value)
else if (strcmp(name, "H18") == 0) {
_tmpFrame.H18 = atoi(value);
}
else if (strcmp(name, "VM") == 0) {
_tmpFrame.VM = atoi(value);
}
else if (strcmp(name, "DM") == 0) {
_tmpFrame.DM = atoi(value);
}
}

/*
Expand Down
26 changes: 14 additions & 12 deletions lib/VeDirectFrameHandler/VeDirectShuntController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,32 @@ 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
float_t P; // Instantaneous power
float_t CE; // Consumed Amp Hours
float_t SOC; // State-of-charge
uint32_t TTG; // Time-to-go
bool ALARM; // Alarm condition active
uint32_t AR; // Alarm Reason
int32_t H1; // Depth of the deepest discharge
int32_t H2; // Depth of the last discharge
int32_t H3; // Depth of the average discharge
float_t H1; // Depth of the deepest discharge
float_t H2; // Depth of the last discharge
float_t H3; // Depth of the average discharge
int32_t H4; // Number of charge cycles
int32_t H5; // Number of full discharges
int32_t H6; // Cumulative Amp Hours drawn
int32_t H7; // Minimum main (battery) voltage
int32_t H8; // Maximum main (battery) voltage
float_t H7; // Minimum main (battery) voltage
float_t H8; // Maximum main (battery) voltage
int32_t H9; // Number of seconds since last full charge
int32_t H10; // Number of automatic synchronizations
int32_t H11; // Number of low main voltage alarms
int32_t H12; // Number of high main voltage alarms
int32_t H13; // Number of low auxiliary voltage alarms
int32_t H14; // Number of high auxiliary voltage alarms
int32_t H15; // Minimum auxiliary (battery) voltage
int32_t H16; // Maximum auxiliary (battery) voltage
int32_t H17; // Amount of discharged energy
int32_t H18; // Amount of charged energy
float_t H15; // Minimum auxiliary (battery) voltage
float_t H16; // Maximum auxiliary (battery) voltage
float_t H17; // Amount of discharged energy
float_t H18; // Amount of charged energy
float_t VM; // Mid-point voltage of the battery bank
float_t DM; // Mid-point deviation of the battery bank
};

veShuntStruct veFrame{};
Expand Down
15 changes: 12 additions & 3 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void BatteryStats::getLiveViewData(JsonVariant& root) const
root[F("manufacturer")] = _manufacturer;
root[F("data_age")] = getAgeSeconds();

addLiveViewValue(root, "SoC", _SoC, "%", 0);
addLiveViewValue(root, "SoC", _SoC, "%", 1);
}

void PylontechBatteryStats::getLiveViewData(JsonVariant& root) const
Expand Down Expand Up @@ -338,6 +338,10 @@ void VictronSmartShuntStats::updateFrom(VeDirectShuntController::veShuntStruct c
_manufacturer = "Victron " + _modelName;
_temperature = shuntData.T;
_tempPresent = shuntData.tempPresent;
_midpointVoltage = shuntData.VM / 1000;
_midpointDeviation = shuntData.DM;
_instantaneousPower = shuntData.P;
_consumedAmpHours = shuntData.CE / 1000;

// shuntData.AR is a bitfield, so we need to check each bit individually
_alarmLowVoltage = shuntData.AR & 1;
Expand All @@ -357,8 +361,8 @@ void VictronSmartShuntStats::getLiveViewData(JsonVariant& root) const {
addLiveViewValue(root, "voltage", _voltage, "V", 2);
addLiveViewValue(root, "current", _current, "A", 1);
addLiveViewValue(root, "chargeCycles", _chargeCycles, "", 0);
addLiveViewValue(root, "chargedEnergy", _chargedEnergy, "KWh", 1);
addLiveViewValue(root, "dischargedEnergy", _dischargedEnergy, "KWh", 1);
addLiveViewValue(root, "chargedEnergy", _chargedEnergy, "KWh", 2);
addLiveViewValue(root, "dischargedEnergy", _dischargedEnergy, "KWh", 2);
if (_tempPresent) {
addLiveViewValue(root, "temperature", _temperature, "°C", 0);
}
Expand All @@ -378,4 +382,9 @@ 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/midpointVoltage"), String(_midpointVoltage));
MqttSettings.publish(F("battery/midpointDeviation"), String(_midpointDeviation));
MqttSettings.publish(F("battery/instantaneousPower"), String(_instantaneousPower));
MqttSettings.publish(F("battery/consumpedAmpHours"), String(_consumedAmpHours));
}

0 comments on commit 1ab5300

Please sign in to comment.