Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Visualisierung
    4. [gelöst] Lovelace Apexchart data_generator aus JSON

    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] Lovelace Apexchart data_generator aus JSON

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

      Hallo!

      Ich versuche verzweifelt mit der Apexchart-card mittels data_generator Daten darzustellen.
      Die Daten kommen aus dem Awattar Adapter im JSON Format.

      Hier im Forum hat es @copystring schon geschafft zukünftige Daten auf dem PV-Forecast Adapter darzustellen. (https://forum.iobroker.net/topic/45315/test-pv-forecast-adapter/440?_=1719822087869)

      Die Daten aus dem Awattar Adapter sehen so aus:

      {
        "object": "list",
        "data": [
          {
            "start_timestamp": 1719698400000,
            "end_timestamp": 1719702000000,
            "marketprice": 59.94,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719702000000,
            "end_timestamp": 1719705600000,
            "marketprice": 58.4,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719705600000,
            "end_timestamp": 1719709200000,
            "marketprice": 61.27,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719709200000,
            "end_timestamp": 1719712800000,
            "marketprice": 61.66,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719712800000,
            "end_timestamp": 1719716400000,
            "marketprice": 59.58,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719716400000,
            "end_timestamp": 1719720000000,
            "marketprice": 47.97,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719720000000,
            "end_timestamp": 1719723600000,
            "marketprice": 43.05,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719723600000,
            "end_timestamp": 1719727200000,
            "marketprice": 18.9,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719727200000,
            "end_timestamp": 1719730800000,
            "marketprice": 6.83,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719730800000,
            "end_timestamp": 1719734400000,
            "marketprice": 0.82,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719734400000,
            "end_timestamp": 1719738000000,
            "marketprice": 0,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719738000000,
            "end_timestamp": 1719741600000,
            "marketprice": 0,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719741600000,
            "end_timestamp": 1719745200000,
            "marketprice": -0.02,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719745200000,
            "end_timestamp": 1719748800000,
            "marketprice": -1.56,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719748800000,
            "end_timestamp": 1719752400000,
            "marketprice": -1.13,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719752400000,
            "end_timestamp": 1719756000000,
            "marketprice": 0,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719756000000,
            "end_timestamp": 1719759600000,
            "marketprice": 0.94,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719759600000,
            "end_timestamp": 1719763200000,
            "marketprice": 39.72,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719763200000,
            "end_timestamp": 1719766800000,
            "marketprice": 63.23,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719766800000,
            "end_timestamp": 1719770400000,
            "marketprice": 74.98,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719770400000,
            "end_timestamp": 1719774000000,
            "marketprice": 80.77,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719774000000,
            "end_timestamp": 1719777600000,
            "marketprice": 88.98,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719777600000,
            "end_timestamp": 1719781200000,
            "marketprice": 97.47,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719781200000,
            "end_timestamp": 1719784800000,
            "marketprice": 89.44,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719784800000,
            "end_timestamp": 1719788400000,
            "marketprice": 91.94,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719788400000,
            "end_timestamp": 1719792000000,
            "marketprice": 81.79,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719792000000,
            "end_timestamp": 1719795600000,
            "marketprice": 74.6,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719795600000,
            "end_timestamp": 1719799200000,
            "marketprice": 73.35,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719799200000,
            "end_timestamp": 1719802800000,
            "marketprice": 70.93,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719802800000,
            "end_timestamp": 1719806400000,
            "marketprice": 74.95,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719806400000,
            "end_timestamp": 1719810000000,
            "marketprice": 85.91,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719810000000,
            "end_timestamp": 1719813600000,
            "marketprice": 113.66,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719813600000,
            "end_timestamp": 1719817200000,
            "marketprice": 123.86,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719817200000,
            "end_timestamp": 1719820800000,
            "marketprice": 97.41,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719820800000,
            "end_timestamp": 1719824400000,
            "marketprice": 95.95,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719824400000,
            "end_timestamp": 1719828000000,
            "marketprice": 78.05,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719828000000,
            "end_timestamp": 1719831600000,
            "marketprice": 74.31,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719831600000,
            "end_timestamp": 1719835200000,
            "marketprice": 74.45,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719835200000,
            "end_timestamp": 1719838800000,
            "marketprice": 70.94,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719838800000,
            "end_timestamp": 1719842400000,
            "marketprice": 69.46,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719842400000,
            "end_timestamp": 1719846000000,
            "marketprice": 70.98,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719846000000,
            "end_timestamp": 1719849600000,
            "marketprice": 85.97,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719849600000,
            "end_timestamp": 1719853200000,
            "marketprice": 87.95,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719853200000,
            "end_timestamp": 1719856800000,
            "marketprice": 90.91,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719856800000,
            "end_timestamp": 1719860400000,
            "marketprice": 90.03,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719860400000,
            "end_timestamp": 1719864000000,
            "marketprice": 105.04,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719864000000,
            "end_timestamp": 1719867600000,
            "marketprice": 108.26,
            "unit": "Eur/MWh"
          },
          {
            "start_timestamp": 1719867600000,
            "end_timestamp": 1719871200000,
            "marketprice": 88.77,
            "unit": "Eur/MWh"
          }
        ],
        "url": "/at/v1/marketdata"
      }
      

      Meine Versuche den Code von @copystring an das o.g. JSON anzupassen, schlugen leider alle fehl.
      zB

      type: custom:apexcharts-card
      graph_span: 2d
      span:
        start: day
      series:
        - entity: sensor.awattar_full
          type: column
          data_generator: |
            var data = [];
            var formattedJSON = JSON.parse(entity.state);
            console.log(formattedJSON);
            formattedJSON.forEach(obj => {
              data.push([obj.start_timestamp, obj.marketprice])
            });
            return data;
      

      In der js console kommt dann immer der Fehler 'Error: formattedJSON.forEach is not a function'

      Ich bin mir fast sicher das ich nur eine Kleinigkeit falsch mache.
      Kann mir jemand weiterhelfen?

      Schöne Grüße!

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

        @fhainz sagte: Die Daten aus dem Awattar Adapter sehen so aus:

        Die Schleife muss über ein Array laufen. Ändere mal Zeile 10 in

              var formattedJSON = JSON.parse(entity.state).data;
        
        fhainz 1 Reply Last reply Reply Quote 1
        • fhainz
          fhainz @paul53 last edited by

          @paul53
          Super, vielen Dank! Jetzt funktioniert es natürlich.

          apexChartAwattar.jpg

          type: custom:apexcharts-card
          experimental:
            color_threshold: true
          graph_span: 2day
          update_interval: 2m
          now:
            show: true
            label: Jetzt
            color: gray
          span:
            offset: +0day
            start: day
          yaxis:
            - id: primary
              decimals: 0
              min: 0
          header:
            show: true
            title: Strom Preis Verlauf - Heute & Morgen
            show_states: true
            colorize_states: true
          all_series_config:
            color_threshold:
              - value: -100
                color: green
              - value: 5
                color: orange
              - value: 10
                color: red
            unit: ct/kWh
            type: line
            stroke_width: 0
            show:
              legend_value: false
              in_header: true
              header_color_threshold: true
          series:
            - entity: sensor.awattar_full
              type: column
              name: Aktuell
              show:
                extremas: true
                in_header: before_now
              data_generator: |
                var data = [];
                var formattedJSON = JSON.parse(entity.state).data;
                console.log(formattedJSON);
                formattedJSON.forEach(obj => {
                  data.push([obj.start_timestamp, (obj.marketprice/10*1.2)])
                });
                return data;
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          903
          Online

          31.9k
          Users

          80.2k
          Topics

          1.3m
          Posts

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