diff --git a/lib/TWCManager/TWCMaster.py b/lib/TWCManager/TWCMaster.py index 882b31b6..3afb09d8 100644 --- a/lib/TWCManager/TWCMaster.py +++ b/lib/TWCManager/TWCMaster.py @@ -28,6 +28,8 @@ class TWCMaster: consumptionAmpsValues = {} debugOutputToFile = False generationValues = {} + lastMaxAmpsToDivideFromGridTime = 0 + lastMaxAmpsToDivideFromGridValue = 0 lastkWhMessage = time.time() lastkWhPoll = 0 lastSaveFailed = 0 @@ -665,10 +667,12 @@ def getMaxAmpsToDivideGreenEnergy(self): return round(amps, 2) def getMaxAmpsToDivideFromGrid(self): - currentOffer = min( - self.getTotalAmpsInUse(), - self.getMaxAmpsToDivideAmongSlaves(), - ) if self.getTotalAmpsInUse() > 0 else self.getMaxAmpsToDivideAmongSlaves() + # Only recalculate once every 30 seconds to allow things to settle + now = time.time() + if now - self.lastMaxAmpsToDivideFromGridTime < 30: + return round(self.lastMaxAmpsToDivideFromGridValue, 2) + + currentOffer = self.getTotalAmpsInUse() if self.getTotalAmpsInUse() > 0 else self.getMaxAmpsToDivideAmongSlaves() # Get consumptions in Amps, if the EMS source supports it consumptionA = float(self.getConsumptionAmps()) @@ -688,6 +692,10 @@ def getMaxAmpsToDivideFromGrid(self): amps = amps / self.getRealPowerFactor(amps) logger.debug("MaxAmpsToDivideFromGrid: +++++++++++++++: " + str(amps)) + # Update for next call + self.lastMaxAmpsToDivideFromGridTime = now + self.lastMaxAmpsToDivideFromGridValue = amps + return round(amps, 2)