Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • 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

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. Array nach Preisen sortiert mit Startzeit aus Tibberconnect

NEWS

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    5
    1
    53

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    4.2k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    1.2k

Array nach Preisen sortiert mit Startzeit aus Tibberconnect

Scheduled Pinned Locked Moved JavaScript
5 Posts 2 Posters 683 Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • paul53P Offline
    paul53P Offline
    paul53
    wrote on last edited by paul53
    #1

    @babl
    Gemäß Deinem Wunsch, ein nach Preisen sortiertes Array zu erhalten, in dessen Objekten auch die Startzeit enthalten ist, schlage ich folgendes Skript vor. Es soll die Preise und Startstunden für heute 17:00 Uhr bis morgen 16:00 Uhr liefern (hoffe ich). Format:

    [{start: 4, preis: 0.24}, {start: 3, preis: 0.25}, ...]
    
    const tibber = 'tibberconnect.0.Homes.ffXXX.'; // Anpassen!
    const idSort = '0_userdata.0.Tibber.Preise.sortiert'; // DP-Typ: "array"
    
    function sortPreis(a, b) {
        return a.preis - b.preis;
    }
    
    schedule('57 16 * * *', function() {
        const preise = [];
        for(let i = 17; i < 24; i++) {
            let obj = {};
            let idStart = tibber + 'PricesToday.' + i + '.startsAt';
            let idPreis = tibber + 'PricesToday.' + i + '.total';
            obj.start = new Date(getState(idStart).val).getHours();
            obj.preis = getState(idPreis).val;
            preise.push(obj);
        }
        for(let i = 0; i < 17; i++) {
            let obj = {};
            let idStart = tibber + 'PricesTomorrow.' + i + '.startsAt';
            let idPreis = tibber + 'PricesTomorrow.' + i + '.total';
            obj.start = new Date(getState(idStart).val).getHours();
            obj.preis = getState(idPreis).val;
            preise.push(obj);
        }
        preise.sort(sortPreis);
        setState(idSort, preise, true);
    });
    

    Das Skript ist nicht getestet, da keine Datenpunkte vorhanden.
    Das Array im Datenpunkt lässt sich auch mit Blockly weiter verarbeiten.

    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

    arteckA 1 Reply Last reply
    1
    • paul53P paul53

      @babl
      Gemäß Deinem Wunsch, ein nach Preisen sortiertes Array zu erhalten, in dessen Objekten auch die Startzeit enthalten ist, schlage ich folgendes Skript vor. Es soll die Preise und Startstunden für heute 17:00 Uhr bis morgen 16:00 Uhr liefern (hoffe ich). Format:

      [{start: 4, preis: 0.24}, {start: 3, preis: 0.25}, ...]
      
      const tibber = 'tibberconnect.0.Homes.ffXXX.'; // Anpassen!
      const idSort = '0_userdata.0.Tibber.Preise.sortiert'; // DP-Typ: "array"
      
      function sortPreis(a, b) {
          return a.preis - b.preis;
      }
      
      schedule('57 16 * * *', function() {
          const preise = [];
          for(let i = 17; i < 24; i++) {
              let obj = {};
              let idStart = tibber + 'PricesToday.' + i + '.startsAt';
              let idPreis = tibber + 'PricesToday.' + i + '.total';
              obj.start = new Date(getState(idStart).val).getHours();
              obj.preis = getState(idPreis).val;
              preise.push(obj);
          }
          for(let i = 0; i < 17; i++) {
              let obj = {};
              let idStart = tibber + 'PricesTomorrow.' + i + '.startsAt';
              let idPreis = tibber + 'PricesTomorrow.' + i + '.total';
              obj.start = new Date(getState(idStart).val).getHours();
              obj.preis = getState(idPreis).val;
              preise.push(obj);
          }
          preise.sort(sortPreis);
          setState(idSort, preise, true);
      });
      

      Das Skript ist nicht getestet, da keine Datenpunkte vorhanden.
      Das Array im Datenpunkt lässt sich auch mit Blockly weiter verarbeiten.

      arteckA Offline
      arteckA Offline
      arteck
      Developer Most Active
      wrote on last edited by
      #2

      @paul53 bin auf dein script gestossen

      in Zeile 26

      preise.sort(sortPreis);
      

      in der funktion sind aber 2 parameter

      function sortPreis(a, b) {
          return a.preis - b.preis;
      }
      

      zigbee hab ich, zwave auch, nuc's genauso und HA auch

      paul53P 1 Reply Last reply
      0
      • arteckA arteck

        @paul53 bin auf dein script gestossen

        in Zeile 26

        preise.sort(sortPreis);
        

        in der funktion sind aber 2 parameter

        function sortPreis(a, b) {
            return a.preis - b.preis;
        }
        
        paul53P Offline
        paul53P Offline
        paul53
        wrote on last edited by paul53
        #3

        @arteck sagte: in Zeile 26

        Das ist eine Funktionsreferenz für die Javascriptfunktion array.sort().

        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

        arteckA 1 Reply Last reply
        0
        • paul53P paul53

          @arteck sagte: in Zeile 26

          Das ist eine Funktionsreferenz für die Javascriptfunktion array.sort().

          arteckA Offline
          arteckA Offline
          arteck
          Developer Most Active
          wrote on last edited by arteck
          #4

          @paul53 das kannst du auch so schreiben

          preise.sort(function(a, b) {
                  return a.preis - b.preis;
              });
          

          übrigends funktionert gut

          zigbee hab ich, zwave auch, nuc's genauso und HA auch

          paul53P 1 Reply Last reply
          0
          • arteckA arteck

            @paul53 das kannst du auch so schreiben

            preise.sort(function(a, b) {
                    return a.preis - b.preis;
                });
            

            übrigends funktionert gut

            paul53P Offline
            paul53P Offline
            paul53
            wrote on last edited by
            #5

            @arteck sagte: das kannst du auch so schreiben

            Richtig.

            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 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            Support us

            ioBroker
            Community Adapters
            Donate

            579

            Online

            32.7k

            Users

            82.4k

            Topics

            1.3m

            Posts
            Community
            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
            ioBroker Community 2014-2025
            logo
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Home
            • Recent
            • Tags
            • Unread 0
            • Categories
            • Unreplied
            • Popular
            • GitHub
            • Docu
            • Hilfe