Verhindern, dass ein Shelly in der Nacht auf Schaltbefehle reagiert:
Code
// GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
// More information: https://www.gnu.org/licenses/gpl-3.0.txt
// ABSOLUTELY NO WARRANTY AT ALL!!!
// Made by ostfriese.
// Config
let Config = {
nighttime : '23:30', //must be before 00:00
daytime : '07:00', //must be after 00:00
on_url : 'http://127.0.0.1/relay/0?turn=on',
off_url : 'http://127.0.0.1/relay/0?turn=off'
}
// Config end. No changes below this row.
function time_to_number(time_str) {
return parseInt(time_str.split(":")[0]) * 3600 + parseInt(time_str.split(":")[1]) * 60;
}
function watch(request,response) {
if(lock) {
return;
}
lock = true;
if (time_to_number(Shelly.getComponentStatus("sys").time) >= time_to_number(Config.nighttime) ||
time_to_number(Shelly.getComponentStatus("sys").time) <= time_to_number(Config.daytime)) {
response.body = 'Night : No action at request ' + request.query;
}
else if (request.query === 'on') {
response.body = 'Day : Turned on';
Shelly.call("http.get", {url:Config.on_url});
}
else if (request.query === 'off') {
response.body = 'Day : Turned off';
Shelly.call("http.get", {url:Config.off_url});
}
response.code = 200;
response.send();
print(response.body);
Timer.set(1000, false, function(){lock = false;});
}
function start() {
HTTPServer.registerEndpoint('switch',watch);
print('Your possible urls are:');
print('http://' + Shelly.getComponentStatus("wifi").sta_ip + '/script/' + Shelly.getCurrentScriptId() + '/switch?on');
print('http://' + Shelly.getComponentStatus("wifi").sta_ip + '/script/' + Shelly.getCurrentScriptId() + '/switch?off');
}
let lock = false;
Timer.set(1000,false,start);
Alles anzeigen