Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. [gelöst] Frage zum Script "Zählen von Fenstern"

NEWS

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    18
    1
    642

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    18
    1
    5.7k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    1.5k

[gelöst] Frage zum Script "Zählen von Fenstern"

Scheduled Pinned Locked Moved Skripten / Logik
40 Posts 12 Posters 6.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stimezo
    Forum Testing
    wrote on last edited by
    #31

    Vielen Dank tempestas,

    da bekomme ich einen Syntax:
    4996_oops.jpg

    Viele Grüße

    Christian

    1 Reply Last reply
    0
    • paul53P Offline
      paul53P Offline
      paul53
      wrote on last edited by
      #32

      @stimezo:

      da bekomme ich einen Syntax: `
      Es fehlt ein Punkt vor common:

      	var name = getObject(objekt).common.name;
      
      

      Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
      Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tempestas
        wrote on last edited by
        #33

        Danke, paul :)

        <size="85">ioBroker | 21 Adapter | Ubuntu Server | intel NUC | Homematic CCU2 | Hue | Osram Lightify| Sonos | 2x Instar Cam | Samsung Tab A 2016 im Holzrahmen| 3x Echo dot | 1x Echo | Neato Botvac D5</size>

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stimezo
          Forum Testing
          wrote on last edited by
          #34

          @paul53,

          @tempestas

          vielen Dank für Eure Unterstützung.

          mit dem Punkt ist der zweite Fehler verschwunden.

          Der erste leider noch nicht :-)

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tempestas
            wrote on last edited by
            #35

            jetzt aber (?!?):

            `// Skript zum prüfen, wieviele Fenster offen sind
            // Lösung für Xiaomi Kontakte, die nicht via $-Selector ansprechbar zu sein scheinen
            // Status: 4.1.2018
            
            // ############ ALLGEMEINE SKRIPTEINSTELLUNGEN ###############
            
            // debugging
            
            var debug = false;
            
            // states
            
            createState('Fenster.Total', 0);
            createState('Fenster.Offen', 0);
            createState('Fenster.Text', "", true);
            
            // ################## Fenster Kontakte #####################
            
            // Variablen / IDs deklarieren
            
            var    idFenster1 = "mihome.0.devices.magnet_158d0001dacfc1.state"/*Is opened Fenster Küche offen*/,   // ids eintragen, geht rechts oben im JS Editor, "id einfügen". Dort auf den "open" state verlinken. 
                   idFenster2 = "mihome.0.devices.magnet_158d0001dacfc7.state"/*Is opened Fenster Wohnzimmer offen*/;               // du kannst die Variablen auch "FensterKueche" usw nennen, es muss nicht "idFenster1" sein
                   // idFenster3 = [HIER DIE ID DEINER MAGNETEN EINFÜGEN] ,               // die IDs kannst du beliebig benennen. Müssen aber nachfolgend entsprechend eingetragen sein
                   // idFensterN = [HIER DIE ID DEINER MAGNETEN EINFÜGEN] ;               // die letzte ID muss mit einem Semikolon beendet werden, dazwischen Kommas
            
            var arrFenster = [idFenster1, idFenster2];               // hier musst du die gleichen Namen eintragen, wie du direkt hierüber eingestellt hast
            
            // Variablen     
            
            var countOffen = 0;
            var countTotal =arrFenster.length;
            var arrText = [];
            
            // ######## FUNKTIONEN ########
            
            on(arrFenster, function(){
            	arrText = [];
            	arrFenster.forEach(function(obj) {
            
            	var status = getState(obj).val;
            
                    if(status){
                        ++countOffen; 
                        countOffen= Math.min(arrFenster.length, countOffen);
                        if(debug) log("Es sind "+countOffen +" Fenster offen");
            
            			arrText.push(obj.common.name);
                    }
                    else{
                        --countOffen;
                        countOffen = Math.max(0, countOffen);
                        if(debug) log("Es sind "+countOffen +" Fenster offen");
                    }
            
            		setState("javascript.0.Fenster.Offen", countOffen);
            		setState("javascript.0.Fenster.Text", arrText.join(',
            '));     
            		}
            	})
            );  
            
             // ############# BEI SKIRPTSTART DIE COUNTER RICHTIG SETZEN ###################
            
            for (var i = 0; i< arrFenster.length; i++) {
                var objekt = arrFenster[i];
                var value = getState(objekt).val;
            
            	var name = getObject(objekt).common.name;
            	arrText.push(name);
            
                if(debug) log(arrFenster[i] + " ist " +value);
                if(value) ++countOffen;
            
                setState("javascript.0.Fenster.Offen", countOffen);
            
            }
                setState("javascript.0.Fenster.Total", countTotal);
            	setState("javascript.0.Fenster.Text", arrText.join(',
            '));` [/i][/i]
            

            <size="85">ioBroker | 21 Adapter | Ubuntu Server | intel NUC | Homematic CCU2 | Hue | Osram Lightify| Sonos | 2x Instar Cam | Samsung Tab A 2016 im Holzrahmen| 3x Echo dot | 1x Echo | Neato Botvac D5</size>

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stimezo
              Forum Testing
              wrote on last edited by
              #36

              Hallo tempestas,

              syntax ist weg :-)

              Bekomme in zeile 73 eine Warnung.

              4996_oops.jpg

              und folgendes im log:

              javascript.0	2018-06-05 12:34:41.535	error	at Object. <anonymous>(script.js.common.fensterfinal:41:13)
              javascript.0	2018-06-05 12:34:41.533	error	at Array.forEach (native)
              javascript.0	2018-06-05 12:34:41.532	error	at script.js.common.fensterfinal:50:27
              javascript.0	2018-06-05 12:34:41.529	error	Error in callback: TypeError: Cannot read property 'name' of undefined
              javascript.0	2018-06-05 12:34:25.163	error	at Object. <anonymous>(script.js.common.fensterfinal:41:13)
              javascript.0	2018-06-05 12:34:25.162	error	at Array.forEach (native)
              javascript.0	2018-06-05 12:34:25.160	error	at script.js.common.fensterfinal:50:27
              javascript.0	2018-06-05 12:34:25.154	error	Error in callback: TypeError: Cannot read property 'name' of undefined
              javascript.0	2018-06-05 12:34:03.026	info	script.js.common.fensterfinal: registered 2 subscriptions and 0 schedules
              javascript.0	2018-06-05 12:34:02.976	info	Start javascript script.js.common.fensterfinal</anonymous></anonymous>
              

              vielen Dank für Deine Hilfe und viele Grüße

              Christian

              1 Reply Last reply
              0
              • paul53P Offline
                paul53P Offline
                paul53
                wrote on last edited by
                #37

                In Zeile 73 ist nur eine Warnung, dass der Bezeichner name schon vorher einmal global deklariert wurde: Lass var weg oder verwende let.

                Der Fehler in Zeile 50 rührt daher, dass obj kein Objekt, sondern eine Datenpunkt-ID ist. Korrigiere bitte Zeilen 41 bis 43:

                	arrFenster.forEach(function(id) {
                		var obj = getObject(id);	
                		var status = getState(id).val;
                
                

                Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
                Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  stimezo
                  Forum Testing
                  wrote on last edited by
                  #38

                  Du bist der Beste.

                  Funktioniert super.

                  Viele Dank und viele Grüße

                  Christian

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    wocwm
                    wrote on last edited by
                    #39

                    Moin zusammen,

                    hört sich auf jeden Fall sehr Interessant an das Ganze. Bin gerade neu in die Materie eingestiegen.

                    Ist dieses Skript auch verwendbar in Verbindung mit ALEXA?

                    Der Anwendungsfall soll folgender sein:

                    • Ich zieh die Jacke an, beim Schuheanziehen sage ich: "ALEXA, ich verlasse dich jetzt!"

                    Alexa soll die Fenster zählen und mir sagen welche gerade noch offen sind.

                    Ist das so umsetzbar?!

                    Danke Community

                    A 1 Reply Last reply
                    0
                    • W wocwm

                      Moin zusammen,

                      hört sich auf jeden Fall sehr Interessant an das Ganze. Bin gerade neu in die Materie eingestiegen.

                      Ist dieses Skript auch verwendbar in Verbindung mit ALEXA?

                      Der Anwendungsfall soll folgender sein:

                      • Ich zieh die Jacke an, beim Schuheanziehen sage ich: "ALEXA, ich verlasse dich jetzt!"

                      Alexa soll die Fenster zählen und mir sagen welche gerade noch offen sind.

                      Ist das so umsetzbar?!

                      Danke Community

                      A Offline
                      A Offline
                      amsernat
                      wrote on last edited by
                      #40

                      @wocwm
                      das würde mich auch interessieren.

                      1 Reply Last reply
                      0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      237

                      Online

                      32.7k

                      Users

                      82.6k

                      Topics

                      1.3m

                      Posts
                      Community
                      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                      ioBroker Community 2014-2025
                      logo
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Home
                      • Recent
                      • Tags
                      • Unread 0
                      • Categories
                      • Unreplied
                      • Popular
                      • GitHub
                      • Docu
                      • Hilfe