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. JavaScript
  5. [GELÖST] Skript gibt [objekt Objekt] aus

NEWS

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    16
    1
    247

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

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

[GELÖST] Skript gibt [objekt Objekt] aus

Scheduled Pinned Locked Moved JavaScript
javascript
51 Posts 6 Posters 5.0k Views 4 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.
  • CodierknechtC Codierknecht

    @fischi87
    Du liest z.B. in Zeile 51 den Namen über getObject(id).
    In Zeile 53 willst Du den gleich weiter verarbeiten.

    getObject() liest aber asynchron.
    Das heißt, in Zeile 53 ist name noch gar nicht besetzt. Das asynchrone Lesen ist da nämlich mit ziemlicher Sicherheit noch gar nicht fertig.

    @ticaki meint das vermutlich so (Code ab Zeile 49):

        cacheSelectorState.each(function (id, i) { 
            const obj = await getObjectAsync(id);
            if (obj && obj.common) {
                let oName = obj.common.name;
            }
    
    paul53P Offline
    paul53P Offline
    paul53
    wrote on last edited by
    #24

    @codierknecht sagte: getObject() liest aber asynchron.

    getObject(id) liest synchron, wenn keine Callback-Funktion übergeben wird.

    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

    CodierknechtC fischi87F 2 Replies Last reply
    0
    • paul53P paul53

      @codierknecht sagte: getObject() liest aber asynchron.

      getObject(id) liest synchron, wenn keine Callback-Funktion übergeben wird.

      CodierknechtC Offline
      CodierknechtC Offline
      Codierknecht
      Developer Most Active
      wrote on last edited by
      #25

      @paul53
      Ich sag' ja: An dem synchron/synchron Kram verzweifle ich noch :-(

      "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." (Martin Fowler, "Refactoring")

      Proxmox 9.1.1 LXC|8 GB|Core i7-6700
      HmIP|ZigBee|Tasmota|Unifi
      Zabbix Certified Specialist
      Konnte ich Dir helfen? Dann benutze bitte das Voting unten rechts im Beitrag

      haus-automatisierungH 1 Reply Last reply
      0
      • CodierknechtC Codierknecht

        @paul53
        Ich sag' ja: An dem synchron/synchron Kram verzweifle ich noch :-(

        haus-automatisierungH Online
        haus-automatisierungH Online
        haus-automatisierung
        Developer Most Active
        wrote on last edited by haus-automatisierung
        #26

        @codierknecht sagte in Skript gibt [objekt Objekt] aus:

        An dem synchron/synchron Kram verzweifle ich noch

        Ich verwende einfach immer die ...Async-Funktionen. Dann kann ich sicher sein, dass ich ein Promise zurückbekomme und kann damit dann halt mit await oder .then() weitermachen... Callbacks sind ja irgendwie retro und führen nur zu stark verschachteltem Code.

        🧑‍🎓 Autor des beliebten ioBroker-Master-Kurses
        🎥 Tutorials rund um das Thema DIY-Smart-Home: https://haus-automatisierung.com/
        📚 Meine inoffizielle ioBroker Dokumentation

        CodierknechtC 1 Reply Last reply
        0
        • haus-automatisierungH haus-automatisierung

          @codierknecht sagte in Skript gibt [objekt Objekt] aus:

          An dem synchron/synchron Kram verzweifle ich noch

          Ich verwende einfach immer die ...Async-Funktionen. Dann kann ich sicher sein, dass ich ein Promise zurückbekomme und kann damit dann halt mit await oder .then() weitermachen... Callbacks sind ja irgendwie retro und führen nur zu stark verschachteltem Code.

          CodierknechtC Offline
          CodierknechtC Offline
          Codierknecht
          Developer Most Active
          wrote on last edited by Codierknecht
          #27

          @haus-automatisierung sagte in Skript gibt [objekt Objekt] aus:

          Ich verwende einfach immer die ...Async-Funktionen

          Ich ja mittlerweile auch.

          Was aber auch daran liegen mag, dass ich das ganze Konzept noch immer nicht verinnerlicht habe.
          Ich komme halt aus der Windows-Welt. Und da muss man Klimmzüge machen, um etwas asynchron hinzukriegen und nicht, um etwas synchron ablaufen zu lassen.

          "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." (Martin Fowler, "Refactoring")

          Proxmox 9.1.1 LXC|8 GB|Core i7-6700
          HmIP|ZigBee|Tasmota|Unifi
          Zabbix Certified Specialist
          Konnte ich Dir helfen? Dann benutze bitte das Voting unten rechts im Beitrag

          1 Reply Last reply
          0
          • paul53P paul53

            @codierknecht sagte: getObject() liest aber asynchron.

            getObject(id) liest synchron, wenn keine Callback-Funktion übergeben wird.

            fischi87F Offline
            fischi87F Offline
            fischi87
            wrote on last edited by
            #28

            @paul53

            also müsste es so laufen wie im ersten post? jetzt bin ich verwirrt!

            paul53P haus-automatisierungH 2 Replies Last reply
            0
            • fischi87F fischi87

              @paul53

              also müsste es so laufen wie im ersten post? jetzt bin ich verwirrt!

              paul53P Offline
              paul53P Offline
              paul53
              wrote on last edited by
              #29

              @fischi87 sagte also müsste es so laufen wie im ersten post?

              Nicht ganz (Zeilen 50, 51)

                      var obj = getObject(id);
                      var name = getObject(id).common;
              

              Richtig:

                      var name = getObject(id).common.name;
                      if(typeof name == 'object') name = name.de;
              

              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

              fischi87F 1 Reply Last reply
              0
              • fischi87F fischi87

                @paul53

                also müsste es so laufen wie im ersten post? jetzt bin ich verwirrt!

                haus-automatisierungH Online
                haus-automatisierungH Online
                haus-automatisierung
                Developer Most Active
                wrote on last edited by
                #30

                @fischi87 sagte in Skript gibt [objekt Objekt] aus:

                also müsste es so laufen wie im ersten post?

                War wohl etwas viel Offtopic hier, aber fehlt Dir hier? https://forum.iobroker.net/topic/72999/skript-gibt-objekt-objekt-aus/17

                🧑‍🎓 Autor des beliebten ioBroker-Master-Kurses
                🎥 Tutorials rund um das Thema DIY-Smart-Home: https://haus-automatisierung.com/
                📚 Meine inoffizielle ioBroker Dokumentation

                1 Reply Last reply
                0
                • paul53P paul53

                  @fischi87 sagte also müsste es so laufen wie im ersten post?

                  Nicht ganz (Zeilen 50, 51)

                          var obj = getObject(id);
                          var name = getObject(id).common;
                  

                  Richtig:

                          var name = getObject(id).common.name;
                          if(typeof name == 'object') name = name.de;
                  
                  fischi87F Offline
                  fischi87F Offline
                  fischi87
                  wrote on last edited by
                  #31

                  @paul53

                  Sind denn da die Fehlermeldung bei .push und .sort auch behoben oder liegt die dann an einem anderen fehler?

                  Danke dir erstmal.

                  Ich glaube die Antwort auf die Frage nach dem „wie ist es richtig“ bzw „wie ist es am korrektesten“ wird man wohl nie beantworten können?

                  paul53P haus-automatisierungH 2 Replies Last reply
                  0
                  • fischi87F fischi87

                    @paul53

                    Sind denn da die Fehlermeldung bei .push und .sort auch behoben oder liegt die dann an einem anderen fehler?

                    Danke dir erstmal.

                    Ich glaube die Antwort auf die Frage nach dem „wie ist es richtig“ bzw „wie ist es am korrektesten“ wird man wohl nie beantworten können?

                    paul53P Offline
                    paul53P Offline
                    paul53
                    wrote on last edited by paul53
                    #32

                    @fischi87
                    Zur Überschrift: Zeile 68

                        if (logging) log("Text: " + textUpdateAn);
                    

                    zeigt "Text: [objekt Objekt]", da textUpdateAn ein Array enthält. Entweder

                        if (logging) log("Text: " + JSON.stringify(textUpdateAn));
                    

                    oder

                        if (logging) log(textUpdateAn);
                    

                    @fischi87 sagte in Skript gibt [objekt Objekt] aus:

                    Sind denn da die Fehlermeldung bei .push und .sort auch behoben

                    Ich sehe im ersten Post keinen Grund, weshalb es nicht funktionieren sollte.

                    EDIT: Durch falsch gewählte Variablenbezeichner (textUpdateAn) kann man sich auch selbst verwirren.

                    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

                    fischi87F 1 Reply Last reply
                    0
                    • fischi87F fischi87

                      @paul53

                      Sind denn da die Fehlermeldung bei .push und .sort auch behoben oder liegt die dann an einem anderen fehler?

                      Danke dir erstmal.

                      Ich glaube die Antwort auf die Frage nach dem „wie ist es richtig“ bzw „wie ist es am korrektesten“ wird man wohl nie beantworten können?

                      haus-automatisierungH Online
                      haus-automatisierungH Online
                      haus-automatisierung
                      Developer Most Active
                      wrote on last edited by haus-automatisierung
                      #33

                      @fischi87 Habe mir jetzt das ganze Script nochmal angeschaut. Dein Problem ist .each und async. Das geht so nicht.

                      const logging = true;
                       
                      const idbutton = 'shelly.0.info.update';
                       
                      const idAnzahlAn = 'javascript.0.Status.Shelly.UpdateFirmware.An';
                      const idAnzahl = 'javascript.0.Status.Shelly.UpdateFirmware.Anzahl';
                      const idText = 'javascript.0.Status.Shelly.UpdateFirmware.Text';
                      const iddatenpunkt = 'javascript.0.Status.Shelly.UpdateFirmware.State';
                       
                      createState(idAnzahl, { // wenn benötigt: Anzahl der vorhandenen Lichter
                          type: 'number',
                          name: 'Anzahl aller Geräte',
                          min: 0,
                          def: 0,
                          role: 'value'
                      });
                      createState(idAnzahlAn, { // Anzahl der Lichter, die auf sind als Variable unter Javascript.0 anlegen
                          type: 'number',
                          name: 'Anzahl Update',
                          min: 0,
                          def: 0,
                          role: 'value'
                      });
                      createState(idText, { // Anzahl der brennenden Lichter und deren Namen als Variable unter Javascript.0 anlegen
                          type: 'string',
                          name: 'Eingeschaltete Update',
                          desc: 'Namen der Update Geräte',
                          def: ' ',
                          role: 'value'
                      });
                      createState(iddatenpunkt, {
                          type: 'boolean',
                          name: 'State',
                          role: '',
                          read: true,
                          write: false,
                          def: false
                      });
                      
                      const cacheSelectorState = $('shelly.0.*[state.id=*.firmware]');
                      
                      async function checkDevices() {
                          let anzahlUpdateAn = 0;
                          let anzahlUpdate = 0;
                          const textUpdateAn = [];
                       
                          for (const id of cacheSelectorState) {
                              const obj = await getObjectAsync(id);
                              const oName = typeof obj.common.name === 'object' ? obj.common.name.de : obj.common.name;
                              const state = await getStateAsync(id).val;
                       
                              if (state.val) { 
                                  anzahlUpdateAn++;
                                  textUpdateAn.push(oName); 
                              }
                              anzahlUpdate++;
                       
                              setState(iddatenpunkt, anzahlUpdateAn > 0, true);
                          }
                       
                          textUpdateAn.sort();
                       
                          if (logging) log(`Text: ${JSON.stringify(textUpdateAn)}`);
                          if (logging) log(`Anzahl Geräte: ${anzahlUpdate} # davon: ${anzahlUpdateAn} Updaten`);
                      
                          setState(idText, textUpdateAn.join(',<br>')); 
                          setState(idAnzahlAn, textUpdateAn.length); 
                          setState(idAnzahl, anzahlUpdate); 
                       
                          if (anzahlUpdateAn > 0 ) {
                              sendTo('telegram.0', {
                                  text: `+++ Geräte Update +++\n\n + ${textUpdateAn.join(', ')}`,
                                  reply_markup: {
                                      keyboard: [['System', 'Heizung'], ['Licht', 'Strom'], ['Multimedia', 'Szenen'], ['Home']],
                                      resize_keyboard: true,
                                      one_time_keyboard: true
                                  }
                              });
                          }
                      }
                      
                      // Trigger
                      cacheSelectorState.on(checkDevices);
                      
                      function main() {
                          setTimeout(() => {
                              if (logging) {
                                  log('Auslöser Skriptstart');
                              }
                      
                              checkDevices();
                          }, 2000);
                      }
                      
                      function button() { 
                          setTimeout(() => {
                              setState(idbutton, false);
                          }, 200);
                      }
                      
                      on(idbutton, (dp) => {
                          if (dp.state.val) {
                              button();
                          }
                      });
                      
                      main(); // Skriptstart-Auslöser
                      

                      🧑‍🎓 Autor des beliebten ioBroker-Master-Kurses
                      🎥 Tutorials rund um das Thema DIY-Smart-Home: https://haus-automatisierung.com/
                      📚 Meine inoffizielle ioBroker Dokumentation

                      paul53P fischi87F 4 Replies Last reply
                      0
                      • haus-automatisierungH haus-automatisierung

                        @fischi87 Habe mir jetzt das ganze Script nochmal angeschaut. Dein Problem ist .each und async. Das geht so nicht.

                        const logging = true;
                         
                        const idbutton = 'shelly.0.info.update';
                         
                        const idAnzahlAn = 'javascript.0.Status.Shelly.UpdateFirmware.An';
                        const idAnzahl = 'javascript.0.Status.Shelly.UpdateFirmware.Anzahl';
                        const idText = 'javascript.0.Status.Shelly.UpdateFirmware.Text';
                        const iddatenpunkt = 'javascript.0.Status.Shelly.UpdateFirmware.State';
                         
                        createState(idAnzahl, { // wenn benötigt: Anzahl der vorhandenen Lichter
                            type: 'number',
                            name: 'Anzahl aller Geräte',
                            min: 0,
                            def: 0,
                            role: 'value'
                        });
                        createState(idAnzahlAn, { // Anzahl der Lichter, die auf sind als Variable unter Javascript.0 anlegen
                            type: 'number',
                            name: 'Anzahl Update',
                            min: 0,
                            def: 0,
                            role: 'value'
                        });
                        createState(idText, { // Anzahl der brennenden Lichter und deren Namen als Variable unter Javascript.0 anlegen
                            type: 'string',
                            name: 'Eingeschaltete Update',
                            desc: 'Namen der Update Geräte',
                            def: ' ',
                            role: 'value'
                        });
                        createState(iddatenpunkt, {
                            type: 'boolean',
                            name: 'State',
                            role: '',
                            read: true,
                            write: false,
                            def: false
                        });
                        
                        const cacheSelectorState = $('shelly.0.*[state.id=*.firmware]');
                        
                        async function checkDevices() {
                            let anzahlUpdateAn = 0;
                            let anzahlUpdate = 0;
                            const textUpdateAn = [];
                         
                            for (const id of cacheSelectorState) {
                                const obj = await getObjectAsync(id);
                                const oName = typeof obj.common.name === 'object' ? obj.common.name.de : obj.common.name;
                                const state = await getStateAsync(id).val;
                         
                                if (state.val) { 
                                    anzahlUpdateAn++;
                                    textUpdateAn.push(oName); 
                                }
                                anzahlUpdate++;
                         
                                setState(iddatenpunkt, anzahlUpdateAn > 0, true);
                            }
                         
                            textUpdateAn.sort();
                         
                            if (logging) log(`Text: ${JSON.stringify(textUpdateAn)}`);
                            if (logging) log(`Anzahl Geräte: ${anzahlUpdate} # davon: ${anzahlUpdateAn} Updaten`);
                        
                            setState(idText, textUpdateAn.join(',<br>')); 
                            setState(idAnzahlAn, textUpdateAn.length); 
                            setState(idAnzahl, anzahlUpdate); 
                         
                            if (anzahlUpdateAn > 0 ) {
                                sendTo('telegram.0', {
                                    text: `+++ Geräte Update +++\n\n + ${textUpdateAn.join(', ')}`,
                                    reply_markup: {
                                        keyboard: [['System', 'Heizung'], ['Licht', 'Strom'], ['Multimedia', 'Szenen'], ['Home']],
                                        resize_keyboard: true,
                                        one_time_keyboard: true
                                    }
                                });
                            }
                        }
                        
                        // Trigger
                        cacheSelectorState.on(checkDevices);
                        
                        function main() {
                            setTimeout(() => {
                                if (logging) {
                                    log('Auslöser Skriptstart');
                                }
                        
                                checkDevices();
                            }, 2000);
                        }
                        
                        function button() { 
                            setTimeout(() => {
                                setState(idbutton, false);
                            }, 200);
                        }
                        
                        on(idbutton, (dp) => {
                            if (dp.state.val) {
                                button();
                            }
                        });
                        
                        main(); // Skriptstart-Auslöser
                        
                        paul53P Offline
                        paul53P Offline
                        paul53
                        wrote on last edited by
                        #34

                        @haus-automatisierung sagte: Problem ist .each und async.

                        Ich kann im ersten Post kein async entdecken.

                        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
                        • haus-automatisierungH haus-automatisierung

                          @fischi87 Habe mir jetzt das ganze Script nochmal angeschaut. Dein Problem ist .each und async. Das geht so nicht.

                          const logging = true;
                           
                          const idbutton = 'shelly.0.info.update';
                           
                          const idAnzahlAn = 'javascript.0.Status.Shelly.UpdateFirmware.An';
                          const idAnzahl = 'javascript.0.Status.Shelly.UpdateFirmware.Anzahl';
                          const idText = 'javascript.0.Status.Shelly.UpdateFirmware.Text';
                          const iddatenpunkt = 'javascript.0.Status.Shelly.UpdateFirmware.State';
                           
                          createState(idAnzahl, { // wenn benötigt: Anzahl der vorhandenen Lichter
                              type: 'number',
                              name: 'Anzahl aller Geräte',
                              min: 0,
                              def: 0,
                              role: 'value'
                          });
                          createState(idAnzahlAn, { // Anzahl der Lichter, die auf sind als Variable unter Javascript.0 anlegen
                              type: 'number',
                              name: 'Anzahl Update',
                              min: 0,
                              def: 0,
                              role: 'value'
                          });
                          createState(idText, { // Anzahl der brennenden Lichter und deren Namen als Variable unter Javascript.0 anlegen
                              type: 'string',
                              name: 'Eingeschaltete Update',
                              desc: 'Namen der Update Geräte',
                              def: ' ',
                              role: 'value'
                          });
                          createState(iddatenpunkt, {
                              type: 'boolean',
                              name: 'State',
                              role: '',
                              read: true,
                              write: false,
                              def: false
                          });
                          
                          const cacheSelectorState = $('shelly.0.*[state.id=*.firmware]');
                          
                          async function checkDevices() {
                              let anzahlUpdateAn = 0;
                              let anzahlUpdate = 0;
                              const textUpdateAn = [];
                           
                              for (const id of cacheSelectorState) {
                                  const obj = await getObjectAsync(id);
                                  const oName = typeof obj.common.name === 'object' ? obj.common.name.de : obj.common.name;
                                  const state = await getStateAsync(id).val;
                           
                                  if (state.val) { 
                                      anzahlUpdateAn++;
                                      textUpdateAn.push(oName); 
                                  }
                                  anzahlUpdate++;
                           
                                  setState(iddatenpunkt, anzahlUpdateAn > 0, true);
                              }
                           
                              textUpdateAn.sort();
                           
                              if (logging) log(`Text: ${JSON.stringify(textUpdateAn)}`);
                              if (logging) log(`Anzahl Geräte: ${anzahlUpdate} # davon: ${anzahlUpdateAn} Updaten`);
                          
                              setState(idText, textUpdateAn.join(',<br>')); 
                              setState(idAnzahlAn, textUpdateAn.length); 
                              setState(idAnzahl, anzahlUpdate); 
                           
                              if (anzahlUpdateAn > 0 ) {
                                  sendTo('telegram.0', {
                                      text: `+++ Geräte Update +++\n\n + ${textUpdateAn.join(', ')}`,
                                      reply_markup: {
                                          keyboard: [['System', 'Heizung'], ['Licht', 'Strom'], ['Multimedia', 'Szenen'], ['Home']],
                                          resize_keyboard: true,
                                          one_time_keyboard: true
                                      }
                                  });
                              }
                          }
                          
                          // Trigger
                          cacheSelectorState.on(checkDevices);
                          
                          function main() {
                              setTimeout(() => {
                                  if (logging) {
                                      log('Auslöser Skriptstart');
                                  }
                          
                                  checkDevices();
                              }, 2000);
                          }
                          
                          function button() { 
                              setTimeout(() => {
                                  setState(idbutton, false);
                              }, 200);
                          }
                          
                          on(idbutton, (dp) => {
                              if (dp.state.val) {
                                  button();
                              }
                          });
                          
                          main(); // Skriptstart-Auslöser
                          
                          fischi87F Offline
                          fischi87F Offline
                          fischi87
                          wrote on last edited by
                          #35

                          @haus-automatisierung

                          Soviele Wege :-)

                          Das ist echt viel Input. Hab noch paar solche Skripte die eigentlich laufen aber wenn ich das jetzt sehe mit 100% Wahrscheinlichkeit auch nicht richtig sind.

                          Danke euch erstmal, werd heut Abend Erfolg oder Misserfolg vermelden!

                          1 Reply Last reply
                          0
                          • paul53P paul53

                            @fischi87
                            Zur Überschrift: Zeile 68

                                if (logging) log("Text: " + textUpdateAn);
                            

                            zeigt "Text: [objekt Objekt]", da textUpdateAn ein Array enthält. Entweder

                                if (logging) log("Text: " + JSON.stringify(textUpdateAn));
                            

                            oder

                                if (logging) log(textUpdateAn);
                            

                            @fischi87 sagte in Skript gibt [objekt Objekt] aus:

                            Sind denn da die Fehlermeldung bei .push und .sort auch behoben

                            Ich sehe im ersten Post keinen Grund, weshalb es nicht funktionieren sollte.

                            EDIT: Durch falsch gewählte Variablenbezeichner (textUpdateAn) kann man sich auch selbst verwirren.

                            fischi87F Offline
                            fischi87F Offline
                            fischi87
                            wrote on last edited by
                            #36

                            @paul53

                            Was meinst du selber verwirren? Ich möchte die Geräte ausgeben die ein verfügbares Update haben. Wie meinst du das? Wie im Skript lass ich mir das auch als Telegram Nachricht senden, da bekomme ich auch nur [objekt Objekt] ausgegeben. Also nicht nur im log?!

                            paul53P 1 Reply Last reply
                            0
                            • haus-automatisierungH haus-automatisierung

                              @fischi87 Habe mir jetzt das ganze Script nochmal angeschaut. Dein Problem ist .each und async. Das geht so nicht.

                              const logging = true;
                               
                              const idbutton = 'shelly.0.info.update';
                               
                              const idAnzahlAn = 'javascript.0.Status.Shelly.UpdateFirmware.An';
                              const idAnzahl = 'javascript.0.Status.Shelly.UpdateFirmware.Anzahl';
                              const idText = 'javascript.0.Status.Shelly.UpdateFirmware.Text';
                              const iddatenpunkt = 'javascript.0.Status.Shelly.UpdateFirmware.State';
                               
                              createState(idAnzahl, { // wenn benötigt: Anzahl der vorhandenen Lichter
                                  type: 'number',
                                  name: 'Anzahl aller Geräte',
                                  min: 0,
                                  def: 0,
                                  role: 'value'
                              });
                              createState(idAnzahlAn, { // Anzahl der Lichter, die auf sind als Variable unter Javascript.0 anlegen
                                  type: 'number',
                                  name: 'Anzahl Update',
                                  min: 0,
                                  def: 0,
                                  role: 'value'
                              });
                              createState(idText, { // Anzahl der brennenden Lichter und deren Namen als Variable unter Javascript.0 anlegen
                                  type: 'string',
                                  name: 'Eingeschaltete Update',
                                  desc: 'Namen der Update Geräte',
                                  def: ' ',
                                  role: 'value'
                              });
                              createState(iddatenpunkt, {
                                  type: 'boolean',
                                  name: 'State',
                                  role: '',
                                  read: true,
                                  write: false,
                                  def: false
                              });
                              
                              const cacheSelectorState = $('shelly.0.*[state.id=*.firmware]');
                              
                              async function checkDevices() {
                                  let anzahlUpdateAn = 0;
                                  let anzahlUpdate = 0;
                                  const textUpdateAn = [];
                               
                                  for (const id of cacheSelectorState) {
                                      const obj = await getObjectAsync(id);
                                      const oName = typeof obj.common.name === 'object' ? obj.common.name.de : obj.common.name;
                                      const state = await getStateAsync(id).val;
                               
                                      if (state.val) { 
                                          anzahlUpdateAn++;
                                          textUpdateAn.push(oName); 
                                      }
                                      anzahlUpdate++;
                               
                                      setState(iddatenpunkt, anzahlUpdateAn > 0, true);
                                  }
                               
                                  textUpdateAn.sort();
                               
                                  if (logging) log(`Text: ${JSON.stringify(textUpdateAn)}`);
                                  if (logging) log(`Anzahl Geräte: ${anzahlUpdate} # davon: ${anzahlUpdateAn} Updaten`);
                              
                                  setState(idText, textUpdateAn.join(',<br>')); 
                                  setState(idAnzahlAn, textUpdateAn.length); 
                                  setState(idAnzahl, anzahlUpdate); 
                               
                                  if (anzahlUpdateAn > 0 ) {
                                      sendTo('telegram.0', {
                                          text: `+++ Geräte Update +++\n\n + ${textUpdateAn.join(', ')}`,
                                          reply_markup: {
                                              keyboard: [['System', 'Heizung'], ['Licht', 'Strom'], ['Multimedia', 'Szenen'], ['Home']],
                                              resize_keyboard: true,
                                              one_time_keyboard: true
                                          }
                                      });
                                  }
                              }
                              
                              // Trigger
                              cacheSelectorState.on(checkDevices);
                              
                              function main() {
                                  setTimeout(() => {
                                      if (logging) {
                                          log('Auslöser Skriptstart');
                                      }
                              
                                      checkDevices();
                                  }, 2000);
                              }
                              
                              function button() { 
                                  setTimeout(() => {
                                      setState(idbutton, false);
                                  }, 200);
                              }
                              
                              on(idbutton, (dp) => {
                                  if (dp.state.val) {
                                      button();
                                  }
                              });
                              
                              main(); // Skriptstart-Auslöser
                              
                              fischi87F Offline
                              fischi87F Offline
                              fischi87
                              wrote on last edited by
                              #37

                              @haus-automatisierung

                              Wofür ist dieses Zeichen? Bzw was besagt oder besser wo ist der Unterschied ohne?

                              =>
                              
                              1 Reply Last reply
                              0
                              • fischi87F fischi87

                                @paul53

                                Was meinst du selber verwirren? Ich möchte die Geräte ausgeben die ein verfügbares Update haben. Wie meinst du das? Wie im Skript lass ich mir das auch als Telegram Nachricht senden, da bekomme ich auch nur [objekt Objekt] ausgegeben. Also nicht nur im log?!

                                paul53P Offline
                                paul53P Offline
                                paul53
                                wrote on last edited by
                                #38

                                @fischi87 sagte: Telegram Nachricht senden, da bekomme ich auch nur [objekt Objekt]

                                Ja, weil auch dort ein Array in textUpdateAn übergeben wird.

                                @fischi87 sagte in Skript gibt [objekt Objekt] aus:

                                Was meinst du selber verwirren?

                                Wenn eine Variable textUpdateAn bezeichnet ist, erwartet man einen String und kein Array - wie die Verwendung für Telegram zeigt.

                                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

                                fischi87F 1 Reply Last reply
                                0
                                • paul53P paul53

                                  @fischi87 sagte: Telegram Nachricht senden, da bekomme ich auch nur [objekt Objekt]

                                  Ja, weil auch dort ein Array in textUpdateAn übergeben wird.

                                  @fischi87 sagte in Skript gibt [objekt Objekt] aus:

                                  Was meinst du selber verwirren?

                                  Wenn eine Variable textUpdateAn bezeichnet ist, erwartet man einen String und kein Array - wie die Verwendung für Telegram zeigt.

                                  fischi87F Offline
                                  fischi87F Offline
                                  fischi87
                                  wrote on last edited by
                                  #39

                                  @paul53

                                  Wie würdest du diese benennen damit man weiß es ist ein Array? Nur zum Verständnis

                                  paul53P 1 Reply Last reply
                                  0
                                  • fischi87F fischi87

                                    @paul53

                                    Wie würdest du diese benennen damit man weiß es ist ein Array? Nur zum Verständnis

                                    paul53P Offline
                                    paul53P Offline
                                    paul53
                                    wrote on last edited by paul53
                                    #40

                                    @fischi87 sagte: Wie würdest du diese benennen damit man weiß es ist ein Array?

                                    Siehe Funktion checkDevices(). Ersatz für Zeilen 42 bis 86 (erster Post):

                                    const idsUpdate = $('shelly.0.*.firmware'); 
                                    setState(idAnzahl, idsUpdate.length, true); 
                                     
                                    function checkDevices() {
                                        const arrUpdate = [];
                                        idsUpdate.each(function (id) { 
                                            if(getState(id).val) { 
                                                let name = getObject(id).common.name;
                                                if(typeof name == 'object') name = name.de;
                                                arrUpdate.push(name); 
                                            }
                                        });
                                    
                                        arrUpdate.sort();
                                        const anzahlUpdateAn = arrUpdate.length;
                                        setState(iddatenpunkt, anzahlUpdateAn > 0, true);
                                        const textUpdateAn = arrUpdate.join(', ');
                                     
                                        if (logging) log("Text: " + textUpdateAn);
                                        if (logging) log(`Anzahl Geräte: ${idsUpdate.length} # davon: ${anzahlUpdateAn} Updaten`);
                                        setState(idText, arrUpdate.join(',<br>'), true); 
                                        setState(idAnzahlAn, anzahlUpdateAn, true); 
                                     
                                        if (anzahlUpdateAn > 0 ) {
                                            sendTo('telegram.0', {
                                                text:   '+++ Geräte Update +++' +
                                                    '\n' +
                                                    '\n' + textUpdateAn,
                                                reply_markup: {
                                                    keyboard: [['System','Heizung'],['Licht','Strom'],['Multimedia','Szenen'],['Home']],
                                                    resize_keyboard: true,
                                                    one_time_keyboard: true
                                                }
                                            });
                                        }
                                    }
                                    

                                    In Zeile 17 wird das Array in einen Text gewandelt.

                                    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
                                    • haus-automatisierungH haus-automatisierung

                                      @fischi87 Habe mir jetzt das ganze Script nochmal angeschaut. Dein Problem ist .each und async. Das geht so nicht.

                                      const logging = true;
                                       
                                      const idbutton = 'shelly.0.info.update';
                                       
                                      const idAnzahlAn = 'javascript.0.Status.Shelly.UpdateFirmware.An';
                                      const idAnzahl = 'javascript.0.Status.Shelly.UpdateFirmware.Anzahl';
                                      const idText = 'javascript.0.Status.Shelly.UpdateFirmware.Text';
                                      const iddatenpunkt = 'javascript.0.Status.Shelly.UpdateFirmware.State';
                                       
                                      createState(idAnzahl, { // wenn benötigt: Anzahl der vorhandenen Lichter
                                          type: 'number',
                                          name: 'Anzahl aller Geräte',
                                          min: 0,
                                          def: 0,
                                          role: 'value'
                                      });
                                      createState(idAnzahlAn, { // Anzahl der Lichter, die auf sind als Variable unter Javascript.0 anlegen
                                          type: 'number',
                                          name: 'Anzahl Update',
                                          min: 0,
                                          def: 0,
                                          role: 'value'
                                      });
                                      createState(idText, { // Anzahl der brennenden Lichter und deren Namen als Variable unter Javascript.0 anlegen
                                          type: 'string',
                                          name: 'Eingeschaltete Update',
                                          desc: 'Namen der Update Geräte',
                                          def: ' ',
                                          role: 'value'
                                      });
                                      createState(iddatenpunkt, {
                                          type: 'boolean',
                                          name: 'State',
                                          role: '',
                                          read: true,
                                          write: false,
                                          def: false
                                      });
                                      
                                      const cacheSelectorState = $('shelly.0.*[state.id=*.firmware]');
                                      
                                      async function checkDevices() {
                                          let anzahlUpdateAn = 0;
                                          let anzahlUpdate = 0;
                                          const textUpdateAn = [];
                                       
                                          for (const id of cacheSelectorState) {
                                              const obj = await getObjectAsync(id);
                                              const oName = typeof obj.common.name === 'object' ? obj.common.name.de : obj.common.name;
                                              const state = await getStateAsync(id).val;
                                       
                                              if (state.val) { 
                                                  anzahlUpdateAn++;
                                                  textUpdateAn.push(oName); 
                                              }
                                              anzahlUpdate++;
                                       
                                              setState(iddatenpunkt, anzahlUpdateAn > 0, true);
                                          }
                                       
                                          textUpdateAn.sort();
                                       
                                          if (logging) log(`Text: ${JSON.stringify(textUpdateAn)}`);
                                          if (logging) log(`Anzahl Geräte: ${anzahlUpdate} # davon: ${anzahlUpdateAn} Updaten`);
                                      
                                          setState(idText, textUpdateAn.join(',<br>')); 
                                          setState(idAnzahlAn, textUpdateAn.length); 
                                          setState(idAnzahl, anzahlUpdate); 
                                       
                                          if (anzahlUpdateAn > 0 ) {
                                              sendTo('telegram.0', {
                                                  text: `+++ Geräte Update +++\n\n + ${textUpdateAn.join(', ')}`,
                                                  reply_markup: {
                                                      keyboard: [['System', 'Heizung'], ['Licht', 'Strom'], ['Multimedia', 'Szenen'], ['Home']],
                                                      resize_keyboard: true,
                                                      one_time_keyboard: true
                                                  }
                                              });
                                          }
                                      }
                                      
                                      // Trigger
                                      cacheSelectorState.on(checkDevices);
                                      
                                      function main() {
                                          setTimeout(() => {
                                              if (logging) {
                                                  log('Auslöser Skriptstart');
                                              }
                                      
                                              checkDevices();
                                          }, 2000);
                                      }
                                      
                                      function button() { 
                                          setTimeout(() => {
                                              setState(idbutton, false);
                                          }, 200);
                                      }
                                      
                                      on(idbutton, (dp) => {
                                          if (dp.state.val) {
                                              button();
                                          }
                                      });
                                      
                                      main(); // Skriptstart-Auslöser
                                      
                                      fischi87F Offline
                                      fischi87F Offline
                                      fischi87
                                      wrote on last edited by fischi87
                                      #41

                                      @haus-automatisierung sagte in Skript gibt [objekt Objekt] aus:

                                      hab dein code mal eingefügt, bekomme sehr oft diesen Fehler angezeigt:

                                      Property 'join' does not exist on type 'any[]'
                                      

                                      auch sowas hier:

                                      Cannot redeclare block-scoped variable 'cacheSelectorState'.(2451)
                                      index0.js(72, 5): 'cacheSelectorState' was also declared here.
                                      
                                      paul53P 2 Replies Last reply
                                      0
                                      • fischi87F fischi87

                                        @haus-automatisierung sagte in Skript gibt [objekt Objekt] aus:

                                        hab dein code mal eingefügt, bekomme sehr oft diesen Fehler angezeigt:

                                        Property 'join' does not exist on type 'any[]'
                                        

                                        auch sowas hier:

                                        Cannot redeclare block-scoped variable 'cacheSelectorState'.(2451)
                                        index0.js(72, 5): 'cacheSelectorState' was also declared here.
                                        
                                        paul53P Offline
                                        paul53P Offline
                                        paul53
                                        wrote on last edited by paul53
                                        #42

                                        @fischi87 sagte: auch sowas hier:

                                        Die Variable cacheSelectorState sollte nicht mehr existieren. Poste bitte das komplette Skript.

                                        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

                                        fischi87F 1 Reply Last reply
                                        0
                                        • paul53P paul53

                                          @fischi87 sagte: auch sowas hier:

                                          Die Variable cacheSelectorState sollte nicht mehr existieren. Poste bitte das komplette Skript.

                                          fischi87F Offline
                                          fischi87F Offline
                                          fischi87
                                          wrote on last edited by fischi87
                                          #43

                                          @paul53

                                           var logging = true;
                                           
                                          const idbutton = 'shelly.0.info.update'
                                           
                                          const idAnzahlAn = 'javascript.0.Status.Shelly.UpdateFirmware.An';
                                          const idAnzahl = 'javascript.0.Status.Shelly.UpdateFirmware.Anzahl';
                                          const idText = 'javascript.0.Status.Shelly.UpdateFirmware.Text'
                                          const iddatenpunkt = 'javascript.0.Status.Shelly.UpdateFirmware.State';
                                           
                                          createState(idAnzahl, { // wenn benötigt: Anzahl der vorhandenen Lichter
                                          type: 'number',
                                          name: 'Anzahl aller Geräte',
                                          min: 0,
                                          def: 0,
                                          role: 'value'
                                          });
                                          createState(idAnzahlAn, { // Anzahl der Lichter, die auf sind als Variable unter Javascript.0 anlegen
                                          type: 'number',
                                          name: 'Anzahl Update',
                                          min: 0,
                                          def: 0,
                                          role: 'value'
                                          });
                                          createState(idText, { // Anzahl der brennenden Lichter und deren Namen als Variable unter Javascript.0 anlegen
                                          type: 'string',
                                          name: 'Eingeschaltete Update',
                                          desc: 'Namen der Update Geräte',
                                          def: ' ',
                                          role: 'value'
                                          });
                                          createState(iddatenpunkt, {
                                          name: "State",
                                          role: "",
                                          type: "boolean",
                                          read: true,
                                          write: true,
                                          desc: "Manuell erzeugt",
                                          def: false
                                          });
                                           
                                           const idsUpdate = $('shelly.0.*.firmware'); 
                                          setState(idAnzahl, idsUpdate.length, true); 
                                           
                                          function checkDevices() {
                                              const arrUpdate = [];
                                              idsUpdate.each(function (id) { 
                                                  if(getState(id).val) { 
                                                      let name = getObject(id).common.name;
                                                      if(typeof name == 'object') name = name.de;
                                                      arrUpdate.push(name); 
                                                  }
                                              });
                                           
                                              arrUpdate.sort();
                                              const anzahlUpdateAn = arrUpdate.length;
                                              setState(iddatenpunkt, anzahlUpdateAn > 0, true);
                                              const textUpdateAn = arrUpdate.join(', ');
                                           
                                              if (logging) log("Text: " + textUpdateAn);
                                              if (logging) log(`Anzahl Geräte: ${idsUpdate.length} # davon: ${anzahlUpdateAn} Updaten`);
                                              setState(idText, arrUpdate.join(',<br>'), true); 
                                              setState(idAnzahlAn, anzahlUpdateAn, true); 
                                           
                                              if (anzahlUpdateAn > 0 ) {
                                                  sendTo('telegram.0', {
                                                      text:   '+++ Geräte Update +++' +
                                                          '\n' +
                                                          '\n' + textUpdateAn,
                                                      reply_markup: {
                                                          keyboard: [['System','Heizung'],['Licht','Strom'],['Multimedia','Szenen'],['Home']],
                                                          resize_keyboard: true,
                                                          one_time_keyboard: true
                                                      }
                                                  });
                                              }
                                          }
                                           
                                           
                                          // Trigger
                                          cacheSelectorState.on(function(obj) { 
                                              if (logging) log('Auslösendes Gerät: ' + obj.id + ': ' + obj.state.val); 
                                              checkDevices();
                                          });
                                           
                                          function main() {
                                              setTimeout(function(){
                                                  if (logging) log('Auslöser Skriptstart');
                                                  checkDevices();
                                              }, 2000);
                                          };
                                           
                                          function button() { 
                                              setTimeout(function(){
                                                       setState(idbutton,false);
                                                  }, 200);
                                          }
                                           
                                          on(idbutton, function(dp) {
                                              if(dp.state.val) {
                                                  button();
                                              }
                                          });
                                           
                                          main(); // Skriptstart-Auslöser
                                          

                                          ist auch noch ein trigger mit cachesSelector in Zeile 80.?

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          246

                                          Online

                                          32.7k

                                          Users

                                          82.5k

                                          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