Skip to content

Commit

Permalink
fixed bug for keeping on swithc when CONFIG.wattThresholdToSwitchOff …
Browse files Browse the repository at this point in the history
…!= 0
  • Loading branch information
chpro committed Jan 2, 2024
1 parent b28e228 commit a9f889b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
11 changes: 11 additions & 0 deletions test/control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9f889b

Please sign in to comment.