So, ich habe das script jetzt einmal so modifiziert:
Code
let night_flag = false;
//
function timerHandler() {
// create a new Date object
let now = new Date();
// get the current hour (from 0 to 23)
let hour = now.getHours();
//
let setHeatingTime = ((hour >= 6) && (hour <= (22 - 1))); /// (time greater than 6:00) AND (time less than 22:00)
///
if (setHeatingTime)
{
print("day mode");
night_flag = false; //reset night flag
Shelly.call( "http.get",
{ url: "http://127.0.0.1/rpc/Switch.SetConfig?id=0&config={%22in_mode%22:%22follow%22,%22initial_state%22:%22match_input%22}"});
Shelly.call( "http.get",
{ url: "http://127.0.0.1/rpc/Switch.SetConfig?id=1&config={%22in_mode%22:%22follow%22,%22initial_state%22:%22match_input%22}"});
}
else
{
print("night mode");
Shelly.call( "http.get",
{ url: "http://127.0.0.1/rpc/Switch.SetConfig?id=0&config={%22in_mode%22:%22detached%22,%22initial_state%22:%22off%22}"});
Shelly.call( "http.get",
{ url: "http://127.0.0.1/rpc/Switch.SetConfig?id=1&config={%22in_mode%22:%22detached%22,%22initial_state%22:%22off%22}"});
}
//all switch off
if (!night_flag && !setHeatingTime)
{
night_flag=true;
print("All switch off");
Shelly.call("Switch.set", {'id': 0,'on': false});
Shelly.call("Switch.set", {'id': 1,'on': false});
}
};
////////////////////////////////////////////////////////////////////////////////////////////
Timer.set(2000, true, timerHandler, null);
////////////////////////////////////////////////////////////////////////////////////////////
Alles anzeigen