node-red-contrib-heater-controller icon indicating copy to clipboard operation
node-red-contrib-heater-controller copied to clipboard

hysteresis calculation wrong

Open odenisenko-zz opened this issue 4 years ago • 1 comments

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 

odenisenko-zz avatar Mar 28 '20 09:03 odenisenko-zz

Hi, It's possible, I will take a look. thank you for this scenario.

SergiuToporjinschi avatar Jan 28 '21 22:01 SergiuToporjinschi