-
Autor
Hab mir ein Script zum Reboot vom Shelly gebaut, was nach 20sec Button down arbeitet.
Anfänger Scripting - bin für jedes Feedback offen, geht sicher einfacher...
Vielleicht hilfts noch wem...
Code
let CONFIG = {
defaultTickerDelay : 0.500, // secs for checking state
defaultLongPressTime : 20.000 // secs before reboot
};
let debug = true; // TRUE for print to console, false by default
let btn_down_ts = 0;
let buttonHandle = 0;
function checkButton (ts)
{
if (debug) { print("checkButton ", ts); }
let btn_down_duration = ts - btn_down_ts;
if (debug) { print ("Button down for ", btn_down_duration , " ( ", ts, " - ", btn_down_ts, " )"); }
if (btn_down_duration > CONFIG.defaultLongPressTime)
{
if (debug) { print ("Long press detected - REBOOT"); }
Shelly.call("Shelly.Reboot", null, null);
} else
{
buttonHandle = Timer.set(CONFIG.defaultTickerDelay*1000,false,checkButton,ts + CONFIG.defaultTickerDelay); // restart timer on new ts
}
}
function Check(event){
let info = event.info;
if (debug) { print(JSON.stringify(info));}
if (info.component === "input:0")
{
if (info.event === "btn_up")
{
if (buttonHandle !== 0) {Timer.clear(buttonHandle);}
}
else if (info.event === "btn_down")
{
btn_down_ts = info.ts;
buttonHandle = Timer.set(CONFIG.defaultTickerDelay*1000,false,checkButton,info.ts + CONFIG.defaultTickerDelay);
if (debug) { print ("button down now: ", info.ts); }
}
}
}
Shelly.addEventHandler(Check);
Alles anzeigen