diff --git a/app/control.js b/app/control.js index f7668ac..d0ddcc1 100644 --- a/app/control.js +++ b/app/control.js @@ -149,8 +149,9 @@ function determinSwitchStatusByGridUsage(currentStatusValues, onStatusFunction, // check if enough solar power is available //console.log(new Date(), "Current status values", currentStatusValues) if (currentStatusValues.wattGridUsageLast < CONFIG.wattThresholdToSwitchOff && currentStatusValues.switchOn && - Math.abs(currentStatusValues.wattGridUsageLast) >= CONFIG.wattThresholdToSwitchOff) { - // as long some energy is feed in keep it on + // shift the feed in energy by the watt threshold for switching off + Math.abs(currentStatusValues.wattGridUsageLast - CONFIG.wattThresholdToSwitchOff) >= 0) { + // as long as engergy usage is within defined limits (feed in or maybe low consumption) keep on return onStatusFunction(currentStatusValues); } else if (currentStatusValues.wattGridUsageLast < CONFIG.wattThresholdToSwitchOff && !currentStatusValues.switchOn && Math.abs(currentStatusValues.wattGridUsageLast) >= CONFIG.wattThresholdToSwitchOn && diff --git a/test/control.test.js b/test/control.test.js index b422453..ad448c9 100644 --- a/test/control.test.js +++ b/test/control.test.js @@ -119,6 +119,17 @@ assertMeanLast(excessEnergyUnderThreshold + CONFIG.wattThresholdToSwitchOn, exce assertMeanLast(excessEnergyUnderThreshold + CONFIG.wattThresholdToSwitchOn*2, excessEnergyUnderThreshold + CONFIG.wattThresholdToSwitchOn*2, CONFIG.maxWaterTemperatureFallback - 1, SWITCH_STATUS.OFF_FORECAST, true, CONFIG.wattThresholdToSwitchOn - 10, new Date("2023-08-29T11:00:00Z")) assertMeanLast(excessEnergyUnderThreshold + CONFIG.wattThresholdToSwitchOn*2, excessEnergyUnderThreshold + CONFIG.wattThresholdToSwitchOn*2, CONFIG.maxWaterTemperatureFallback - CONFIG.maxWaterTemperatureDelta- 1, SWITCH_STATUS.OFF_FORECAST, true, CONFIG.wattThresholdToSwitchOn - 10, new Date("2023-08-29T11:00:00Z")) +// check modified CONFIG.wattThresholdToSwitchOff value +CONFIG.wattThresholdToSwitchOff=100 +assertMeanLast(excessEnergyOverThreshold, -101, minWaterTemperature +1, SWITCH_STATUS.ON_ENERGY, true) +assertMeanLast(excessEnergyOverThreshold, 99, minWaterTemperature +1, SWITCH_STATUS.ON_ENERGY, true) +assertMeanLast(excessEnergyOverThreshold, 100, minWaterTemperature +1, SWITCH_STATUS.OFF_LOW_ENERGY, true) + +assertMeanLast(excessEnergyOverThreshold, 100, minWaterTemperature +1, SWITCH_STATUS.OFF_LOW_ENERGY, false) +assertMeanLast(excessEnergyOverThreshold, 99, minWaterTemperature +1, SWITCH_STATUS.OFF_LOW_ENERGY, false) +assertMeanLast(excessEnergyOverThreshold, excessEnergyOverThreshold, minWaterTemperature +1, SWITCH_STATUS.ON_ENERGY, false) + +CONFIG.wattThresholdToSwitchOff=0 // fallback to always off CONFIG.startHourFallback = 24