Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • 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

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Visualisierung
  4. [gelöst] Lovelace Apexchart data_generator aus JSON

NEWS

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

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

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    25
    1
    2.5k

[gelöst] Lovelace Apexchart data_generator aus JSON

Geplant Angeheftet Gesperrt Verschoben Visualisierung
3 Beiträge 2 Kommentatoren 559 Aufrufe 1 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • fhainzF Offline
    fhainzF Offline
    fhainz
    schrieb am zuletzt editiert von fhainz
    #1

    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!

    paul53P 1 Antwort Letzte Antwort
    0
    • fhainzF 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!

      paul53P Offline
      paul53P Offline
      paul53
      schrieb am zuletzt editiert von paul53
      #2

      @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;
      

      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

      fhainzF 1 Antwort Letzte Antwort
      1
      • paul53P 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;
        
        fhainzF Offline
        fhainzF Offline
        fhainz
        schrieb am zuletzt editiert von
        #3

        @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 Antwort Letzte Antwort
        0
        Antworten
        • In einem neuen Thema antworten
        Anmelden zum Antworten
        • Älteste zuerst
        • Neuste zuerst
        • Meiste Stimmen


        Support us

        ioBroker
        Community Adapters
        Donate

        387

        Online

        32.7k

        Benutzer

        82.4k

        Themen

        1.3m

        Beiträge
        Community
        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
        ioBroker Community 2014-2025
        logo
        • Anmelden

        • Du hast noch kein Konto? Registrieren

        • Anmelden oder registrieren, um zu suchen
        • Erster Beitrag
          Letzter Beitrag
        0
        • Home
        • Aktuell
        • Tags
        • Ungelesen 0
        • Kategorien
        • Unreplied
        • Beliebt
        • GitHub
        • Docu
        • Hilfe