Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. setState als Schrittkette ausführen

    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

    setState als Schrittkette ausführen

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

      Hi,

      wie bekomme ich es elegant hin, dass die States nacheinander abgearbeitet werden, auch wenn einer der States aufgrund der Bedingungen nicht ausgeführt wird?
      Mit dem Callback tue ich mir schwer, da ja SetState teilweise nicht ausgeführt wird, wenn es sich nicht um einen neuen Wert handelt.
      Die Abfrage, ob der alte Wert dem Neuen entspricht habe ich eingebaut, um keine unnötige Befehle über Zigbee und Homeatic zu senden.

      Im Grunde genommen soll das letzte SetState (pathControl) erst ausgeführt werden, wenn alle Vorgegangene durchgeführt sind.

      arrLights[i].setLightOn = async function(group){
              if (group.buttonPress == this.buttonPress) {
                  if (this.pathTransistion) {
                      var oldVal =  await getState(this.pathTransistion).val;
                      (oldVal != this.defaultTransition) 
                      setState(this.pathTransistion, this.defaultTransition);
                  }
                  if (this.pathColortemp) {
                      var oldVal = await getState(this.pathColortemp).val;
                      if(oldVal != this.defaultColorTemp) 
                      setState(this.pathColortemp, this.defaultColorTemp);
                  }
                  if (this.pathColor) {
                      var oldVal = await getState(this.pathColor).val;
                      //if(oldVal != this.defaultColor)
                      setState(this.pathColor, this.defaultColor);
                  }
                  if (this.pathControl) {
                      var oldVal = await getState(this.pathControl).val;
                      if(oldVal != (this.pathControlType == 'number') ? this.defaultLevel : true) {
                          setState(this.pathControl, (this.pathControlType == 'number') ? this.defaultLevel : true);
                          if (extLogging) console.log(`${scriptname}: Licht wird eingeschaltet: ${this.name} // Pfad: ${this.pathControl} // Wert: ${(this.pathControlType == 'number') ? this.defaultLevel : true}`);
                      }
                  }
      

      Grüße
      Schmakus

      E 1 Reply Last reply Reply Quote 0
      • E
        ente34 @Schmakus last edited by

        @schmakus
        Muss das nicht "await getStateAsync()" heissen?
        Genauso kannst Du "await setStateAsync()" verwenden

        Schmakus 1 Reply Last reply Reply Quote 0
        • Schmakus
          Schmakus Developer @ente34 last edited by

          @ente34 Ich stelle keinen Unterschied fest. Egal ob SetState oder setStateAsync

          Hab nun folgendes Code und laut Log wird alles nacheinander abgearbeitet so wie ich es gerne hätte.
          Gibt es vielleicht eine elegantere Lösung?

          if(this.pathColortemp) {  
              await setState(this.pathTransistion, this.defaultTransition)
              console.warn('1: Set Transition')
          }
          if(this.pathColortemp) {  
              await setState(this.pathColortemp, this.defaultColorTemp)
              console.warn('2: Set Colortemp')
          }
          if(this.pathColor) {    
              await setState(this.pathColor, this.defaultColor)
              console.warn('3: Set Color')
          }
          if(this.pathControl) {
              await setState(this.pathControl, (this.pathControlType == 'number') ? this.defaultLevel : true)
              console.warn('4: Set Control')
              setState(this.pathLastValue, (this.pathControlType == 'number') ? this.defaultLevel : true, true);
              console.warn('5: Set Light State')
              setState(this.pathLightState, true, true);  
              console.warn('6: Set Group Light State')    
              if (extLogging) console.log(`${scriptname}: Licht wird eingeschaltet: ${this.name} // Pfad: ${this.pathControl} // Wert: ${(this.pathControlType == 'number') ? this.defaultLevel : true}`);
          } 
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          887
          Online

          31.8k
          Users

          80.0k
          Topics

          1.3m
          Posts

          2
          3
          188
          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