New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced MQTT Data for Serial Battery Configuration #573
base: development
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing and congrats to your first pull request 🚀 Please have a look at my review comments.
.DS_Store
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file from the changeset (edit the commit that added the file and do not add the file).
.gitignore
Outdated
@@ -8,3 +8,4 @@ platformio-device-monitor*.log | |||
logs/device-monitor*.log | |||
platformio_override.ini | |||
.DS_Store | |||
.DS_Store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is a duplicate. There should be no change to the .gitignore file.
lib/.DS_Store
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file from the changeset (leave it as is).
lib/Hoymiles/.DS_Store
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file from the changeset (leave it as is).
include/BatteryStats.h
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you changing the float types? I suggest leaving them at float
and using float
for the new member variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked into this again and will revert this change.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You must not change the type of the member variables of this struct. The Shunt never transmits floating point values through the wire. It always transmits integers. And we shall save them as such. This is important, as floating point values are not always interchangable with real integers. Conversion to floating point values (because the integers are tens or hundreds or whatever multiples of a particular unit) happens later (BatteryStats).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, understood. The latter is what I am after, respectively I want to use float since they (from my understanding) provide higher accuracy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will revert the changes here and look into increasing accuracy / BatteryStats separately, once this PR is done.
src/BatteryStats.cpp
Outdated
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too generic. The JK BMS (and maybe the Pylontech as well) do not report tens of percents. I suggest you introduce a protected "SoC resolution" variable in the base class BatteryStats, initialize it to zero, and overwrite it to be 1 in VictronSmartShuntStats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe later, as this goes beyond my skills. I'll revert this one first.
src/BatteryStats.cpp
Outdated
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid adding empty lines like this one.
publishSensor("SmartShunt battery midpoint", NULL, "midpointVoltage", "voltage", "measurement", "V"); | ||
publishSensor("SmartShunt battery midpoint Deviation", NULL, "midpointDeviation", "battery", "measurement", "%"); | ||
publishSensor("SmartShunt Instantaneous Power", NULL, "instantaneousPower", "power", "measurement", "W"); | ||
publishSensor("SmartShunt Consumed AmpHours", NULL, "consumpedAmpHours", "energy", "measurement", "Ah"); | ||
publishSensor("SmartShunt Total Charged Energy", NULL, "chargedEnergy", "energy", "total_increasing", "kWh"); | ||
publishSensor("SmartShunt Total DisCharged Energy", NULL, "dischargedEnergy", "energy", "total_increasing", "kWh"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may leave it like that for now, however, this is not the way forward. You are now publishing "SmartShunt" sensors to HomeAssistent, even if the actual battery is a Pylontech or a JK BMS. This is not yet fixed in general. The whole file needs to be refactored such that only the appropriate sensors are published. Your change makes it worse, though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am aware of this flaw and piggybacking on the Pylontech, since I haven't found any other way to get the sensor published.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I do not agree that this is making things worse as this is just using existing code strategies / structures and extending on it.
@schlimmchen I made couple of adjustments based on your feedback and deleted the .DS files (at least I think I deleted them). Can you please take a look. I merged the last updated from the main repo into my dev and now have 2 onBattery PCBs running with the latest (main + my changes) updates. So far things look good. |
@swingstate This is much better, thanks! This changeset now removes three of those (other) Regarding the issue that you publish your values alongside the Pylontech sensors you wrote:
I disagree. People with Pylonthech batteries would see sensors that don't even show values for their Battery, as they are specific to the SmartShunt. Since you prepared the PR, at least one more thing changed: The use of the "F" macro. That would have to be removed. And you would have to rebase your work onto the current state of the development branch. I finished the Home Assistent integration for the JK BMS in #640. Your work and mine now conflict. However, the work I did will solve the issue with the missing distinction of the battery provider. If you are okay with it, I can offer to help this change along and prepare a respective new PR that is based on #640. I would use the work you did to put it in the right new places and prepare clean commits. I could try to preserve your authorship, however I cannot promise that it will work as I intend. |
the Victron SmartShunt communicates the SoC value in promille. this should be displayed in the web UI accordingly. this is a good excuse to fully move ownership of the SoC value to the BatteryStats base class and add a precision indicator variable. this is required to be set each time a derived class (a battery provider) wants to update the SoC value. the precision is then used when populating the JSON data for the web UI (live view). related to helgeerbe#573.
the Victron SmartShunt communicates the SoC value in promille. this should be displayed in the web UI accordingly. this is a good excuse to fully move ownership of the SoC value to the BatteryStats base class and add a precision indicator variable. this is required to be set each time a derived class (a battery provider) wants to update the SoC value. the precision is then used when populating the JSON data for the web UI (live view). related to helgeerbe#573.
the Victron SmartShunt communicates the SoC value in permille. this should be displayed in the web UI accordingly. this is a good excuse to fully move ownership of the SoC value to the BatteryStats base class and add a precision indicator variable. this is required to be set each time a derived class (a battery provider) wants to update the SoC value. the precision is then used when populating the JSON data for the web UI (live view). related to helgeerbe#573.
the Victron SmartShunt communicates the SoC value in permille. this should be displayed in the web UI accordingly. this is a good excuse to fully move ownership of the SoC value to the BatteryStats base class and add a precision indicator variable. this is required to be set each time a derived class (a battery provider) wants to update the SoC value. the precision is then used when populating the JSON data for the web UI (live view). related to helgeerbe#573.
I will not capacity to finish and test this in the near future. Maybe you @schlimmchen or @LukasK13 can look into this and/or merge this with the effort Lukas is looking into for the MQTT Powerlimiter settings. |
If you need someone to test it (if ready), I could do it. I have a Pylontech battery. |
I'm excited to share my first pull request, which focuses on enriching the MQTT data for batteries in a serial configuration. This enhancement includes not only additional data fields but also improves the decimal accuracy for both live view displayed data and MQTT transmissions.
Changes Made:
New Data Fields for HomeAssistant MQTT Auto Discovery:
Decimal Accuracy Improvement:
To enhance precision, the decimal accuracy for both live view and MQTT-transmitted Smartshunt data has been increased.