Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [Gelöst]Lowbat script

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    [Gelöst]Lowbat script

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

      1626_lowbat.png Hallo,

      ich hätte eine Frage zum LOWbat script.

      Ich habe es eingebunden doch es zeigt mir in den Objekten nur Null an.

      Wo ist denn da mein Fehler?

      Danke für die Hilfe im voraus.

      createState('zählenLowbat.möglicheLOWBAT', 0);   // wenn benötigt: Anzahl der vorhandenen LOWBAT
      createState('zählenLowbat.anzahlLOWBAT', 0);     // wenn benötigt: Anzahl der vorhandenen LOWBAT
      createState('zählenLowbat.textLOWBAT', " ");     // Anzahl LOWBAT, die an sind als Variable unter Javascript.0 anlegen
      
      var cacheSelectorLOWBAT  = $('channel[state.id=*.LOWBAT]');
      
      function countLowbat(obj) {
         // Setzt die Zähler vor dem Durchlauf aller Elemente *.LOWBAT auf 0
         var moeglicheLOWBAT = 0;
         var anzahlLOWBAT    = 0;
         var textLOWBAT      = [];
      
         if (obj) {
            log('Auslösender Aktor: ' + obj.id + ': ' + obj.newState.val);  // Info im Log, welcher Zustand sich geändert hat
         } else {
            log('Ausgelöst bei Timer'); 
         } 
      
         cacheSelectorLOWBAT.each(function (id, i) {                         // Schleife für jedes gefundenen Element *.LOWBAT
            var status = getState(id).val;                                  // Zustand *.LOWBAT abfragen (jedes Element)
            var obj    = getObject(id);
            if (status === true) {                                          // wenn Zustand = true, dann wird die Anzahl der Geräte hochgezählt
               textLOWBAT.push(obj.common.name);                           // Zu Array hinzufügen
            }                
            log("Geräte Nr. " + i + ": " + getObject(id).common.name + ": " + status);
            ++anzahlLOWBAT;                                                 // Zählt die Anzahl der vorhandenen Geräte unabhängig vom Status
         }); 
      
         // Schleife ist durchlaufen. Im Log wird der aktuelle Status (Anzahl, davon LOWBAT zutreffend) ausgegeben
         log("Text: " + textLOWBAT);
         log("Anzahl Geräte: " + moeglicheLOWBAT + " # davon LOWBAT erkannt: " +  anzahlLOWBAT);
      
         // die ermittelten Werte werden als javascript.0\. Variable in ioBroker gespeichert (z.B. für die Verarbeitung in VIS)
         setState("zählenLowbat.textLOWBAT",     textLOWBAT.join(',
      ')); // Schreibt die aktuelle Namen der Geräte mit LOWBAT Meldung
         setState("zählenLowbat.anzahlLOWBAT",   textLOWBAT.length);        // Schreibt die aktuelle Anzahl der Geräte im System
         setState("zählenLowbat.möglicheLOWBAT", moeglicheLOWBAT);          // Schreibt die aktuelle Anzahl der vorhandene Geräte 
      }
      
      cacheSelectorLOWBAT.on(function(obj) {    // bei Zustandänderung *. LOWBAT in allen Gewerken
         countLowbat(obj);
      });
      schedule("*/1 * * * *", function () {                                  //oder!! soll entweder ausgelöst werden alle 10 Minuten
         log("===>Will be triggered every 60 minutes!"); 
         countLowbat();
      });
      
      1 Reply Last reply Reply Quote 0
      • S
        spaceduck last edited by

        Dann hast Du kein Gerät welches einen Low Batt Status sendet. Alle Batterien voll 🙂

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

          stimmt imho so nicht.

          Auch die "möglichen" Lowbat sind 0, was nicht sein sollte.

          Nachtrag:

          Da scheint noch ein Skript mit Fehler drin genutzt zu sein.

          Dieser Teil

                 log("Geräte Nr. " + i + ": " + getObject(id).common.name + ": " + status);
                ++anzahlLOWBAT;                                                 // Zählt die Anzahl der vorhandenen Geräte unabhängig vom Statust
          

          sollte eigentlich

           ++moeglicheLOWBAT
          ````sein
          1 Reply Last reply Reply Quote 0
          • Lenny.CB
            Lenny.CB Most Active last edited by

            habe ich auch so…
            983_js.png
            983_js2.png

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

              Hi Jungs,

              genau das war es.

              Jetzt zählt er auch die möglichen.

              Vielen Dank für die wie immer tolle Hilfe.

              Gruß totocotonio

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

              Support us

              ioBroker
              Community Adapters
              Donate

              818
              Online

              31.7k
              Users

              79.8k
              Topics

              1.3m
              Posts

              4
              5
              633
              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