Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Wie Script ändern damit neuster Eintrag als erstes ist?

    NEWS

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

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    Wie Script ändern damit neuster Eintrag als erstes ist?

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

      Ist es möglich das folgende Script so zuändern, das der neuste Eintrag als erstes und nicht als letztes im JSON ist?

      const idTable = '0_userdata.0.JSON.Spülmaschiene'; // ID JSON-Tabelle
      // const idStatus = 'homeconnect.0.011040388898000963.status.BSH_Common_Status_OperationState';
      // const idProg = 'homeconnect.0.011040388898000963.programs.selected.BSH_Common_Root_SelectedProgram';
      const idAktiv = 'homeconnect.0.011040388898000963.programs.active.BSH_Common_Root_ActiveProgram';
      const idVerbrauch = 'sonoff.0.Spuehlmaschine.ENERGY_Total';
      
      var table = [];
      if(getState(idTable).val) table = JSON.parse(getState(idTable).val);
      var obj = {};
      var StartVerbrauch = getState(idVerbrauch).val;
      var startDate = new Date();
      var endDate   = new Date();
      var Zeit;
      
      on(idAktiv, function(dp) {
          if(dp.state.val) {
              obj = {};
              obj.Start = formatDate(new Date(), 'MM.DD.YY hh:mm');
              obj.StartUhr = formatDate(new Date(), 'hh:mm'); 
              obj.Programm = dp.common.states[dp.state.val];
              StartVerbrauch = getState(idVerbrauch).val;
              startDate = new Date();
              
          } else {
              obj.Ende = formatDate(new Date(), 'MM.DD.YY hh:mm');
              obj.EndeUhr = formatDate(new Date(), 'hh:mm');
              obj.Verbrauch = getState(idVerbrauch).val - StartVerbrauch;
              endDate   = new Date();
              const timeDiff = getDateObject(endDate).getTime() - getDateObject(startDate).getTime();
              obj.Dauer = formatDate(timeDiff, 'hh:mm');
              log(table);
              table.push(obj);
              if(table.length > 100) table.shift();
              setState(idTable, JSON.stringify(table), true);
              log(table);
          }
      });
      
      
      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Chris76e last edited by

        @chris76e sagte: neuste Eintrag als erstes

        Zeilen 32, 33

                table.unshift(obj);
                if(table.length > 100) table.pop();
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post

        Support us

        ioBroker
        Community Adapters
        Donate

        768
        Online

        32.1k
        Users

        80.6k
        Topics

        1.3m
        Posts

        2
        2
        117
        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