Skip to content

Feature Request: Function support for Heating and Cooling #2

@viper33802

Description

@viper33802

I wanted to share how I have expanded on this function. I am using the base concept introduced here but I am adding both a heater and a fan (cooling) to the function as well as I setup four outputs for the function. I tried to make the code a bit more readable by creating variables for the payload objects. Since I wanted the single tolerance slider to effect both the heater and fan I added some additional math to give a wider tolerance for the fan than the heater(lines 4-7). This could be done with multiplication to make it scale to the temp but I am lazy. Lastly, since I am adjusting the tolerances I want to send the adjusted values back out to be displayed on my dashboard so I have added the actual on/off values to the msg.payload when it exits the script.

var temp = msg.payload["input_number.climate_temperature"] ;
var tol = msg.payload["input_number.climate_tolerance"];
var sensor = msg.payload["sensor.5x5_temperature"];
var fanon = (temp + (tol + 2));
var fanoff = (temp - (tol -2));
var heaton = (temp - (tol + 1));
var heatoff = (temp + (tol - 1));
msg.data.temps = {"current_temp":sensor, "set_temp":temp, "temp_tol":tol, "heat_on":heaton, "heat_off":heatoff, "fan_on":fanon, "fan_off":fanoff};
if (sensor < heaton) {
	var msg1={};
	msg1.payload= msg.data.temps;
}
else if (sensor > heatoff) {
        var msg2={};
	msg2.payload= msg.data.temps;
}
if (sensor > fanon) {
        var msg3={};
	msg3.payload= msg.data.temps;
}
else if (sensor < fanoff) {
	var msg4={};
	msg4.payload= msg.data.temps;
}
return[ msg1, msg2, msg3, msg4 ]

Here is what an output from this function looks like:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions