Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. [Gelöst] History & JS & Zeitraum

    NEWS

    • Neues Video "KI im Smart Home" - ioBroker plus n8n

    • Neues Video über Aliase, virtuelle Geräte und Kategorien

    • Wir empfehlen: Node.js 22.x

    [Gelöst] History & JS & Zeitraum

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

      Grüß Euch,
      bezogen auf den Beitrag möchte ich ähnliches umsetzen:

      Was auch immer ich versuche, ich schaffe es nicht, sämtliche Werte eines Kanals der letzten 24 Stunden (es sich einige 1000) anzeigen uu lassen

      const end = new Date().getTime();
      //const start = end - (60 * 60 * 24 * 1 * 1000); // letzte 7 Tage;
      const start = end - 8640000
      

      Usecase: Um 23:55 soll das auf die Platte geschrieben werden. Das alles klappt wunderbar, bis auf den Zeitraum

      Zum Beispiel:

      const start = end - 3600000
      

      Letzte Stunde, der Wert mal 24 müsste doch einen ganzen Tag herausfiltern, es wird mir aber nur der Abend gestern angezeigt. Ich verstehe es nicht, wo liege ich falsch?

      Vielen DANK & LG, Andi

      P.S. Hier mein Code

      //schedule1 = schedule('{"time":{"exactTime":true,"start":"09:02"},"period":{"days":1}}', async function () {
      console.log('Start');
      const objId = 'javascript.0.Photovoltaik.Leistung'/*Wchselrichter*/;
      console.log(objId);
      var today = new Date();
      var dd = String(today.getDate()).padStart(2, '0');
      var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
      var yyyy = today.getFullYear();
      
      const fileName = yyyy + '-' + mm + '-' + dd + '-' + objId + '.txt';
      console.log(fileName);
      
      //const fileName = `Solax.csv`;
      const filePath = `/opt/iobroker/iobroker-data/${fileName}`;
      const csvDateFormat = 'DD.MM.YYYY hh:mm:ss';
      
      var fs = require('fs');
       const end = new Date().getTime();
      //const start = end - (60 * 60 * 24 * 1 * 1000); // letzte 7 Tage;
      const start = end - 86400000
      
      console.log('Start: ' + start);
      console.log('End  : ' + end);
      
          getHistory('history.0', {
              id: objId,
              end: end,
              start: start,
              aggregate: 'none',
              timeout: 5000
          }, (err, result) => {
              if (err) {
                  console.error(`History nicht verfügbar ${objId}: ${err}`);
              } else if (result) {
      
                  let csvData = ['timestamp;value'];
                  for (var i = 0; i < result.length; i++) {
                  
                      csvData.push(`${formatDate(new Date(result[i].ts), csvDateFormat)};${result[i].val}`);
      
                  }
                  fs.writeFileSync(filePath, csvData.join("\n"));
      
              }
          });
      console.log('Fertig');
      console.log(objId);
      //});
      
      joergeli 1 Reply Last reply Reply Quote 0
      • joergeli
        joergeli @Gukerl last edited by

        @gukerl
        Hi,

        schau mal hier:
        https://forum.iobroker.net/topic/65767/frage-zum-zeitraum-der-history-adapter-verlaufsdaten?_=1689235522306

        Evtl. trifft das auch bei Dir zu?

        G 1 Reply Last reply Reply Quote 0
        • G
          Gukerl @joergeli last edited by

          @joergeli Das ist es!

          VIELEN VIELEN DANK!!!

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

          Support us

          ioBroker
          Community Adapters
          Donate
          FAQ Cloud / IOT
          HowTo: Node.js-Update
          HowTo: Backup/Restore
          Downloads
          BLOG

          855
          Online

          32.1k
          Users

          80.7k
          Topics

          1.3m
          Posts

          2
          3
          251
          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