Hallo zusammen,
hab es dann doch noch alleine geschafft und mir die Schnipsel zusammengeklaut (danke an den Ostfriese (n) ). Falls das jemand braucht, hier der Code. Vielleicht kann ja da nochmal jemand drüberschauen, ob das so passt oder ich an der einen oder anderen Stelle noch etwas ändern sollte.
Code
let CONFIG = {
safetime : 500,
toggleTimeout: 5,
inputId: 0,
switchId: 0,
INPUT_ID: 0,
/**
* List (in the expected order) the operations that you want this script to cycle through.
* E.g. [switchId, "on" or "off"]
*/
CYCLES: [
[0, "on"],
[1, "on"],
],
};
Shelly.call("Switch.SetConfig", {
id: CONFIG.switchId,
config: {
in_mode: "detached",
},
});
Shelly.addEventHandler(function (event) {
if (typeof event.info.event === "undefined") return;
if (event.info.component === "input:" + JSON.stringify(CONFIG.inputId)) {
//ignore single_push and double_push events
if (event.info.event.indexOf("push") >= 0) return;
let swParams = {
id: CONFIG.switchId,
on: true,
}
if (event.info.event === "btn_up") {
// swParams.toggle_after = CONFIG.toggleTimeout;
set_to_off();
}
}
});
function log(to_log) {
console.log(to_log);
};
let currentCycle = 0;
function runCycle() {
log('Cyle started');
let currentOperation = CONFIG.CYCLES[currentCycle];
if (!currentOperation) {
currentCycle = 0;
currentOperation = CONFIG.CYCLES[currentCycle];
}
currentCycle++;
log('Set Relais ' + currentOperation[0] + ' to on');
Shelly.call("switch.set", {
id: JSON.stringify(currentOperation[0]),
on: currentOperation[1] === "on",
});
};
function set_to_off() {
Shelly.call("switch.set", {'id': 0, 'on': false});
log('Relay 0 off');
Shelly.call("switch.set", {'id': 1, 'on': false});
log('Relay 1 off');
/* if (query === '00') {
lock = false;
return;
}
*/
Timer.set(CONFIG.safetime,false,runCycle);
};
Alles anzeigen