Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Lampe blinken lassen => Set State im Intervall

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Lampe blinken lassen => Set State im Intervall

    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      chco last edited by

      Hi,

      ich möchte meine Lampe, die an eine smarte Steckdose angeschlossen ist, per ioBroker JS Skript blinken lassen => 10x ein- und wieder ausschalten.

      Hätte dafür eine Blink-Funktion geschrieben:

      function blink()
      {
          for (var i = 0; i < 10; i++)
          {
              setState("shelly.Relay0.Switch",true)
              
              setTimeout(() => { setState("shelly.Relay0.Switch",false); }, 1000);
      
          }
      }
      
      blink();
      

      Die Lampe blinkt jedoch nur einmal und bleibt dann ausgeschaltet.

      Was mache ich in der Schleife mit dem SetTimeout falsch?

      Danke und LG

      Homoran liv-in-sky 2 Replies Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators @chco last edited by

        @chco das ist kein Thema zum Forum!
        ich hab das mal in die richtige (??) Kategorie verschoben.

        1 Reply Last reply Reply Quote 0
        • liv-in-sky
          liv-in-sky @chco last edited by liv-in-sky

          @chco

          probiersmal so:

          let counter=0;
          let valId =""shelly.Relay0.Switch"
            let myInt= setInterval(async function () {
                  counter++; 
                  let theState=getState(valId).val
                  setState(valId, theState=!theState)
          		if (counter==10) {clearInterval(myInt); myInt= null;}
          }, 2000);
          

          bei deiner version wird das extrem schnell hintereinader ausgeführt - da ist keine pause drin !

          C 1 Reply Last reply Reply Quote 1
          • C
            chco @liv-in-sky last edited by

            @liv-in-sky : Funktioniert perfekt, danke!

            1 Reply Last reply Reply Quote 1
            • First post
              Last post

            Support us

            ioBroker
            Community Adapters
            Donate

            822
            Online

            31.8k
            Users

            80.0k
            Topics

            1.3m
            Posts

            3
            4
            252
            Loading More Posts
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes
            Reply
            • Reply as topic
            Log in to reply
            Community
            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
            The ioBroker Community 2014-2023
            logo