Script for enabling schedule every evening

Hinweis zur Nutzung von Skripten (für Nutzer)

Die Verwendung von Skripten erfolgt ausdrücklich auf eigene Gefahr. Weder Shelly noch die jeweiligen Autoren oder Entwickler der Skripte übernehmen irgendeine Form der Haftung für mögliche Schäden, Fehlfunktionen, Datenverluste oder anderweitige Beeinträchtigungen, die durch die Nutzung dieser Skripte entstehen könnten. Bitte stellen Sie vor dem Einsatz sicher, dass Sie den Quellcode verstehen und sich der möglichen Auswirkungen bewusst sind. Die Skripte werden ohne Gewähr bereitgestellt und unterliegen keiner regelmäßigen Wartung oder offiziellen Unterstützung.


Hinweis für Entwickler

Wenn Sie eigene Skripte bereitstellen, achten Sie bitte darauf, eine klare Beschreibung, eventuelle Einschränkungen und Sicherheitsaspekte zu dokumentieren. Beachten Sie zudem, dass Nutzer Ihre Skripte grundsätzlich auf eigenes Risiko verwenden. Eine Haftung für Schäden ist ausgeschlossen, sofern diese nicht vorsätzlich oder grob fahrlässig verursacht wurden oder gesetzlich anderweitig geregelt ist.

  • Can someone please give me some guide to a script that enables an existing schedule (no 1) every evening at 23:00?

    EDIT: Now I have the first part that reenables the existing schedule. Last thing is to complete the script with code so it runs every evening.

    Shelly.call("Schedule.Update", {

    "id": 1,

    "enable": true

    }

    );

    3 Mal editiert, zuletzt von DrJoshua (3. November 2022 um 15:08)

  • You could use a timer to ask a time server what time it is every minute and check if it is currently 23:00. I tried to do a test implementation below. You still have to insert your schedule enabling into the if clause. Also change the time zone accordingly, I currently set it to German time. There is also the problem with missing the target time because the polling intervall is exactly 60 seconds, which means we could possibly skip it. Good luck:

    [script] [/script]

    [script]let CONFIG = { [/script]

    [script] pollingInterval: 60 * 1000, [/script]

    [script] pollingUrl: "https://timeapi.io/api/Time/curre…e=Europe/Berlin", [/script]

    [script] hour: 23, [/script]

    [script] minute: 00, [/script]

    [script]}; [/script]

    [script]
    [/script]

    [script]Timer.set( [/script]

    [script] CONFIG.pollingInterval, [/script]

    [script] true, // Run periodically [/script]

    [script] function (ud) { [/script]

    [script] Shelly.call("HTTP.REQUEST", [/script]

    [script] { method: "GET", url: CONFIG.pollingUrl, timeout: 10 }, [/script]

    [script] function (res, error_code, error_msg, ud) { [/script]

    [script] print("errors-http-post:", error_code, error_msg); [/script]

    [script] if (error_code === 0) { [/script]

    [script] let parsedBody = JSON.parse(res.body); [/script]

    [script] print("Time server response:", res.body); [/script]

    [script] if (parsedBody.hour === CONFIG.hour && parsedBody.minute === CONFIG.minute) { [/script]

    [script] print("test"); [/script]

    [script] // do your thing [/script]

    [script] } [/script]

    [script] } [/script]

    [script] }, [/script]

    [script] null [/script]

    [script] ); [/script]

    [script] }, [/script]

    [script] null [/script]

    [script]); [/script]

    [script][/script]

  • I just found out you can actually get the time from the device itself. This way you're not depending on some time server running. It works like this:

    [script][/script]

    [script]Shelly.call("Sys.GetStatus", [/script]

    [script] {}, [/script]

    [script] function (res, error_code, error_msg, ud) { [/script]

    [script] print("Current time is:", res.time); [/script]

    [script] }, [/script]

    [script]); [/script]

    [script][/script]

  • Thanks for input!

    I think I made it more complex than it was. The result became a script like this:

    Shelly.call("schedule.create",

    {

    "enable":true,

    "timespec":"0 11 21 * * SUN,MON,TUE,WED,THU,FRI,SAT",

    "calls":[{

    "method":"Schedule.Update",

    "params":{

    "id":1,

    "enable":true

    }

    }

    ]

    }

    )