node-red-contrib-heater-controller
node-red-contrib-heater-controller copied to clipboard
hysteresis calculation wrong
from recalculateAndTrigger method
function hysteresis(currentTemp, targetValue, thresholdRising, thresholdFalling) {
var difference = (targetValue - currentTemp);
var newHeaterStatus = (difference < 0 ? "off" : "on");
var threshold = (newHeaterStatus === "off" ? thresholdRising : thresholdFalling);
var changeStatus = (Math.abs(difference) >= threshold);
if (changeStatus) {
return newHeaterStatus;
}
return null;
}
test-case
var targetValue = 22;
var thresholdRising = 1;
var thresholdFalling = 3;
for (let currentTemp = 19; currentTemp < 25; currentTemp++) {
console.log(currentTemp, hysteresis(currentTemp, targetValue, thresholdRising, thresholdFalling));
}
result
19 on test.js:17
20 null test.js:17
21 null test.js:17
22 null test.js:17
23 off test.js:17
24 off
Hi, It's possible, I will take a look. thank you for this scenario.