Skip to content
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

Feature: auto-detect SoC precision for MQTT Battery provider #1449

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

AndreasBoehm
Copy link
Member

@AndreasBoehm AndreasBoehm commented Dec 7, 2024

With this change we will allow users to set the decimal places (or precision) of the SoC when the MQTT Battery Provider is used.

Live View
Screenshot 2024-12-07 at 18 53 43

Console

18:56:32.934 > MqttBattery: Updated SoC to 49.93 from 'solarLights/battery/stateOfCharge'
18:56:33.076 > MqttBattery: Updated voltage to 52.68 from 'solarLights/battery/voltage'
...
18:56:51.454 > [DPL] battery interface enabled, SoC 49.9 % (used), age 3 s (valid)
18:56:51.462 > [DPL] BMS: 52.68 V, MPPT: -1.00 V, inverter 1164a00aaa1f: 52.80 
18:56:51.471 > [DPL] battery voltage 52.68 V, load-corrected voltage 52.68 V @ 0 W, factor 0.00130 1/A

@AndreasBoehm AndreasBoehm changed the title feature: user-defined precision for MQTT battery SoC Feature: user-defined precision for MQTT battery SoC Dec 7, 2024
@schlimmchen
Copy link
Member

Hm... I can see why we need something like this. Should it be a user setting? I think it should not be. Can't we do something like this:

// MqttBattery class member
uint8_t _socPrecision = 0;

onMqttMessageSoC(...) {
    ...
    unsigned factor = 10;
    uint8_t precision = 0;
    while (precision < 2) {
        if (std::floor(*soc * factor) == std::floor(*soc) * factor) { break; }
        ++precision;
        factor *= 10;
    }
    _socPrecision = std::max(_socPrecision, precision);
}

This way the precision would be learned automatically. What do you think?

@AndreasBoehm AndreasBoehm force-pushed the feature/mqtt-batterie-soc-precision branch from df2498a to 3b4874f Compare December 7, 2024 19:27
@AndreasBoehm AndreasBoehm changed the title Feature: user-defined precision for MQTT battery SoC Feature: auto-detect SoC precision for MQTT Battery provider Dec 7, 2024
@AndreasBoehm
Copy link
Member Author

Very good idea @schlimmchen. Thanks for providing code, it works perfectly. I adjusted my PR accordingly.

src/MqttBattery.cpp Outdated Show resolved Hide resolved
@schlimmchen
Copy link
Member

Did you forget to include the change to MqttBattery.h?

@AndreasBoehm AndreasBoehm force-pushed the feature/mqtt-batterie-soc-precision branch 2 times, most recently from c1b11f1 to 01cf2b8 Compare December 7, 2024 19:41
@AndreasBoehm
Copy link
Member Author

Did you forget to include the change to MqttBattery.h?

Yes i did 🙈
Changes pushed.

@AndreasBoehm AndreasBoehm force-pushed the feature/mqtt-batterie-soc-precision branch from 01cf2b8 to bb59ca6 Compare December 7, 2024 19:44
@schlimmchen schlimmchen merged commit a37b012 into development Dec 7, 2024
12 checks passed
@schlimmchen schlimmchen deleted the feature/mqtt-batterie-soc-precision branch December 7, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants