Having trouble with timers?

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.

VPN/Proxy erkannt

Es scheint, dass Sie einen VPN- oder Proxy-Dienst verwenden. Bitte beachten Sie, dass die Nutzung eines solchen Dienstes die Funktionalität dieser Webseite einschränken kann.

  • Hello all -

    I'm having a hell of a time trying to get a Shelly script to work with Timers. I know what I'm after, but it does seem like the asynchronous execution of this JavaScript is biting me. It's a very simple script, but every time I add another timer it seems like the call stack just balloons into infinity and then I "run out of" timers. Basically, my script needs to:

    1. Turn the Shelly on.
    2. Wait two minutes.
    3. Use the HTTP.Get to check if a certain webpage is up, and print to the console the number of reboots, the number of successes (times it got the webpage) and the number of failures (times it failed to load the webpage).
    4. Turn the Shelly off.
    5. Repeat.

    In order to repeat this, I use a five second timer to repeat the process... but I'm obviously ALSO using a timer to delay firing off the HTTP.Get part of the script. How do I solve this? If this were a synchronous script, this would be cake, but... it isn't, and async code is something I'm MUCH less experienced with (and extremely frustrated by, but I'm here to learn!).

  • I'm not sure if I understand the desired functionality completely, but the following code should run without technical difficulties. This version will:

    1. Turn the switch on
    2. Wait 115 seconds
    3. Check if the endpoint can be reached
      • if no: increase the failCount, wait 5 seconds and go back to step 3
      • if yes: increase the rebootCount, turn the switch off and immediately restart from step 1

    Two notes:

    • You define a CONFIG.rebootToggleTime, but it is never used
    • The CONFIG.httpTimeout variable is not defined, so I added it with a value of 10

    Let me know if this does what you need...

  • //http timeout, magic number, not yet documented

    https://shelly-api-docs.shelly.cloud/gen2/Component…es/HTTP#httpget

    Your script is mysterious.

    print to the console the number of reboots

    Reboots? Of which device? Where does the information about the number of reboots come from?

    What is hidden behind the IP address of CONFIG.endpoint?

    An Cloud-/Szenen-Benutzer (insbesondere für Regelungen): Was erwartest du, wenn Internet oder Cloud sabotiert werden? Nicht nur dafür meine kleine Skripteinführung  8)

    Die einzig existierende Konstante ist der Wandel. Oft liegt die größte Schwierigkeit darin, das Anliegen des Klienten zu verstehen.