Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Gelöst: Auslöser ermitteln

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Gelöst: Auslöser ermitteln

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

      Hallo mit folgenden kleine Script von Paul53 kann ich alle "true" gegen "false austauschen.
      Ich möchte gerne noch den Namen des Datensatz ermitteln der von true auf false gesetzt wurde

      const ids = $("iot.*.services.custom_Heimreise");
      
      function cntDel() {
          ids.each(function (id, i) {
              if (getState(id).val == 'true') 
              setState(id,"false")
          });
      };
      cntDel(); // Skriptstart
      ids.on(cntDel);
      

      Michael

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

        @michihorn sagte: alle "true" gegen "false austauschen

        Wirklich als String? Sonst:

        const ids = $("iot.*.services.custom_Heimreise");
         
        ids.each(function(id) { // Skriptstart
            if(getState(id).val) setState(id, false);
        });
        
        ids.on(function(dp) {
            if(dp.state.val) {
                setState(dp.id, false);
                log(dp.common.name);
            }
        });
        
        M 1 Reply Last reply Reply Quote 0
        • M
          michihorn @paul53 last edited by

          @paul53 sagte in Auslöser ermitteln:

          @michihorn sagte: alle "true" gegen "false austauschen

          Wirklich als String? Sonst:

          const ids = $("iot.*.services.custom_Heimreise");
           
          ids.each(function(id) { // Skriptstart
              if(getState(id).val) setState(id, false);
          });
          
          ids.on(function(dp) {
              if(dp.state.val) {
                  setState(dp.id, false);
                  log(dp.common.name);
              }
          });
          

          Ja String, aber nur weil ich nicht weiß wie ich im IOT einen Boolschen Wert über geben kann.

          https://service.iobroker.in/v1/iotService?service=custom_Anreise&key=xxxxxxxxx&user=michi.xhxxrn%40gmail.com&data=<SOME_TEXT>
          
          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @michihorn last edited by

            @michihorn sagte: Ja String,

            Dann muss mit "true" verglichen und "false" gesetzt werden.

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

              @paul53 sagte in Auslöser ermitteln:

              @michihorn sagte: Ja String,

              Dann muss mit "true" verglichen und "false" gesetzt werden.

              Ja das ist der Plan.
              Das Projekt soll eine Anwesenheitüberwachung für meine 3 Familienmitglieder im Geo Umkreis von 500 Meter machen, das klappt auch. Ich habe zwei weitere Dienste im IOT hinterlegt "Ankunft" triggert an der Grenze zu Holland und schaltet schon mal den Kühlschrank im Ferienhaus ein, stellt die Heizung/Klima auf 21Grad. 1h 20 min reichen aus.
              Ein weiter Dienst heisst Heimreise und der löst schon 30 km nach dem Verlassen des FH aus, Kühlschrank aus, Heizung auf 10 Grad. Der Hintergrund meiner Anfrage ist das Gegeseitige verriegeln von Anreise und Heimreise. Wenn ich z.B Heimreise soll falls meine Frau oder der Sohn noch vor Ort bleiben, nur mein Dienst "Anreise" auf false gesetzt werden.
              Das Script für Anreise sieht so aus:

              /*****GEOfancy ANREISE *****************************************
              **    Januar 2022
              **   IOT, EgiGeo
              **    (true), (false)
              **    erstellt: 24.01.22, 
              **    geändert: 14.06.23
              ***********************************************************************/
              var logging = true;
              const idFrigo = "tuya.0.bfce754681c6e2c8faowag.2"
              const idMedia = "tuya.0.bf292a4c8b62843697ntvv.1"
              const idTempIn = "tuya.0.73103057e868e768284a.3"
              const idHeizung = "tuya.0.73103057e868e768284a.2"
              const idAirCo = "daikin.0.control.power"
              const idAW = "0_userdata.0.Giethoorn.AW.AW"
              const ids = $('iot.*.services.custom_Anreise');
              const idCnt = "0_userdata.0.Giethoorn.AW.Anreise"
              var text
              
              function cntAnreise() {
                  let cnt = 0;
                  ids.each(function (id, i) {
                      if (getState(id).val == 'true') cnt++;
                  });
                  setState(idCnt, cnt, true);
                  if (getState(idCnt).val >= 1) {
                      log("Anreise erkannt")
                      setState(idFrigo, true)
                      setState(idMedia, true)
                      setState(idHeizung, 22)
                      text = '\ud83d\ude98  Anreise von  🇩🇪  nach  🇳🇱  erkannt '
                      createEventlog("GTHRN", text)
                      if (logging) sendTo('whatsapp-cmb.0', 'send', { text, phone: '+491xxxxx' });
                      if ((getState(idTempIn).val >= 30)) {
                          setState(idAirCo, true)
                  }
                  }
              };
              cntAnreise(); // Skriptstart
              ids.on(cntAnreise);
              

              EDIT: Anbei der Objektbaum vom IOT
              Screenshot 2023-10-16 152935.png
              Als Lösung funktioniert nun folgendes Script:

              /*****GEOfancy ANREISE *****************************************
              **    Januar 2022
              **   IOT, EgiGeo
              **    (true), (false)
              **    erstellt: 24.01.22, 
              **    geändert: 14.06.23
              ***********************************************************************/
              var logging = true;
              const idFrigo = "tuya.0.bfce754681c6e2c8faowag.2"
              const idMedia = "tuya.0.bf292a4c8b62843697ntvv.1"
              const idTempIn = "tuya.0.73103057e868e768284a.3"
              const idHeizung = "tuya.0.73103057e868e768284a.2"
              const idAirCo = "daikin.0.control.power"
              const ids = $('iot.*.services.custom_Anreise');
              const idCnt = "0_userdata.0.Giethoorn.AW.Anreise"
              var text
              
              function cntAnreise() {
                  let cnt = 0;
                  ids.each(function (id, i) {
                      if (getState(id).val == 'true') cnt++;
                  });
                  setState(idCnt, cnt, true);
                  if (getState(idCnt).val >= 1) {
                      log("Anreise erkannt")
                      setState(idFrigo, true)
                      setState(idMedia, true)
                      setState(idHeizung, 22)
                      text = '\ud83d\ude98  Anreise von  🇩🇪  nach  🇳🇱  erkannt '
                      createEventlog("GTHRN", text)
                      if (logging) sendTo('whatsapp-cmb.0', 'send', { text, phone: '+491xxxx149' });
                      if ((getState(idTempIn).val >= 30)) {
                          setState(idAirCo, true)
                      }
                  }
              };
              cntAnreise(); // Skriptstart
              ids.on(cntAnreise);
              
              var newstring
              ids.each(function (id) { // Skriptstart
                  if (getState(id).val)
                      setState(id, true);
              });
              
              ids.on(function (dp) {
                  if (dp.state.val) {
                      log("INFO: " + dp.id);
                      var string = dp.id
                      newstring = string.replace("custom_Anreise", "custom_Heimreise");
                      log("Ergebnis: " + newstring)
                      setState(newstring, "false")
                  }
              });
              

              Und für die Heimreise sieht das Script dann so aus.

              /*****GEOfancy HEIMREISE *****************************************
              **    Januar 2022
              **    IOT, EgiGeo
              **    (true), (false)
              **    erstellt: 24.01.22, 
              **    geändert: 14.6.23
              ***********************************************************************/
              
              var logging = true;
              const idFrigo = "tuya.0.bfce754681c6e2c8faowag.2"
              const idMedia = "tuya.0.bf292a4c8b62843697ntvv.1"
              const idTempIn = "tuya.0.73103057e868e768284a.3"
              const idHeizung = "tuya.0.73103057e868e768284a.2"
              const idAirCo = "daikin.0.control.power"
              const idAW = "0_userdata.0.Giethoorn.AW.AW"
              const ids = $("iot.*.services.custom_Heimreise");
              const idCnt = "0_userdata.0.Giethoorn.AW.Heimreise"
              var text
              
              function cntHeimreise() {
                  let cnt = 0;
                  ids.each(function (id, i) {
                      if (getState(id).val == 'true') cnt++;
                  });
                  setState(idCnt, cnt, true);
                  if (getState(idCnt).val >= 1) {
                      log("Heimreise erkannt")
                      setState(idFrigo, false)
                      setState(idMedia, false)
                      setState(idHeizung, 10)
                      setState(idAirCo, false)
                      text = '\ud83d\ude98  Heimreise von  🇳🇱  nach  🇩🇪  erkannt '
                      createEventlog("GTHRN", text)
                      if (logging) sendTo('whatsapp-cmb.0', 'send', { text, phone: '+49xxxxx149' });
                  }
              };
              cntHeimreise(); // Skriptstart
              ids.on(cntHeimreise);
              
              var newstring
              ids.each(function (id) { // Skriptstart
                  if (getState(id).val)
                      setState(id, true);
              });
              
              ids.on(function (dp) {
                  if (dp.state.val) {
                      log("INFO: " + dp.id);
                      var string = dp.id
                      newstring = string.replace("custom_Heimreise", "custom_Anreise");
                      log("Ergebnis: " + newstring)
                      setState(newstring, "false")
                  }
              });
              
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              Support us

              ioBroker
              Community Adapters
              Donate

              721
              Online

              31.7k
              Users

              79.8k
              Topics

              1.3m
              Posts

              javascript
              2
              5
              222
              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