Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [GELÖST] Skript gibt [objekt Objekt] aus

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

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

    • ioBroker goes Matter ... Matter Adapter in Stable

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

    This topic has been deleted. Only users with topic management privileges can see it.
    • fischi87
      fischi87 @haus-automatisierung last edited by

      @haus-automatisierung

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

      =>
      
      1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @fischi87 last edited by

        @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.

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

          @paul53

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

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

            @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.

            1 Reply Last reply Reply Quote 0
            • fischi87
              fischi87 @haus-automatisierung last edited by 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.
              
              paul53 2 Replies Last reply Reply Quote 0
              • paul53
                paul53 @fischi87 last edited by paul53

                @fischi87 sagte: auch sowas hier:

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

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

                  @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 Reply Quote 0
                  • paul53
                    paul53 @fischi87 last edited by

                    @fischi87
                    Ändere Zeile 80 in

                    idsUpdate.on(function(obj) {
                    
                    fischi87 1 Reply Last reply Reply Quote 0
                    • fischi87
                      fischi87 @paul53 last edited by fischi87

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

                      idsUpdate.on(function(obj) {

                      okay das funktioniert zumindest bekomme ich kein Objekt mehr aber dieses .push und .sort und .lengh ist immer noch rot?!

                      ausserdem bekomme ich nur "Neue Firmware verfügbar" angezeigt und nicht den Namen des Gerätes:

                      Bildschirmfoto 2024-02-26 um 21.35.14.png

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

                        @fischi87 sagte: .push und .sort und .lengh ist immer noch rot?!

                        Im Editor? Das wundert mich, da in meinem Editor nicht. Das kann man oft ignorieren.

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

                        ausserdem bekomme ich nur "Neue Firmware verfügbar" angezeigt und nicht den Namen des Gerätes:

                        Wo findet man den Namen des Gerätes (ID-Struktur zeigen)?
                        Wenn es im übergeordneten Objekt ist, dann ergänze die Änderung der ID in parent-ID:

                                if(getState(id).val) {
                                    id = id.substring(0, id.lastIndexOf('.')); // parent-ID
                                    let name = getObject(id).common.name;
                                    if(typeof name == 'object') name = name.de;
                                    arrUpdate.push(name); 
                                }
                        
                        fischi87 1 Reply Last reply Reply Quote 0
                        • fischi87
                          fischi87 @paul53 last edited by

                          @paul53

                          okay. das wundert mich jetzt aber auch da es verwundert aber okay danke

                          Bildschirmfoto 2024-02-26 um 21.41.02.png

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

                            @fischi87
                            Ergänze um die Änderung der ID in parent-ID (2. Zeile einfügen):

                                    if(getState(id).val) {
                                        id = id.substring(0, id.lastIndexOf('.')); // parent-ID
                                        let name = getObject(id).common.name;
                                        if(typeof name == 'object') name = name.de;
                                        arrUpdate.push(name); 
                                    }
                            
                            fischi87 1 Reply Last reply Reply Quote 0
                            • fischi87
                              fischi87 @paul53 last edited by

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

                              id = id.substring(0, id.lastIndexOf('.')); // parent-ID

                              weil du es halt kannst, super läuft jetzt bekomme zwar wieder rote Linien:

                              Property 'lastIndexOf' does not exist on type 'string'
                              

                              aber funktioniert.

                              vielen dank

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

                                @fischi87 sagte: wieder rote Linien:

                                Kann ich bei mir nicht nachvollziehen.

                                Blockly_temp.JPG

                                Keine roten Schlangenlinien.

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

                                  @paul53

                                  Bildschirmfoto 2024-02-26 um 21.52.28.png

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

                                  Support us

                                  ioBroker
                                  Community Adapters
                                  Donate

                                  911
                                  Online

                                  31.8k
                                  Users

                                  80.0k
                                  Topics

                                  1.3m
                                  Posts

                                  javascript
                                  6
                                  51
                                  2143
                                  Loading More Posts
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  Community
                                  Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                  The ioBroker Community 2014-2023
                                  logo