Hello,
Let me start with informing that i am a supernoob in programming JSON.
I am trying to setup a thermostat function in node-red.
The idea is to control my heatpump´s temperature, and fanspeed settings based on a temperature sensor on my knx system.
I have managed to write a code for this that kind of work.
Does anyone have a better solution?, please share
var setpoint = flow.get("setpoint");
var current = msg.payload;
var h1 = 0.1
var h2 = 0.2
var h3 = 0.3
var h4 = 0.4
var h5 = 0.5
var h6 = 0.6
var h7 = 0.7
//Actual temperature under setpoint
if (current === (0)) {
msg.payload = "nothing";
} else if(current == (setpoint - h1)) {
msg.payload = "low";
} else if(current == (setpoint - h2)) {
msg.payload = "medium";
} else if(current == (setpoint - h3)) {
msg.payload = "medium";
} else if(current == (setpoint - h4)) {
msg.payload = "medium_high";
} else if(current == (setpoint - h5)) {
msg.payload = "medium_high";
} else if(current == (setpoint - h6)) {
msg.payload = "medium_high";
} else if(current <= (setpoint - h7)) {
msg.payload = "high";
// actual temperature same as setpoint
} else if(current == (setpoint)) {
msg.payload = "low";
// actual temperature over setpoint
} else if(current == (setpoint + h1)) {
msg.payload = "low";
} else if(current == (setpoint + h2)) {
msg.payload = "low";
} else if(current == (setpoint + h3)) {
msg.payload = "low";
} else if(current == (setpoint + h4)) {
msg.payload = "low";
} else if(current == (setpoint + h5)) {
msg.payload = "low";
} else if(current >= (setpoint + h6)) {
msg.payload = "off";
} else {
msg.payload = "nothing";
}
return msg;