Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • 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

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
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

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.7k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.2k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    3.1k

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

Geplant Angeheftet Gesperrt Verschoben JavaScript
javascript
51 Beiträge 6 Kommentatoren 4.5k Aufrufe 4 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • 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
    schrieb am zuletzt editiert von
    #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 Antworten Letzte Antwort
    0
    • paul53P paul53

      @codierknecht sagte: getObject() liest aber asynchron.

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

      CodierknechtC Online
      CodierknechtC Online
      Codierknecht
      Developer Most Active
      schrieb am zuletzt editiert von
      #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 Antwort Letzte Antwort
      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
        schrieb am zuletzt editiert von 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 Antwort Letzte Antwort
        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 Online
          CodierknechtC Online
          Codierknecht
          Developer Most Active
          schrieb am zuletzt editiert von 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 Antwort Letzte Antwort
          0
          • paul53P paul53

            @codierknecht sagte: getObject() liest aber asynchron.

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

            fischi87F Offline
            fischi87F Offline
            fischi87
            schrieb am zuletzt editiert von
            #28

            @paul53

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

            paul53P haus-automatisierungH 2 Antworten Letzte Antwort
            0
            • fischi87F fischi87

              @paul53

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

              paul53P Offline
              paul53P Offline
              paul53
              schrieb am zuletzt editiert von
              #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 Antwort Letzte Antwort
              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
                schrieb am zuletzt editiert von
                #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 Antwort Letzte Antwort
                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
                  schrieb am zuletzt editiert von
                  #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 Antworten Letzte Antwort
                  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
                    schrieb am zuletzt editiert von 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 Antwort Letzte Antwort
                    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
                      schrieb am zuletzt editiert von 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 Antworten Letzte Antwort
                      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
                        schrieb am zuletzt editiert von
                        #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 Antwort Letzte Antwort
                        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
                          schrieb am zuletzt editiert von
                          #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 Antwort Letzte Antwort
                          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
                            schrieb am zuletzt editiert von
                            #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 Antwort Letzte Antwort
                            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
                              schrieb am zuletzt editiert von
                              #37

                              @haus-automatisierung

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

                              =>
                              
                              1 Antwort Letzte Antwort
                              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
                                schrieb am zuletzt editiert von
                                #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 Antwort Letzte Antwort
                                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
                                  schrieb am zuletzt editiert von
                                  #39

                                  @paul53

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

                                  paul53P 1 Antwort Letzte Antwort
                                  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
                                    schrieb am zuletzt editiert von 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 Antwort Letzte Antwort
                                    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
                                      schrieb am zuletzt editiert von 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 Antworten Letzte Antwort
                                      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
                                        schrieb am zuletzt editiert von 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 Antwort Letzte Antwort
                                        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
                                          schrieb am zuletzt editiert von 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 Antwort Letzte Antwort
                                          0
                                          Antworten
                                          • In einem neuen Thema antworten
                                          Anmelden zum Antworten
                                          • Älteste zuerst
                                          • Neuste zuerst
                                          • Meiste Stimmen


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          401

                                          Online

                                          32.4k

                                          Benutzer

                                          81.5k

                                          Themen

                                          1.3m

                                          Beiträge
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Anmelden

                                          • Du hast noch kein Konto? Registrieren

                                          • Anmelden oder registrieren, um zu suchen
                                          • Erster Beitrag
                                            Letzter Beitrag
                                          0
                                          • Home
                                          • Aktuell
                                          • Tags
                                          • Ungelesen 0
                                          • Kategorien
                                          • Unreplied
                                          • Beliebt
                                          • GitHub
                                          • Docu
                                          • Hilfe