Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gel.] Werte aus influxdb2 holen und in anderen DP schreiben

    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.] Werte aus influxdb2 holen und in anderen DP schreiben

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

      @marc-berg,

      Hallo, obwohl ich den thread auf gelöst gesetzt habe, würde ich Dich gerne nochmal ansprechen zu einem Problem:

      Mit diesem Script will ich alle Daten eines "measurements" holen und nach einem Vergleich in einen anderen DP schreiben:

      function loeschen () {
                              sendTo('influxdb.0', 'deleteAll', [
                                  {id: '0_userdata.0.Wetterstation_Korrektur_temp_DP.Wind_max_clean'}
                              ], result => console.log('deleted'));
                          }
      
      
      function holen () {
                              sendTo('influxdb.0', 'getHistory', {
                              id: '0_userdata.0.Wetterstation.Wind_max',
                              options: {
                                  start:      Date.now()-30*24*60*60*1000,
                                  end:        Date.now(),
                                  aggregate: 'onchange',
                                  addId: true
                              }
                          }, function (result) {
                              for (var i = 0; i < result.result.length; i++) {
                          //        console.log(result.result[i].val + result.result[i].id + ' ' + new Date(result.result[i].ts).toISOString());
                                  if  (result.result[i].val <= 50)
                                      {
                                          sendTo('influxdb.0', 'storeState', {
                                              id: '0_userdata.0.Wetterstation_Korrektur_temp_DP.Wind_max_clean',
                                              state: {ts: result.result[i].ts, val: result.result[i].val}  
                                          }
                                          ) 
                                      };
                                  
                              }
                          })
      }
      
      // loeschen();
      holen();
      

      wobei

      start:    Date.now()-30*24*60*60*1000
      

      nach meinem Verständnis das Datum in ms von vor 30 Tagen sein sollte. Und obwohl aus den letzten 30 Tagen mehrere tausend Werte vorliegen sollten, steht in dem Datenpunkt nur der Wert von gerade eben.
      Unter der Flux-Sprache ist es ja möglich, alle Werte vom ersten, der gespeichert wurde, bis zum letzten zu adressieren.
      Soweit ich den englischen Text dazu beim github-Readme zum influxDB Adapter verstehe, kann dieser aber nur einen begrenzten letzten Zeitraum auslesen.

      Frage: Wie kann ich den gesamten Zeitraum adressieren? Es gibt Werte von etwa 3 Jahren. In denen sind Ausrutscher, die ich einmal herausfiltern und dann die Daten zurückschreiben will. Die Ausrutscher werden inzwischen anders abgefangen - man lernt halt dazu.

      Vielen Dank für Deine Tipps.
      Gruß
      Jo

      1 Reply Last reply Reply Quote 0
      • Marc Berg
        Marc Berg Most Active last edited by

        @xxjooo

        Wie ist deine Instanz hier konfiguriert?

        1942dc75-ded7-4d8b-988c-dc453a814a15-grafik.png

        XxJooO 1 Reply Last reply Reply Quote 0
        • XxJooO
          XxJooO @Marc Berg last edited by

          @marc-berg,

          hm, bei mir ist es so:

          cbadf04b-143e-48a1-87cc-3ffc36e1184d-image.png

          Also umstellen?

          1 Reply Last reply Reply Quote 0
          • Marc Berg
            Marc Berg Most Active last edited by

            @xxjooo sagte in [gel.] Werte aus influxdb2 holen und in anderen DP schreiben:

            Also umstellen?

            nein, das passt so. Nicht umstellen, war nur 'ne Vermutung. Ich habe aber keine Idee, warum bei dir nicht die korrekten Ergebnisse kommen.

            Vielleicht mal mit einer "Custom Query" versuchen?

            https://github.com/ioBroker/ioBroker.influxdb#influx-2x

            XxJooO 1 Reply Last reply Reply Quote 0
            • XxJooO
              XxJooO @Marc Berg last edited by

              @marc-berg ,

              hmhhh, sehr ärgerlich das... Ich würde unterstellen, dass diese Abfrage richtig formuliert ist:

                              sendTo('influxdb.0', 'query','from(bucket: "iobroker")\
                                                                              |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\
                                                                              |> filter(fn: (r) => r["_measurement"] == "0_userdata.0.Wetterstation.Wind_max"'
                                                                              
                                                      , function (result) {
                                                      for (var i = 0; i < result.result.length; i++) {
                                                  //        console.log(result.result[i].val + result.result[i].id + ' ' + new Date(result.result[i].ts).toISOString());
                                                          if  (result.result[i].val <= 50)
                                                              {
                                                                  sendTo('influxdb.0', 'storeState', {
                                                                      id: '0_userdata.0.Wetterstation_Korrektur_temp_DP.Wind_max_clean',
                                                  /*                  state: {ts: result.result[i].ts, val: result.result[i].val, ack: true, q: result.result[i].q, from: result.result[i].from}  */
                                                                      state: {ts: result.result[i].ts, val: result.result[i].val}  
                                                                  }
                                                                  ) 
                                                              };
                                                          
                                                      }
                                                  })
              

              Im Log taucht dazu allerdings ein Fehler auf, mit dem ich leider nichts anfangen kann:

              
              influxdb.0
              2024-05-05 14:27:45.219	error	queries: Error: 1 Error happened while processing 1 queries
              
              influxdb.0
              2024-05-05 14:27:45.218	warn	Error in query "from(bucket: "iobroker") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "0_userdata.0.Wetterstation.Wind_max"": HttpError: compilation failed: error @1:86-1:162: expected RPAREN, got EOF
              
              Marc Berg 1 Reply Last reply Reply Quote 0
              • Marc Berg
                Marc Berg Most Active @XxJooO last edited by Marc Berg

                @xxjooo sagte in [gel.] Werte aus influxdb2 holen und in anderen DP schreiben:

                Im Log taucht dazu allerdings ein Fehler auf, mit dem ich leider nichts anfangen kann

                Es fehlt die abschließende Klammer (die hinter "filter" geöffnet wird). Außerdem kann in dieser Abfrage v.timeRangeStart / v.timeRangeStop nicht interpretiert werden. Da musst du schon konkrete Zeitangaben reinschreiben.

                EDIT: und ob die

                "\"
                

                da drin funktionieren, weiß ich auch nicht, aus meiner Sicht können die weg. Ob Umbrüche in der Query drin sind oder nicht, ist egal.

                XxJooO 1 Reply Last reply Reply Quote 0
                • XxJooO
                  XxJooO @Marc Berg last edited by

                  @marc-berg ,

                  ok, er hat mir die fehlende Klammer nicht moniert. Start habe ich mit 0 gesetzt. Jetzt ändert er mir auch den Fehler im Log. Kannst Du mir noch gerade sagen, welchen Wert ich für stop eingebe, wenn ich bis jetzt die Werte holen will. Habe mittlerweise soviele google Fenster auf, dass ich den Wald nicht mehr sehe...

                  👍

                  Lieben Dank

                  Marc Berg 1 Reply Last reply Reply Quote 0
                  • Marc Berg
                    Marc Berg Most Active @XxJooO last edited by

                    @xxjooo sagte in [gel.] Werte aus influxdb2 holen und in anderen DP schreiben:

                    ok, er hat mir die fehlende Klammer nicht moniert.

                    Doch 🙂

                    expected RPAREN
                    

                    Start habe ich mit 0 gesetzt. Jetzt ändert er mir auch den Fehler im Log. Kannst Du mir noch gerade sagen, welchen Wert ich für stop eingebe, wenn ich bis jetzt die Werte holen will.

                    now()
                    

                    (oder alternativ einfach weglassen)

                    XxJooO 1 Reply Last reply Reply Quote 0
                    • XxJooO
                      XxJooO @Marc Berg last edited by

                      @marc-berg

                      Ok, jetzt habe ich es so:

                                      sendTo('influxdb.0', 'query','from(bucket: "iobroker")\
                                                                      |> range(start: 0)\
                                                                      |> filter(fn: (r) => r["_measurement"] == "0_userdata.0.Wetterstation.Wind_max")\
                                                                      |> filter(fn: (r) => r["_field"] == "value")'
                                                                      
                                              , function (result) {
                                              for (var i = 0; i < result.result.length; i++) {
                                                 console.log(result.result[i].val + result.result[i].id + ' ' + new Date(result.result[i].ts).toISOString());
                                                  if  (result.result[i].val <= 50)
                                                      {
                                                          sendTo('influxdb.0', 'storeState', {
                                                              id: '0_userdata.0.Wetterstation_Korrektur_temp_DP.Wind_max_clean',
                                          /*                  state: {ts: result.result[i].ts, val: result.result[i].val, ack: true, q: result.result[i].q, from: result.result[i].from}  */
                                                              state: {ts: result.result[i].ts, val: result.result[i].val}  
                                                          }
                                                          ) 
                                                      };
                                                  
                                              }
                                          })
                      

                      Offensichtlich passiert jetzt was, aber es kommt ein wüster Fehler im Log. Entscheidend ist wahrscheinlich, dass er die ganzen Werte nicht zwischenspeichern kann (Zeile 38). Jetzt bin ich ratlos.

                      Die Maschine läuft unter Proxmox. Vielleicht muss ich mal versuchen, der mehr als 8GB RAM zu geben. Das ganze muss ja nur einmal laufen, damit ich die falschen Werte eliminieren kann. Leider habe ich eine ganze Reihe von DP mit falschen Werten, auf die ich das anwenden müsste. Vielleicht hast Du einen Tipp, was Du anders machen würdest?

                      Vielen Dank für eine letzte Antwort. Für heute bin ich erst mal raus.

                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.642	warn	instance system.adapter.influxdb.0 terminated due to SIGABRT
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.642	error	Caught by controller[12]: 17: 0x1710839 [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.642	error	Caught by controller[11]: 16: 0xdf7d57 v8::internal::Builtin_JsonStringify(int, unsigned long*, v8::internal::Isolate*) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.642	error	Caught by controller[10]: 15: 0x1064bff v8::internal::JsonStringify(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.642	error	Caught by controller[9]: 14: 0x10631b3 v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.641	error	Caught by controller[8]: 13: 0x105e500 v8::internal::JsonStringifier::SerializeString(v8::internal::Handle<v8::internal::String>) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.641	error	Caught by controller[7]: 12: 0x1349265 v8::internal::IncrementalStringBuilder::Extend() [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.641	error	Caught by controller[6]: 11: 0xf17868 v8::internal::FactoryBase<v8::internal::Factory>::NewRawOneByteString(int, v8::internal::AllocationType) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.641	error	Caught by controller[5]: 10: 0xf155b4 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.641	error	Caught by controller[4]: 9: 0xf1db40 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.641	error	Caught by controller[3]: 8: 0xf3d5c7 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.641	error	Caught by controller[3]: 7: 0xf3c1fe v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[3]: 6: 0xf61b0d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[3]: 5: 0xf4f635 [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[3]: 4: 0xd72277 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[3]: 3: 0xd71ed0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[3]: 2: 0xaa07ee [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[2]: 1: 0xb9a330 node::Abort() [io.influxdb.0]
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[1]: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[0]: <--- JS stacktrace --->
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[0]: [1702073:0x65d8850] 503081 ms: Mark-sweep (reduce) 2011.1 (2075.4) -> 2011.0 (2076.4) MB, 1019.8 / 0.0 ms (+ 254.1 ms in 48 steps since start of marking, biggest step 27.0 ms, walltime since start of marking 1491 ms) (average mu = 0.851, current mu = 0
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.640	error	Caught by controller[0]: [1702073:0x65d8850] 502004 ms: Scavenge (reduce) 2010.2 (2074.4) -> 2010.1 (2075.4) MB, 48.0 / 0.0 ms (average mu = 0.940, current mu = 0.926) allocation failure;
                      host.ioBrokerDebian10VM
                      2024-05-05 15:41:03.639	error	Caught by controller[0]: <--- Last few GCs --->
                      
                      
                      javascript.0
                      2024-05-05 15:40:40.747	error	at processTimers (node:internal/timers:512:7)
                      
                      javascript.0
                      2024-05-05 15:40:40.747	error	at listOnTimeout (node:internal/timers:569:17)
                      
                      javascript.0
                      2024-05-05 15:40:40.747	error	at Timeout._onTimeout (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:2901:38)
                      
                      javascript.0
                      2024-05-05 15:40:40.747	error	at Object.<anonymous> (script.js.Datenpunkte_erstellen.test2:7:59)
                      
                      javascript.0
                      2024-05-05 15:40:40.746	error	Error in callback: TypeError: Cannot read properties of undefined (reading 'length')
                      
                      Marc Berg 1 Reply Last reply Reply Quote 0
                      • Marc Berg
                        Marc Berg Most Active @XxJooO last edited by

                        @xxjooo sagte in [gel.] Werte aus influxdb2 holen und in anderen DP schreiben:

                        Vielleicht hast Du einen Tipp, was Du anders machen würdest?

                        Ja, habe/hatte ich :

                        @marc-berg sagte in [gel.] Werte aus influxdb2 holen und in anderen DP schreiben:

                        grundsätzlich könnte man das Ergebnis auch mit einer reinen FLUX Query erreichen, ohne Script

                        Hier mal ein Beispiel, musst du nur noch den Filter anpassen, der die die "bösen" Werte rauswirft:

                        influx query 'from(bucket:"iobroker")
                         |> range(start:-10y)
                         |> filter(fn: (r) => r._measurement == "0_userdata.0.Wetterstation.Wind_max" and r._value <= 100)
                         |> set(key: "_measurement", value: "0_userdata.0.Wetterstation.Wind_max_clean")
                         |> to(bucket: "iobroker")'
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        386
                        Online

                        31.8k
                        Users

                        80.0k
                        Topics

                        1.3m
                        Posts

                        2
                        13
                        481
                        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