Skip to content

Commit

Permalink
use SunPosition.isDayPeriod() to check if its day or night
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm committed Aug 8, 2024
1 parent eac1f5b commit e90b00c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <ctime>
#include <cmath>
#include <frozen/map.h>
#include "SunPosition.h"

PowerLimiterClass PowerLimiter;

Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}
Expand Down

0 comments on commit e90b00c

Please sign in to comment.