Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Pause zwischen 2 Befehlen

    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

    Pause zwischen 2 Befehlen

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

      Immer wenn die Bodenfeuchtigkeit zu gering ist, soll eine Message an Telegram gesendet werden.
      Dann soll wieder in einer Stunde getestet werden.
      Aber es funktioniert nicht.
      Diese Meldung kommt: "script.js.Pflanzenmelder: Invalid callback for setTimeout! - string"
      Jemand eine Idee?

      // Ist die Pflanze gegossen ? 
      var request = require('request');
      var fs      = require('fs');
      
      on({id: "ble.0.c4:7c:8d:6b:12:c1.moisture", change: 'any'}, function (obj) {
        var value = obj.state.val;
        var oldValue = obj.oldState.val;
        var Wasserstatus = getState('ble.0.c4:7c:8d:6b:12:c1.moisture').val;
        if (Wasserstatus < '40') {
        sendTo('telegram.0', '@Thomas Hallo! Ich bin die Pflanze im Wohnzimmer. Ich muß gegossen werden !');
        //sendTo('telegram.0', '@Nicole Hallo! Ich will gegossen werden !')
      function time_out() {
      		history.back();
      	}
      	to = setTimeout("time_out()", 3600000);
        
        };
      });
      
      paul53 2 Replies Last reply Reply Quote 0
      • paul53
        paul53 @thobastian last edited by

        @thobastian

        1. Wozu dienen die require() ?
        2. Wo ist history.back() deklariert ?
        3. Wenn man etwas zyklisch ausführt, benötigt man auch eine Abbruch-Bedingung
        4. Richtig:
        setTimeout(time_out, 3600000);
        
        1 Reply Last reply Reply Quote 0
        • paul53
          paul53 @thobastian last edited by paul53

          @thobastian sagte:

          Dann soll wieder in einer Stunde getestet werden.

          Mache es mit einem Intervall.

          Blockly_temp.JPG

          <xml xmlns="http://www.w3.org/1999/xhtml">
           <variables>
             <variable type="undefined" id="Intervall">Intervall</variable>
           </variables>
           <block type="procedures_defnoreturn" id="lWiM3/mwpPn}ln}qZ]%*" x="488" y="-63">
             <field name="NAME">giessen</field>
             <comment pinned="false" h="80" w="160">Beschreibe diese Funktion …</comment>
             <statement name="STACK">
               <block type="telegram" id="MD4a;3_/7bR{_T/^lx5g">
                 <field name="INSTANCE"></field>
                 <field name="LOG"></field>
                 <field name="SILENT">FALSE</field>
                 <field name="PARSEMODE">default</field>
                 <value name="MESSAGE">
                   <shadow type="text" id="S/IVQw3cmKH*7AW.`v^X">
                     <field name="TEXT">text</field>
                   </shadow>
                 </value>
               </block>
             </statement>
           </block>
           <block type="on" id="~A+JOfB}FDh{n7SG{/ZJ" x="138" y="-37">
             <field name="OID">Object ID</field>
             <field name="CONDITION">ne</field>
             <field name="ACK_CONDITION"></field>
             <statement name="STATEMENT">
               <block type="controls_if" id="(Qix8$JP7X$Yb8J[p`(P">
                 <mutation elseif="1"></mutation>
                 <value name="IF0">
                   <block type="logic_compare" id="|}[M-|9YBQh(;vU+hP!+">
                     <field name="OP">LT</field>
                     <value name="A">
                       <block type="on_source" id=",BGiVd=DJY8vGwNOU{R?">
                         <field name="ATTR">state.val</field>
                       </block>
                     </value>
                     <value name="B">
                       <block type="math_number" id="tWyF(NV){lU1Lp;42Y_L">
                         <field name="NUM">40</field>
                       </block>
                     </value>
                   </block>
                 </value>
                 <statement name="DO0">
                   <block type="controls_if" id="t~[yi.`v0u4|T8dirQO#">
                     <value name="IF0">
                       <block type="logic_negate" id="z;G(pQw8bq,`bKg6R[Rv">
                         <value name="BOOL">
                           <block type="variables_get" id=",k?p%5tC35`4F-I95*eF">
                             <field name="VAR" id="Intervall" variabletype="undefined">Intervall</field>
                           </block>
                         </value>
                       </block>
                     </value>
                     <statement name="DO0">
                       <block type="procedures_callnoreturn" id="s;GBAm_zaw$+lcOcNnRO">
                         <mutation name="giessen"></mutation>
                         <next>
                           <block type="timeouts_setinterval" id="Np!maX1^/:50w!9TZ8^J">
                             <field name="NAME">Intervall</field>
                             <field name="INTERVAL">60</field>
                             <field name="UNIT">min</field>
                             <statement name="STATEMENT">
                               <block type="procedures_callnoreturn" id="HRk//@9dOqmvxQO0HlF.">
                                 <mutation name="giessen"></mutation>
                               </block>
                             </statement>
                           </block>
                         </next>
                       </block>
                     </statement>
                   </block>
                 </statement>
                 <value name="IF1">
                   <block type="logic_compare" id="X64OcEwqO.;ge}J{THp}">
                     <field name="OP">GT</field>
                     <value name="A">
                       <block type="on_source" id="b)?JK,gE?s{1,luj]|+w">
                         <field name="ATTR">state.val</field>
                       </block>
                     </value>
                     <value name="B">
                       <block type="math_number" id="U(rvuM%7[]/16Uq~HjPB">
                         <field name="NUM">45</field>
                       </block>
                     </value>
                   </block>
                 </value>
                 <statement name="DO1">
                   <block type="timeouts_clearinterval" id="+i*(P``Kvpn:6-J*J[Y9">
                     <field name="NAME">Intervall</field>
                   </block>
                 </statement>
               </block>
             </statement>
           </block>
          </xml>
          

          1 Reply Last reply Reply Quote 0
          • T
            thobastian last edited by

            @paul53 sagte in Pause zwischen 2 Befehlen:

            setTimeout(time_out, 3600000);

            Wie kann ich das im Script einfach machen ?
            Hast Du ein Beispiel mit Settmieout?

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

              @thobastian sagte in Pause zwischen 2 Befehlen:

              Wie kann ich das im Script einfach machen ?

              var Wasserstatus = getState('ble.0.c4:7c:8d:6b:12:c1.moisture').val;
              var timer = null;
              
              function time_out() {
                if (Wasserstatus < 43) {
                  sendTo('telegram.0', '@Thomas Hallo! Ich bin die Pflanze im Wohnzimmer. Ich muß gegossen werden !');
                  //sendTo('telegram.0', '@Nicole Hallo! Ich will gegossen werden !')
                  timer = setTimeout(time_out, 3600000);
                } else timer = null;
              }
              
              time_out(); // Script start
              on("ble.0.c4:7c:8d:6b:12:c1.moisture", function (obj) { // Wertänderung
                Wasserstatus = obj.state.val;
                if(Wasserstatus < 40 && !timer) time_out();
              });
              
              1 Reply Last reply Reply Quote 0
              • Gaspode
                Gaspode last edited by

                Mir ist nicht so 100%ig klar, was du eigentlich willst, aber wenn es darum geht, jede Stunde die Feuchtigkeit zu prüfen, wäre schedule die einfachste Lösung. So würde dein Script zu jeder vollen Stunde ausgeführt:

                schedule({'0 * * * *'}, function(){
                    var Wasserstatus = getState('ble.0.c4:7c:8d:6b:12:c1.moisture').val;
                    if (Wasserstatus < '40') {
                        sendTo('telegram.0', '@Thomas Hallo! Ich bin die Pflanze im Wohnzimmer. Ich muß gegossen werden !');
                    }
                });
                
                T 1 Reply Last reply Reply Quote 0
                • T
                  thobastian @Gaspode last edited by

                  @Alexi Hallo Alexi, ja, das hast Du Recht. Die Programmierung ist auch sauberer. Danke!

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

                  Support us

                  ioBroker
                  Community Adapters
                  Donate

                  827
                  Online

                  31.8k
                  Users

                  80.0k
                  Topics

                  1.3m
                  Posts

                  3
                  7
                  929
                  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