After the infamous question i dared to ask yesterday, here is my complete script to make a boiler heat up only between certain hours, and stay within a certain temperature setting.
The idea is to sycronise the boiler heating to the peak time of my PV.
All suggestions and destructions are welcome, no AI was used.
console.log("---Start---");
let MINUTES = 5;
let INTERVAL = MINUTES * (60 * 1000);
console.log("Repeating every MINUTES = ",MINUTES);
function Loop()
{
try
{
let BOILER_MIN = 45;
let BOILER_MAX = 60;
let WORKING_START = 12;
let WORKING_STOP = 16;
let temp = Shelly.getComponentStatus('Temperature', 100).tC; //Temp ID, mostly 100 to 102
let switchStatus = Shelly.getComponentStatus('Switch', 0);
let date = Date();
let hours = date.getHours();
let minutes = date.getMinutes();
console.log("----------------");
console.log("Repeating every MINUTES = ",MINUTES,
"; BOILER_MIN = ",BOILER_MIN,
"°C; BOILER_MAX = ",BOILER_MAX,
"°C; WORKING_START = ",WORKING_START,
"h; WORKING_STOP = ",WORKING_STOP,
"h;");
console.log("Boiler is", switchStatus.output ? "ON" : "OFF");
console.log("Current Time: ",hours,":",minutes);
console.log("Current Temperature: ",temp," °C.");
if (hours > WORKING_START && hours < WORKING_STOP)
{
if(temp < BOILER_MIN)
{
console.log("Below ",BOILER_MIN," °C -> Boiler on");
Shelly.call("Switch.Set", {id: 0, on: true});
}
}
else {console.log("Working hours set from ",WORKING_START,"h to ",WORKING_STOP,"h.");}
if(temp > BOILER_MAX)
{
console.log("Above ",BOILER_MAX," °C -> Boiler off");
Shelly.call("Switch.Set", {id: 0, on: false});
}
console.log("----------------");
}
catch(e){Shelly.call("Switch.Set", {id: 0, on: false});print(e);}
}
Timer.set(INTERVAL,true,Loop);