Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Gelöst: Anzahl der Zigbee Geräte ermitteln

    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

    Gelöst: Anzahl der Zigbee Geräte ermitteln

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

      @paul53 Ja ich weiß, ich möchte jetzt gerne noch über "available" das true oder false auswerten um die nicht erreichbaren Geräte separat zu zählen

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

        @michihorn sagte: nicht erreichbaren Geräte separat zu zählen

        const ids = $("zigbee.0.*.available");
        const idCntOn = "0_userdata.0.System.Zigbee.Geräte0_On";
        const idCntOff = "0_userdata.0.System.Zigbee.Geräte0_Off";
         
        function cntzig0() {
            let cntOn = 0;
            let cntOff = 0;
            ids.each(function (id, i) {
                if (getState(id).val) cntOn++;
                else cntOff++
            });
            setState(idCntOn, cntOn, true);
            setState(idCntOff, cntOff, true);
            log('On: ' + cntOn + ', Off: ' + cntOff);
        }
         
        cntzig0(); // Skriptstart
        ids.on(cntzig0);
        

        EDIT: Anstelle von cntOff kann man auch die Differenz zur Gesamtanzahl verwenden:

            setState(idCntOff, ids.length - cntOn, true);
        
        M 1 Reply Last reply Reply Quote 0
        • M
          michihorn @paul53 last edited by michihorn

          @paul53 Danke Paul das klappt

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

            @michihorn sagte in Gelöst: Anzahl der Zigbee Geräte ermitteln:

            @paul53 Danke Paul das klappt

            Hätte allerdings noch eine Bitte:
            Wie kann ich die Anzahl der Tuya Geräte ermitteln, die im Common.Name "CAS_xxxxx" oder NL_xxxxx" enthalten?
            So einfach geht es nicht.

            const ids = $("tuya.1.*.common.name");
            const idCnt = "0_userdata.0.System.Tuya.CAS_Count";
             
            function cnttuya() {
                let cnt = 0;
                ids.each(function (id, i) {
                    
                    if (getState(id).val == 'CAS*') cnt++;
                    //if (getState(id).val) cnt++;
                    
                });
                setState(idCnt, cnt, true);
                log(cnt);
            }
             
            cnttuya(); // Skriptstart
            ids.on(cnttuya);
            
            
            paul53 1 Reply Last reply Reply Quote 0
            • paul53
              paul53 @michihorn last edited by

              @michihorn sagte: im Common.Name "CAS_xxxxx" oder NL_xxxxx" enthalten?

                      const nameDp = getObject(id).common.name;
                      if (nameDp.includes('CAS') || nameDp.includes('NL')) cnt++;
              

              Der Selektor stimmt nicht!!

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

                @paul53 sagte in Gelöst: Anzahl der Zigbee Geräte ermitteln:

                    const nameDp = getObject(id).common.name;                                                                                                                                                                                    if (nameDp.includes('CAS') || nameDp.includes('NL')) cnt++;                                            
                

                Ich möchte separat die Anzahl der Geräte mit CAS_xxx und ebenfalls separat die NL_Geräte ermitteln
                Ich habe dazu DP angelegt:
                "0_userdata.0.System.Tuya.CAS_Count" und
                "0_userdata.0.System.Tuya.NL_Count"

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

                  @michihorn sagte: separat die Anzahl der Geräte mit CAS_xxx und ebenfalls separat die NL_Geräte

                          const nameDp = getObject(id).common.name;
                          if (nameDp.includes('CAS')) cntCAS++;
                          if (nameDp.includes('NL')) cntNL++;
                  
                  M 1 Reply Last reply Reply Quote 0
                  • M
                    michihorn @paul53 last edited by

                    @paul53 sagte in Gelöst: Anzahl der Zigbee Geräte ermitteln:

                    const nameDp = getObject(id).common.name

                    Wie komme ich denn ie id? Muss ich nicht zunächst den Selector einrichten?
                    const ids = $("tuya.1.*.Common.Name");

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

                      @michihorn sagte: const ids = $("tuya.1.*.Common.Name");

                      Dieser Selektor ist mit großer Wahrscheinlichkeit falsch!
                      Zeige bitte mind. einen zu selektierenden Datenpunkt.

                      @michihorn sagte in Gelöst: Anzahl der Zigbee Geräte ermitteln:

                      Wie komme ich denn ie id?

                      Die id wird innerhalb der Schleife ids.each(id) übergeben.

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

                        @paul53 sagte in Gelöst: Anzahl der Zigbee Geräte ermitteln:

                        Dieser Selektor ist mit großer Wahrscheinlichkeit falsch!

                        selector.png

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

                          @michihorn
                          Ich sehe keinen Datenpunkt, sondern nur Geräte!
                          Gibt es einen Datenpunkt, der zu jedem Tuya-Gerät existiert?

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

                            @paul53 OK mein Fehler, ich will die Geräte zählen, ist wohl am einfachsten, und das separiert nach CAS_* und NL_*

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

                              @michihorn sagte: ich will die Geräte zählen

                              Dazu ist es zweckmäßig, im Selektor einen Datenpunkt(ID) anzugeben, der pro Gerät genau einmal existiert.

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

                                @paul53 Bei jedem Gerät ist der DP "xxxxx.online" vorhanden.

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

                                  @michihorn sagte: Bei jedem Gerät ist der DP "xxxxx.online" vorhanden.

                                  Direkt in der Ebene unter dem Gerät?

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

                                    @paul53 selector2.png

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

                                      @michihorn
                                      Versuche es so:

                                      const ids = $("tuya.1.*.online");
                                      const idCAS = "0_userdata.0.System.Tuya.CAS_Count";
                                      const idNL = "0_userdata.0.System.Tuya.NL_Count";
                                       
                                      let cntCAS = 0;
                                      let cntNL = 0;
                                      ids.each(function(id) {
                                          id = id.substring(0, id.lastIndexOf('.'));
                                          const devName = getObject(id).common.name;
                                          if(devName.includes('CAS')) cntCAS++;
                                          if(devName.includes('NL')) cntNL++;
                                      });
                                      setState(idCAS, cntCAS, true);
                                      setState(idNL, cntNL, true);
                                      log('CAS: ' + cntCAS + ', NL: ' + cntNL);
                                      
                                      M 1 Reply Last reply Reply Quote 0
                                      • M
                                        michihorn @paul53 last edited by michihorn

                                        @paul53

                                        Ja Paul das funktioniert. Dankeschön

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

                                        Support us

                                        ioBroker
                                        Community Adapters
                                        Donate

                                        854
                                        Online

                                        31.8k
                                        Users

                                        80.0k
                                        Topics

                                        1.3m
                                        Posts

                                        javascript
                                        2
                                        22
                                        612
                                        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