Danke an alle für eure Hilfe,
Mit eurer Hilfe und der von KI habe ich nun ein laufendes Script, was auch die zeitliche Steuerung unterstützt, sowie den Button, als auch push Benachrichtigung.
Code
// Script 1 – Klingelsteuerung mit Zeitfenstern + Button-Override + Push-Szenen
// ---------- KONFIG: CLOUD & SZENEN ----------
// HIER anpassen:
const CLOUD = {
server: 'https://shelly-1-eu.shelly.cloud', // xx & Region anpassen
auth_key: 'xxx',
};
// Push-Szenen: 0 = AUS, 1 = EIN
const Scene = [
{ id: 1770235321840, msg: "input disabled" }, // AUS
{ id: 1770235253976, msg: "input enabled" }, // EIN
];
let SceneEn = true;
// ---------- ZEITFENSTER ----------
// Minuten seit Mitternacht
// Fenster 1: 12:00–15:00
// Fenster 2: 20:00–24:00 + 00:00–06:00
let TIME_WINDOWS = [
[12 * 60, 15 * 60], // 12:00–15:00
[20 * 60, 06 * 60], // 20:00–24:00
[0, 6 * 60] // 00:00–06:00
];
function getMinutes() {
let d = new Date();
return d.getHours() * 60 + d.getMinutes();
}
function isInTimeWindow() {
let m = getMinutes();
for (let i = 0; i < TIME_WINDOWS.length; i++) {
let start = TIME_WINDOWS[i][0];
let end = TIME_WINDOWS[i][1];
if (m >= start && m < end) return true;
}
return false;
}
// ---------- INPUT-STEUERUNG ----------
function toggleInpEn(id) {
Shelly.call("Input.GetConfig", { id: id },
function (res, errc, errm, id) {
if (errc) { console.log(errc, errm); return; }
Shelly.call("Input.SetConfig", { id: id, config: { enable: !res.enable } });
}, id
);
}
function enableInput() {
Shelly.call("Input.SetConfig", { id: 0, config: { enable: true } });
}
function disableInput() {
Shelly.call("Input.SetConfig", { id: 0, config: { enable: false } });
}
// ---------- PUSH-SZENEN AUSLÖSEN ----------
function sceneTrigger(i) {
if (!Scene[i]) return;
let url = CLOUD.server +
'/scene/manual_run&auth_key=' +
CLOUD.auth_key + '&id=' + Scene[i].id;
Shelly.call('HTTP.GET', { url: url },
function (resp, err, msg) {
if (err !== 0) {
print('Szene error: ', err, msg);
return;
}
let ok = JSON.parse(resp.body).isok;
print(Scene[i].msg + ", Szene wurde " + (ok ? "" : "nicht ") + "ausgelöst");
}
);
}
// ---------- EVENT-HANDLER: INPUT-ÄNDERUNGEN ----------
function inpEn(ev) {
if (ev.name !== "input") return;
if (ev.info.event !== "config_changed" || !SceneEn) return;
Shelly.call("Input.GetConfig", { id: ev.id },
function (res, errc, errm) {
if (errc) { console.log(errc, errm); return; }
sceneTrigger(res.enable ? 1 : 0);
}
);
}
Shelly.addEventHandler(inpEn);
// ---------- TIMER: ZEITFENSTER-STEUERUNG ----------
function checkTime() {
let inWindow = isInTimeWindow();
Shelly.call("Input.GetConfig", { id: 0 }, function (st) {
let enabled = st.enable;
if (inWindow && enabled) {
disableInput();
} else if (!inWindow && !enabled) {
enableInput();
}
});
}
// alle 60 Sekunden prüfen
Timer.set(60 * 1000, true, checkTime);
// einmal kurz nach Start prüfen
Timer.set(3000, false, checkTime);
print("Script 1 gestartet");
Alles anzeigen