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

Fix DPL nighttime discharging #1126

Merged
merged 3 commits into from
Aug 15, 2024
Merged

Conversation

schlimmchen
Copy link
Member

the switch "always start discharging battery at night" would cause to stop discharging the battery when there was solar power and the battery was discharged below the start threshold.

this change introduces a nighttime discharging boolean variable, which is enabled the instant we decide to start a battery discharge cycle due to nighttime havin arrived. we reset this variable as soon as it is daytime (solar power available). in that case, we allow discharging the battery if the start threshold was reached. this can actually be the case if the battery is charged with cheap electricity during the night.

removed comments as they merely spell out what the if statement already expresses quite nicely.

closes #1123.

the switch "always start discharging battery at night" would cause to
stop discharging the battery when there was solar power and the battery
was discharged below the start threshold.

this change introduces a nighttime discharging boolean variable, which
is enabled the instant we decide to start a battery discharge cycle due
to nighttime havin arrived. we reset this variable as soon as it is
daytime (solar power available). in that case, we allow discharging the
battery if the start threshold was reached. this can actually be the
case if the battery is charged with cheap electricity during the night.

removed comments as they merely spell out what the if statement already
expresses quite nicely.
@schlimmchen
Copy link
Member Author

@greymda, are you able to test the firmware build as part of this PR's build run?

@greymda
Copy link

greymda commented Jul 24, 2024

@schlimmchen is this firmware upgradeable via OTA on a 4MB board? if not, i don't have access physically to the setup and can't write it using a cable :(
the board is still using the "old" partition schema...

@schlimmchen
Copy link
Member Author

is this firmware upgradeable via OTA on a 4MB board?

No.

In the long run, I advise you to upgrade your hardware if you usually don't have physical access to it.

@greymda
Copy link

greymda commented Jul 24, 2024

yep, I am planning to get the ESP32-WROVER-VIE as it has the same pin layout with the one i'm using now on Lukas's board. but it will take a while.

@AndreasBoehm
Copy link
Member

@schlimmchen what do you think about adding this change to use day/night from 'SunPosition' instead of relying on solarPower to detect day/night?

diff --git a/src/PowerLimiter.cpp b/src/PowerLimiter.cpp
index 58e8713a..c2ad86f9 100644
--- a/src/PowerLimiter.cpp
+++ b/src/PowerLimiter.cpp
@@ -17,6 +17,7 @@
 #include <ctime>
 #include <cmath>
 #include <frozen/map.h>
+#include "SunPosition.h"

 PowerLimiterClass PowerLimiter;

@@ -239,7 +240,10 @@ void PowerLimiterClass::loop()
     auto getBatteryPower = [this,&config]() -> bool {
         if (config.PowerLimiter.IsInverterSolarPowered) { return false; }

-        if (_nighttimeDischarging && getSolarPower() > 0) {
+        auto isDayPeriod = (SunPosition.isSunsetAvailable() && SunPosition.isDayPeriod())
+            || getSolarPower() > 0;
+
+        if (_nighttimeDischarging && isDayPeriod) {
             _nighttimeDischarging = false;
             return isStartThresholdReached();
         }
@@ -248,12 +252,10 @@ void PowerLimiterClass::loop()

         if (isStartThresholdReached()) { return true; }

-        // TODO(schlimmchen): should be supported by sunrise and sunset, such
-        // that a thunderstorm or other events that drastically lower the solar
-        // power do not cause the start of a discharge cycle during the day.
         if (config.PowerLimiter.SolarPassThroughEnabled &&
                 config.PowerLimiter.BatteryAlwaysUseAtNight &&
-                getSolarPower() == 0 && !_batteryDischargeEnabled) {
+                !isDayPeriod &&
+                !_batteryDischargeEnabled) {
             _nighttimeDischarging = true;
             return true;
         }

@schlimmchen
Copy link
Member Author

yes, please. this is what I had in mind. I was too lazy to do it until now. can you create a PR against this one?

@AndreasBoehm
Copy link
Member

Here you go: #1158

@schlimmchen
Copy link
Member Author

Awesome 🚀

@AndreasBoehm
Copy link
Member

AndreasBoehm commented Aug 8, 2024

I realised that I made a mistake which would still take solarPower into consideration when its night. A new PR fixes this issue: #1160

@AndreasBoehm
Copy link
Member

I finished my battery setup today and installed this PRs build. I will report back after 2 or 3 full days and nights if this now works as expected.

@AndreasBoehm
Copy link
Member

I can confirm that this works as expected

@schlimmchen schlimmchen merged commit 5d1d071 into development Aug 15, 2024
10 checks passed
@schlimmchen schlimmchen deleted the dpl-fix-nighttime-discharging branch August 15, 2024 18:10
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion or issue for related concerns.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants