Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. Daten mit Blockly erheben und im Json Format speichern

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    Daten mit Blockly erheben und im Json Format speichern

    This topic has been deleted. Only users with topic management privileges can see it.
    • david83
      david83 last edited by david83

      Hallo zusammen,
      Ich bin dabei mir ein Blockly zu schreiben, das Adapter findet die offline sind. Dafür nutze ich den Daten-Punkt .alive . wenn dieser false ist, wird der Adapter vom Blockly als Json Datensatz in einem Datenpunkt hinterlegt. Nun kann ich mir mit Vis alle Daten in der Tabelle anzeigen lassen.

      Bis dahin funktioniert das Blockly einwandfrei.

      Nun der Teil der mich verzweifeln lässt:
      Sobald der Adapter wieder online ist und der Wert auf true steht, wird der Eintrag nicht wie von mir beabsichtigt entfernt. Dies klappt nur sporadisch.
      Das Problem wird die Angabe des Zeitstempels sein. Wie könnte ich das besser lösen? Jemand einen Tipp?

      Screenshot_2022-07-07-14-20-49-05_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

      Screenshot_2022-07-07-14-39-48-67_200b0a05dbc45b1de60d6a2da09c9fd1.jpg

      Screenshot_2022-07-07-14-41-32-84_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

      haus-automatisierung 1 Reply Last reply Reply Quote 0
      • haus-automatisierung
        haus-automatisierung Developer Most Active @david83 last edited by

        @david83 Also JSON manuell zusammen bauen würde ich eher nicht empfehlen. Du kannst ja scheinbar auch JavaScript - damit wäre das deutlich einfacher machbar. Brauchst Du dazu Input?

        1 Reply Last reply Reply Quote 0
        • david83
          david83 last edited by

          @haus-automatisierung

          Ganz ehrlich gesagt bin ich grade dabei mir Javascript etwas genauer anzuschauen. Aber können... da bin ich Meilen von entfernt.
          Ich würde das gerne mit Blockly lösen, falls du einen Vorschlag in Js hast, schaue ich ihn mir sehr gerne an.

          haus-automatisierung 2 Replies Last reply Reply Quote 0
          • haus-automatisierung
            haus-automatisierung Developer Most Active @david83 last edited by haus-automatisierung

            @david83 Ich bin mir nicht ganz sicher, wie das Ergebnis aussehen soll. Aber eventuell hilft Dir das ja als Basis:

            const aliveIds = Array.prototype.slice.apply($('system.adapter.*.*.alive'));
            
            function refreshList() {
                const resultList = [];
            
                for (var i in aliveIds) {
                    const aliveState = getState(aliveIds[i]);
            
                    // Offline instance
                    if (!aliveState.val) {
                        resultList.push({
                            'Adapter': aliveIds[i],
                            'Last-Contact': formatDate(aliveState.ts, 'TT.MM.JJJJ SS:mm:ss')
                        });
                    }
            
                    console.log(aliveState);
                }
            
                setState('0_userdata.0.test.myString', JSON.stringify(resultList), true);
            }
            
            on({id: aliveIds, change: 'ne'}, async (obj) => {
                refreshList();
            });
            
            // Initialisieren bei Script-Start
            refreshList();
            
            
            1 Reply Last reply Reply Quote 0
            • haus-automatisierung
              haus-automatisierung Developer Most Active @david83 last edited by

              @david83 Oder Du holst Dir noch den richtigen Namen des Adapters und packst den in die Tabelle:

              const aliveIds = Array.prototype.slice.apply($('system.adapter.*.*.alive'));
              
              function getAdapterName(obj) {
                  if (typeof obj.common.titleLang === 'object') {
                      if (Object.prototype.hasOwnProperty.call(obj.common.titleLang, 'de')) {
                          return obj.common.titleLang.de;
                      } else {
                          return obj.common.titleLang.en;
                      }
                  }
              
                  return obj.common.title;
              }
              
              function refreshList() {
                  const resultList = [];
              
                  for (var i in aliveIds) {
                      const aliveStateId = aliveIds[i];
                      const aliveState = getState(aliveStateId);
              
                      // Offline adapters
                      if (!aliveState.val) {
                          const instanceObj = getObject(aliveStateId.replace('.alive', ''));
              
                          resultList.push({
                              'Adapter': getAdapterName(instanceObj),
                              'Last-Contact': formatDate(aliveState.ts, 'TT.MM.JJJJ SS:mm:ss')
                          });
                      }
              
                      console.log(aliveState);
                  }
              
                  setState('0_userdata.0.test.myString', JSON.stringify(resultList), true);
              }
              
              on({id: aliveIds, change: 'ne'}, async (obj) => {
                  refreshList();
              });
              
              // Initialisieren bei Script-Start
              refreshList();
              
              
              david83 1 Reply Last reply Reply Quote 0
              • david83
                david83 @haus-automatisierung last edited by

                @haus-automatisierung

                funktioniert! Danke!

                [
                  {
                    "Adapter": "Alexa2 (Amazon Echo)",
                    "Last-Contact": "07.07.2022 09:59:48"
                  },
                  {
                    "Adapter": "Device-Watcher",
                    "Last-Contact": "07.07.2022 18:45:01"
                  },
                  {
                    "Adapter": "Deutsche Feiertage",
                    "Last-Contact": "07.07.2022 10:36:11"
                  },
                  {
                    "Adapter": "iCal Kalender",
                    "Last-Contact": "07.07.2022 18:30:12"
                  },
                  {
                    "Adapter": "Tankerkönig Spritpreise",
                    "Last-Contact": "10.07.2021 15:24:51"
                  },
                  {
                    "Adapter": "Visualisierung",
                    "Last-Contact": "07.07.2022 10:35:52"
                  },
                  {
                    "Adapter": "Vorhersage Weatherunderground",
                    "Last-Contact": "07.07.2022 18:06:33"
                  }
                ]
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post

                Support us

                ioBroker
                Community Adapters
                Donate

                674
                Online

                32.0k
                Users

                80.5k
                Topics

                1.3m
                Posts

                2
                6
                352
                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