Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. [gelöst] Schaltzustand Verzögern

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] Schaltzustand Verzögern

    This topic has been deleted. Only users with topic management privileges can see it.
    • Aphofis
      Aphofis @paul53 last edited by

      @paul53 mach ich!

      Mein Script sieht so aus

      const idRestzeit = 'Osmose.Restzeit';
      
      const text_ein = ['Filter Max unterschritten, Skimmer & Osmose','\n','wurden wieder eingeschaltet'].join('');
      
      const text_aus = ['Filter Max erreicht, Skimmer & Osmose','\n','wurden abgeschaltet'].join('');
      
       
      
      createState(idRestzeit, 300, {type: 'number', unit: 's'});
      
       
      
      var Osmosefreigabe = !getState('sonoff.0.Aqua_Float.POWER4').val;
      
      var Schwimmer = getState("sonoff.0.Aqua_Float.POWER1").val;
      
      var Restzeit, timeout_aus, timeout_ein, Magnetventil_Kontrolle;
      
       
      
      function Magnetventil_Ein() {
      
        if (!Magnetventil_Kontrolle && Restzeit > 0 && Osmosefreigabe) {
      
          Magnetventil_Kontrolle = setInterval(function () {
      
            if (Restzeit > 0 && Schwimmer && Osmosefreigabe) {
      
              Restzeit--;
      
              setState(idRestzeit, 2 * Restzeit, true);
      
            } else {
      
              setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
      
              clearInterval(Magnetventil_Kontrolle); 
      
              Magnetventil_Kontrolle = null;
      
            }
      
          }, 2000);
      
          setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, true);
      
        }
      
      }
      
       
      
      // Skripstart
      
      setTimeout(function() {
      
          Restzeit = getState(idRestzeit).val / 2;
      
          if(Schwimmer && Osmosefreigabe) Magnetventil_Ein();
      
          else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
      
      }, 200);
      
       
      
      on({id: 'sonoff.0.Aqua_Float.POWER1', change: "ne"}, function (obj) {
      
        Schwimmer = obj.state.val;
      
        if(Schwimmer) Magnetventil_Ein();
      
      });
      
       
      
      schedule("0 0 * * *", function () {
      
        Restzeit = 150;
      
        setState(idRestzeit, 300, true);
      
        if(Schwimmer) Magnetventil_Ein();
      
      });
      
       
      
      on({id: 'sonoff.0.Aqua_Float.POWER4', change: "ne"}, function (obj) {
      
        if (obj.state.val) {
      
          timeout_aus = setTimeout(function () {
      
            Osmosefreigabe = false;  
      
            setState("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, false);
      
            setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
      
          }, 5000);
      
          if (timeout_ein) {
      
              clearTimeout(timeout_ein); 
      
              timeout_ein = null;
      
          }
      
        } else {
      
          timeout_ein = setTimeout(function () {
      
            Osmosefreigabe = true;
      
            if(Schwimmer) Magnetventil_Ein();                
      
            setStateDelayed("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, true, 10000);
      
          }, 10000);
      
          if (timeout_aus) {
      
              clearTimeout(timeout_aus); 
      
              timeout_aus = null;
      
          }
      
        }
      
      });
      
       
      
      on({id: 'sonoff.0.Aqua_Power.POWER3', change: "ne"}, function (obj) {
      
        var txt;  
      
        if (obj.state.val) txt = text_ein;   
      
        else txt = text_aus;   
      
        sendTo("telegram.0", "send", {
      
          text: txt
      
        });
      
        log(txt);
      
      });
      

      Wo soll ich es hier einfügen ?

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Aphofis last edited by

        @Aphofis sagte:

        Wo soll ich es hier einfügen ?

        In Zeile 72.

        Aphofis 1 Reply Last reply Reply Quote 0
        • Aphofis
          Aphofis @paul53 last edited by

          @paul53
          nach:

          if(Schwimmer) Magnetventil_Ein();
           else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false); 
          
          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @Aphofis last edited by paul53

            @Aphofis sagte:

            nach:

            Richtig. Und in Zeile 70 füge noch ein Log ein, um zu sehen ob richtig getriggert wird:

              log('Schwimmer: ' + Schwimmer);
            
            1 Reply Last reply Reply Quote 0
            • Aphofis
              Aphofis last edited by

              ok
              korrekt?

              on({id: 'sonoff.0.Aqua_Float.POWER1', change: "ne"}, function (obj) {
              
                Schwimmer = obj.state.val;
              
                if(Schwimmer) Magnetventil_Ein();
              
               else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false); 
               
              });
              
              paul53 1 Reply Last reply Reply Quote 0
              • paul53
                paul53 @Aphofis last edited by paul53

                @Aphofis sagte:

                korrekt?

                Ja, jedoch die Leerzeilen sind überflüssig: Sie entstehen beim Kopieren aus dem Forum.

                Aphofis 1 Reply Last reply Reply Quote 0
                • Aphofis
                  Aphofis last edited by

                  Magnetventil Stecker ist wieder drin JS neu gestartet.
                  OK also kann ich die rasu nehmen?

                  1 Reply Last reply Reply Quote 0
                  • Aphofis
                    Aphofis @paul53 last edited by Aphofis

                    @paul53
                    ist es so in Ordnung ?

                    const idRestzeit = 'Osmose.Restzeit';
                    const text_ein = ['Filter Max unterschritten, Skimmer & Osmose','\n','wurden wieder eingeschaltet'].join('');
                    const text_aus = ['Filter Max erreicht, Skimmer & Osmose','\n','wurden abgeschaltet'].join('');
                    
                    createState(idRestzeit, 300, {type: 'number', unit: 's'});
                    
                    var Osmosefreigabe = !getState('sonoff.0.Aqua_Float.POWER4').val;
                    var Schwimmer = getState("sonoff.0.Aqua_Float.POWER1").val;
                    var Restzeit, timeout_aus, timeout_ein, Magnetventil_Kontrolle;
                    
                    function Magnetventil_Ein() {
                      if (!Magnetventil_Kontrolle && Restzeit > 0 && Osmosefreigabe) {
                        Magnetventil_Kontrolle = setInterval(function () {
                          if (Restzeit > 0 && Schwimmer && Osmosefreigabe) {
                            Restzeit--;
                            setState(idRestzeit, 2 * Restzeit, true);
                          } else {
                            setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                            clearInterval(Magnetventil_Kontrolle); 
                            Magnetventil_Kontrolle = null;
                          }
                        }, 2000);
                        setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, true);
                      }
                    }
                    // Skripstart
                    setTimeout(function() {
                        Restzeit = getState(idRestzeit).val / 2;
                        if(Schwimmer && Osmosefreigabe) Magnetventil_Ein();
                        else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                    }, 200);
                    on({id: 'sonoff.0.Aqua_Float.POWER1', change: "ne"}, function (obj) {
                      Schwimmer = obj.state.val;
                      if(Schwimmer) Magnetventil_Ein();
                     else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false); 
                    });
                    
                    schedule("0 0 * * *", function () {
                      Restzeit = 150;
                      setState(idRestzeit, 300, true);
                      if(Schwimmer) Magnetventil_Ein();
                    });
                    
                    on({id: 'sonoff.0.Aqua_Float.POWER4', change: "ne"}, function (obj) {
                      if (obj.state.val) {
                        timeout_aus = setTimeout(function () {
                          Osmosefreigabe = false;  
                          setState("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, false);
                          setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                        }, 5000);
                      if (timeout_ein) {
                            clearTimeout(timeout_ein); 
                            timeout_ein = null;
                        }
                      } else {
                        timeout_ein = setTimeout(function () {
                          Osmosefreigabe = true;
                          if(Schwimmer) Magnetventil_Ein();                
                          setStateDelayed("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, true, 10000);
                        }, 10000);
                      if (timeout_aus) {
                            clearTimeout(timeout_aus); 
                            timeout_aus = null;
                        }
                      }
                    });
                    
                    on({id: 'sonoff.0.Aqua_Power.POWER3', change: "ne"}, function (obj) {
                      var txt;  
                      if (obj.state.val) txt = text_ein;   
                      else txt = text_aus;   
                      sendTo("telegram.0", "send", {
                        text: txt
                      });
                      log(txt);
                      log('Schwimmer: ' + Schwimmer);
                    });
                    

                    so

                    paul53 1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 @Aphofis last edited by paul53

                      @Aphofis sagte:

                      ist es so in Ordnung ?

                      Ja, aber wegen der besseren Lesbarkeit füge vorn in Zeile 35 (vor else) ein Leerzeichen ein; in Zeilen 51 und 61 vor if zwei Leerzeichen ein.

                      Aphofis 1 Reply Last reply Reply Quote 0
                      • Aphofis
                        Aphofis @paul53 last edited by

                        @paul53
                        So besser ?

                        const idRestzeit = 'Osmose.Restzeit';
                        const text_ein = ['Filter Max unterschritten, Skimmer & Osmose','\n','wurden wieder eingeschaltet'].join('');
                        const text_aus = ['Filter Max erreicht, Skimmer & Osmose','\n','wurden abgeschaltet'].join('');
                        
                        createState(idRestzeit, 300, {type: 'number', unit: 's'});
                        
                        var Osmosefreigabe = !getState('sonoff.0.Aqua_Float.POWER4').val;
                        var Schwimmer = getState("sonoff.0.Aqua_Float.POWER1").val;
                        var Restzeit, timeout_aus, timeout_ein, Magnetventil_Kontrolle;
                        
                        function Magnetventil_Ein() {
                          if (!Magnetventil_Kontrolle && Restzeit > 0 && Osmosefreigabe) {
                            Magnetventil_Kontrolle = setInterval(function () {
                              if (Restzeit > 0 && Schwimmer && Osmosefreigabe) {
                                Restzeit--;
                                setState(idRestzeit, 2 * Restzeit, true);
                              } else {
                                setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                                clearInterval(Magnetventil_Kontrolle); 
                                Magnetventil_Kontrolle = null;
                              }
                            }, 2000);
                            setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, true);
                          }
                        }
                        // Skripstart
                        setTimeout(function() {
                            Restzeit = getState(idRestzeit).val / 2;
                            if(Schwimmer && Osmosefreigabe) Magnetventil_Ein();
                            else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                        }, 200);
                        on({id: 'sonoff.0.Aqua_Float.POWER1', change: "ne"}, function (obj) {
                          Schwimmer = obj.state.val;
                          if(Schwimmer) Magnetventil_Ein();
                            else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false); 
                        });
                        
                        schedule("0 0 * * *", function () {
                          Restzeit = 150;
                          setState(idRestzeit, 300, true);
                          if(Schwimmer) Magnetventil_Ein();
                        });
                        
                        on({id: 'sonoff.0.Aqua_Float.POWER4', change: "ne"}, function (obj) {
                          if (obj.state.val) {
                            timeout_aus = setTimeout(function () {
                              Osmosefreigabe = false;  
                              setState("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, false);
                              setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                            }, 5000);
                             if (timeout_ein) {
                                clearTimeout(timeout_ein); 
                                timeout_ein = null;
                            }
                          } else {
                            timeout_ein = setTimeout(function () {
                              Osmosefreigabe = true;
                              if(Schwimmer) Magnetventil_Ein();                
                              setStateDelayed("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, true, 10000);
                            }, 10000);
                             if (timeout_aus) {
                                clearTimeout(timeout_aus); 
                                timeout_aus = null;
                            }
                          }
                        });
                        
                        on({id: 'sonoff.0.Aqua_Power.POWER3', change: "ne"}, function (obj) {
                          var txt;  
                          if (obj.state.val) txt = text_ein;   
                          else txt = text_aus;   
                          sendTo("telegram.0", "send", {
                            text: txt
                          });
                          log(txt);
                          log('Schwimmer: ' + Schwimmer);
                        });
                        
                        paul53 1 Reply Last reply Reply Quote 0
                        • paul53
                          paul53 @Aphofis last edited by

                          @Aphofis sagte:

                          So besser ?

                          Bedingt: Jetzt sind es zwei bzw. je ein Leerzeichen zuviel:

                          • else gehört linksbündig unter if
                          • if gehört linksbündig über die zugehörige schließende geschweifte Klammer in Zeilen 54, 64
                          Aphofis 1 Reply Last reply Reply Quote 0
                          • Aphofis
                            Aphofis @paul53 last edited by

                            @paul53 Ich schnalle die Struktur nicht so ganz!

                            const idRestzeit = 'Osmose.Restzeit';
                            const text_ein = ['Filter Max unterschritten, Skimmer & Osmose','\n','wurden wieder eingeschaltet'].join('');
                            const text_aus = ['Filter Max erreicht, Skimmer & Osmose','\n','wurden abgeschaltet'].join('');
                            
                            createState(idRestzeit, 300, {type: 'number', unit: 's'});
                            
                            var Osmosefreigabe = !getState('sonoff.0.Aqua_Float.POWER4').val;
                            var Schwimmer = getState("sonoff.0.Aqua_Float.POWER1").val;
                            var Restzeit, timeout_aus, timeout_ein, Magnetventil_Kontrolle;
                            
                            function Magnetventil_Ein() {
                            if (!Magnetventil_Kontrolle && Restzeit > 0 && Osmosefreigabe) {
                                Magnetventil_Kontrolle = setInterval(function () {
                                if (Restzeit > 0 && Schwimmer && Osmosefreigabe) {
                                    Restzeit--;
                                    setState(idRestzeit, 2 * Restzeit, true);
                                  } 
                            else {
                                    setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                                    clearInterval(Magnetventil_Kontrolle); 
                                    Magnetventil_Kontrolle = null;
                                  }
                                }, 2000);
                                setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, true);
                              }
                            }
                            // Skripstart
                            setTimeout(function() {
                                Restzeit = getState(idRestzeit).val / 2;
                                 if(Schwimmer && Osmosefreigabe) Magnetventil_Ein();
                                else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                            }, 200);
                            on({id: 'sonoff.0.Aqua_Float.POWER1', change: "ne"}, function (obj) {
                              Schwimmer = obj.state.val;
                            if(Schwimmer) Magnetventil_Ein();
                                else setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false); 
                            });
                            
                            schedule("0 0 * * *", function () {
                              Restzeit = 150;
                              setState(idRestzeit, 300, true);
                            if(Schwimmer) Magnetventil_Ein();
                            });
                            
                            on({id: 'sonoff.0.Aqua_Float.POWER4', change: "ne"}, function (obj) {
                            if (obj.state.val) {
                                timeout_aus = setTimeout(function () {
                                  Osmosefreigabe = false;  
                                  setState("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, false);
                                  setState("sonoff.0.Aqua_Control.POWER1"/*Osmose_Magnetventil*/, false);
                                }, 5000);
                                if (timeout_ein) {
                                    clearTimeout(timeout_ein); 
                                    timeout_ein = null;
                                }
                              } else {
                                timeout_ein = setTimeout(function () {
                                  Osmosefreigabe = true;
                                if(Schwimmer) Magnetventil_Ein();                
                                  setStateDelayed("sonoff.0.Aqua_Power.POWER3"/*Aqua_Power_Skimmer*/, true, 10000);
                                }, 10000);
                                if (timeout_aus) {
                                    clearTimeout(timeout_aus); 
                                    timeout_aus = null;
                                }
                              }
                            });
                            
                            on({id: 'sonoff.0.Aqua_Power.POWER3', change: "ne"}, function (obj) {
                              var txt;  
                             if (obj.state.val) txt = text_ein;   
                            else txt = text_aus;   
                              sendTo("telegram.0", "send", {
                                text: txt
                              });
                              log(txt);
                              log('Schwimmer: ' + Schwimmer);
                            });
                            
                            paul53 1 Reply Last reply Reply Quote 0
                            • paul53
                              paul53 @Aphofis last edited by

                              @Aphofis sagte:

                              Ich schnalle die Struktur nicht so ganz!

                              Die vorherige Version war besser !

                              Aphofis 1 Reply Last reply Reply Quote 0
                              • Aphofis
                                Aphofis @paul53 last edited by

                                @paul53
                                Na toll

                                paul53 1 Reply Last reply Reply Quote 0
                                • paul53
                                  paul53 @Aphofis last edited by

                                  @Aphofis
                                  Nimm diese:
                                  Osmose.js.txt

                                  Aphofis 1 Reply Last reply Reply Quote 0
                                  • Aphofis
                                    Aphofis @paul53 last edited by Aphofis

                                    @paul53
                                    Da fehlt dann nur

                                     log('Schwimmer: ' + Schwimmer); 
                                    
                                    paul53 1 Reply Last reply Reply Quote 0
                                    • paul53
                                      paul53 @Aphofis last edited by

                                      @Aphofis sagte:

                                      Da fehlt dann nur

                                      Wo ?

                                      Aphofis 1 Reply Last reply Reply Quote 0
                                      • Aphofis
                                        Aphofis @paul53 last edited by

                                        @paul53
                                        In der txt die ich nehmen sollte oder ist der Log da schon irgendwo drin?

                                        paul53 1 Reply Last reply Reply Quote 0
                                        • paul53
                                          paul53 @Aphofis last edited by

                                          @Aphofis sagte:

                                          ist der Log da schon irgendwo drin?

                                          Zeile 36.

                                          Aphofis 1 Reply Last reply Reply Quote 0
                                          • Aphofis
                                            Aphofis @paul53 last edited by

                                            @paul53 Das hab ich wohl nicht so ganz gefunden!
                                            Wird wohl auch noch eine Zeit dauern, bis ich JS lesen kann

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            885
                                            Online

                                            32.0k
                                            Users

                                            80.5k
                                            Topics

                                            1.3m
                                            Posts

                                            4
                                            262
                                            16368
                                            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