Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Node-Red
    5. Gelöst: Wert in dynamische Struktur im ioBroker ablegen

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Gelöst: Wert in dynamische Struktur im ioBroker ablegen

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

      @mickym
      Im Normalfall ist das die optimale Lösung. Ich habe den Fall betrachtet, wenn das System Nachts steht und somit der eine Wert nicht generiert wird. In der nächsten Nacht wird dann ein neuer Wert an die Position des ausgefallenen geschrieben. Das ist nicht Systemkritisch, stört mich einfach, weil der Wert für den entsprechenden Tag nicht stimmt.

      Das scheint aber ein diffiziles Problem zu sein. Aktuell bekomme ich nur Fehler.

      mickym 1 Reply Last reply Reply Quote 0
      • mickym
        mickym Most Active @MartyBr last edited by

        @martybr Wie gesagt - ich würde die Position eines Arrays nicht mit einem bestimmten Tag verknüpfen. Sonst hast Du Lücken und das macht alles kompliziert

        M 1 Reply Last reply Reply Quote 0
        • M
          MartyBr @mickym last edited by

          @mickym
          Ich habe aber ansonsten das Problem, dass ich die Temperaturwerte nicht mit den Heizungswerten verknüpfen kann. Auch die Heizungswerte laufen in Arrays Tagesgenau ein.
          Leider bisher aber in Javascript. Ich versuche ja mit deiner Hilfe die "Programme" in Node-Red umzusetzen.
          Ich habe hier schöne Grafiken, die diese Werte Temperatur Tag x mit dem Energiewert Tag x anzeigen.
          Ich halte die Tagesgenaue Speicherung zu absolut notwendig. Aktuell läuft es mit dem append. Ein Problem tritt ja nur bei einem Serverausfall auf.

          mickym 1 Reply Last reply Reply Quote 0
          • mickym
            mickym Most Active @MartyBr last edited by

            @martybr Gut - wie Du auf einzelne Elemente mittels einer ChangeNode zugreifst, habe ich Dir ja untengepostet.

            Wenn Du programmatisch ein Array mit einer definierten Zahl an Elementen erstellen willst.

            f5b471fd-6e66-4360-b32f-f0561456a9ec-image.png

            [0..payload-1].($:=0)
            
            M mickym 2 Replies Last reply Reply Quote 0
            • M
              MartyBr @mickym last edited by

              @mickym
              Okay, ich setze mich mal dran.
              Danke für deine Geduld.

              1 Reply Last reply Reply Quote 0
              • mickym
                mickym Most Active @mickym last edited by

                So ich habe Dir mal - glaub nach Deinen Wünschen - das mal theoratisch über ChangeNodes implementiert.

                Eingespeist wird eine Temperatur über die Inject Node und über die Change Node habe ich hier mal folgendes gemacht:

                fc5ba300-b800-4d59-9528-91bf7824da12-image.png

                1. Regel - Ermittlung der Anzahhl Tage des aktuellen Monats:
                $moment().endOf("month").date()
                

                Ermittelt die Anzahl der Tage des aktuellen Monats. (Du siehst wie kurz man das anstelle der function Nodes machen kann).

                1. Regel - Erstellt ein Array mit Anzahl Elementen anhand der Tage des aktuellen Monats wird dann durch Einlesen des Datenpunkts ersetzt
                [0..numDaysOfMonth-1].($:=0)
                
                1. Regel - Ermittelt den aktuellen Tag des Monats:
                $moment().date()
                
                1. Regel - Iteriert durch das Array und setzt am Index (da mit 0 beginnt, also an Position 8), die payload.
                $map(array,function($v,$i){$i=dayOfMonth-1 ? payload : $v })
                

                So ich hoffe das hilft Dir weiter:

                [
                   {
                       "id": "b9038fc06bf41c8f",
                       "type": "inject",
                       "z": "7e6af0015415146d",
                       "name": "",
                       "props": [
                           {
                               "p": "payload"
                           }
                       ],
                       "repeat": "",
                       "crontab": "",
                       "once": false,
                       "onceDelay": 0.1,
                       "topic": "",
                       "payload": "20.5",
                       "payloadType": "num",
                       "x": 150,
                       "y": 6720,
                       "wires": [
                           [
                               "d06e37f57f6a9c68"
                           ]
                       ]
                   },
                   {
                       "id": "d06e37f57f6a9c68",
                       "type": "change",
                       "z": "7e6af0015415146d",
                       "name": "",
                       "rules": [
                           {
                               "t": "set",
                               "p": "numDaysOfMonth",
                               "pt": "msg",
                               "to": "$moment().endOf(\"month\").date()",
                               "tot": "jsonata"
                           },
                           {
                               "t": "set",
                               "p": "array",
                               "pt": "msg",
                               "to": "[0..numDaysOfMonth-1].($:=0)",
                               "tot": "jsonata"
                           },
                           {
                               "t": "set",
                               "p": "dayOfMonth",
                               "pt": "msg",
                               "to": "$moment().date()",
                               "tot": "jsonata"
                           },
                           {
                               "t": "set",
                               "p": "payload",
                               "pt": "msg",
                               "to": "$map(array,function($v,$i){$i=dayOfMonth-1 ? payload : $v })",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 330,
                       "y": 6720,
                       "wires": [
                           [
                               "a3565f08d7626565"
                           ]
                       ]
                   },
                   {
                       "id": "a3565f08d7626565",
                       "type": "debug",
                       "z": "7e6af0015415146d",
                       "name": "Modify element of array",
                       "active": true,
                       "tosidebar": true,
                       "console": false,
                       "tostatus": false,
                       "complete": "true",
                       "targetType": "full",
                       "statusVal": "",
                       "statusType": "auto",
                       "x": 570,
                       "y": 6720,
                       "wires": []
                   }
                ]
                

                M mickym 2 Replies Last reply Reply Quote 0
                • M
                  MartyBr @mickym last edited by

                  @mickym
                  Danke dir. Ich setze das Morgen um. Aktuell muss ich das Rededuell Merz-Scholz noch sacken lassen.

                  1 Reply Last reply Reply Quote 0
                  • mickym
                    mickym Most Active @mickym last edited by

                    @MartyBr
                    So hier muss ich selbst immer probieren, wenn ich innerhalb eines Arrays was updaten will und nicht die explizite map Funktion nutzen will.

                    Um also das X.te Element des Monats einen arrays zu aktualisieren, kann man anstelle von

                    $map(array,function($v,$i){$i=dayOfMonth-1 ? payload : $v })
                    

                    auch folgendes schreiben:

                    array#$i.($i=$$.dayOfMonth -1 ? $$.payload : $)
                    

                    [
                       {
                           "id": "b9038fc06bf41c8f",
                           "type": "inject",
                           "z": "7e6af0015415146d",
                           "name": "",
                           "props": [
                               {
                                   "p": "payload"
                               }
                           ],
                           "repeat": "",
                           "crontab": "",
                           "once": false,
                           "onceDelay": 0.1,
                           "topic": "",
                           "payload": "20.5",
                           "payloadType": "num",
                           "x": 290,
                           "y": 6720,
                           "wires": [
                               [
                                   "d06e37f57f6a9c68"
                               ]
                           ]
                       },
                       {
                           "id": "d06e37f57f6a9c68",
                           "type": "change",
                           "z": "7e6af0015415146d",
                           "name": "",
                           "rules": [
                               {
                                   "t": "set",
                                   "p": "numDaysOfMonth",
                                   "pt": "msg",
                                   "to": "$moment().endOf(\"month\").date()",
                                   "tot": "jsonata"
                               },
                               {
                                   "t": "set",
                                   "p": "array",
                                   "pt": "msg",
                                   "to": "[0..numDaysOfMonth-1].($:=0)",
                                   "tot": "jsonata"
                               },
                               {
                                   "t": "set",
                                   "p": "dayOfMonth",
                                   "pt": "msg",
                                   "to": "$moment().date()",
                                   "tot": "jsonata"
                               },
                               {
                                   "t": "set",
                                   "p": "payload",
                                   "pt": "msg",
                                   "to": "array#$i.($i=$$.dayOfMonth -1 ? $$.payload : $)",
                                   "tot": "jsonata"
                               }
                           ],
                           "action": "",
                           "property": "",
                           "from": "",
                           "to": "",
                           "reg": false,
                           "x": 470,
                           "y": 6720,
                           "wires": [
                               [
                                   "a3565f08d7626565"
                               ]
                           ]
                       },
                       {
                           "id": "a3565f08d7626565",
                           "type": "debug",
                           "z": "7e6af0015415146d",
                           "name": "Modify element of array",
                           "active": true,
                           "tosidebar": true,
                           "console": false,
                           "tostatus": false,
                           "complete": "true",
                           "targetType": "full",
                           "statusVal": "",
                           "statusType": "auto",
                           "x": 710,
                           "y": 6720,
                           "wires": []
                       }
                    ]
                    

                    M 1 Reply Last reply Reply Quote 0
                    • M
                      MartyBr @mickym last edited by

                      @mickym
                      Vielen Dank. Ich habe den Node in meine Flows eingebaut und lasse das mal ein paar Tage laufen. Dann sollten ja Daten in den Arrays sein.

                      Die Flows sind nun erheblich kürzer geworden. Wenn alles läuft stelle ich den Flow hier ein.
                      Vielleicht kann ja noch jemand davon profitieren.

                      mickym 1 Reply Last reply Reply Quote 0
                      • mickym
                        mickym Most Active @MartyBr last edited by

                        @martybr Im Fall der variablen Adressierung innerhalb eines Arrays bietet sich dann doch eher ein Function Node mit Javascript an.

                        M 1 Reply Last reply Reply Quote 0
                        • M
                          MartyBr @mickym last edited by

                          @mickym
                          Ich stelle hier mal den gesamten Flow vor. Ziel war, aus einem Temperatursensor den Mittelwert (== mean), den Minimalwert (== min) und den Maximalwert (==max) über einen Tag gemittelt in ein Array zu speichern.
                          Dabei soll das erste Element den 1. Tag im Monat entsprechend, das 2. Element entsprechend die zweite Position im Array gespeichert werden.
                          Die Datenstruktur ist {min: 2, mean:4,max:12}
                          Zur Einhaltung der Reihenfolge dienen die delay Nodes.

                          Die Ablage des Arrays liegt unter 0_userdata.0.Hauptpfad.Jahr.Monat.
                          Als Beispiel:
                          0_userdata.0.Heizung.2025.Februar.meanTmp

                          Die Werte werden um Mitternacht geschrieben. Die Struktur der Ablage wird automatisch angelegt, d.h. am 1. März wird der nächste Datenpunkt geschrieben.
                          Aus historischen Gründen ersetze ich März durch Maerz (nicht Merz 😇 )

                          Hier der Flow:

                          Bildschirmfoto 2025-02-10 um 18.22.49.png

                          [
                              {
                                  "id": "ae673cf6cd8433a0",
                                  "type": "subflow",
                                  "name": "Datum in Topic",
                                  "info": "",
                                  "category": "",
                                  "in": [
                                      {
                                          "x": 60,
                                          "y": 80,
                                          "wires": [
                                              {
                                                  "id": "2e1ea06b2e94bf1a"
                                              }
                                          ]
                                      }
                                  ],
                                  "out": [
                                      {
                                          "x": 820,
                                          "y": 80,
                                          "wires": [
                                              {
                                                  "id": "fc37f5f9d2b0297b",
                                                  "port": 0
                                              }
                                          ]
                                      }
                                  ],
                                  "env": [
                                      {
                                          "name": "basePath",
                                          "type": "str",
                                          "value": "Test1.Test2"
                                      }
                                  ],
                                  "meta": {},
                                  "color": "#DDAA99"
                              },
                              {
                                  "id": "2e1ea06b2e94bf1a",
                                  "type": "change",
                                  "z": "ae673cf6cd8433a0",
                                  "name": "",
                                  "rules": [
                                      {
                                          "t": "set",
                                          "p": "datum",
                                          "pt": "msg",
                                          "to": "$moment().locale('de').format('YYYY.MMMM')",
                                          "tot": "jsonata"
                                      }
                                  ],
                                  "action": "",
                                  "property": "",
                                  "from": "",
                                  "to": "",
                                  "reg": false,
                                  "x": 230,
                                  "y": 80,
                                  "wires": [
                                      [
                                          "0e8de9437c3c420a"
                                      ]
                                  ]
                              },
                              {
                                  "id": "0e8de9437c3c420a",
                                  "type": "change",
                                  "z": "ae673cf6cd8433a0",
                                  "name": "März zu Maerz",
                                  "rules": [
                                      {
                                          "t": "change",
                                          "p": "datum",
                                          "pt": "msg",
                                          "from": "März",
                                          "fromt": "str",
                                          "to": "Maerz",
                                          "tot": "str"
                                      }
                                  ],
                                  "action": "",
                                  "property": "",
                                  "from": "",
                                  "to": "",
                                  "reg": false,
                                  "x": 440,
                                  "y": 80,
                                  "wires": [
                                      [
                                          "fc37f5f9d2b0297b"
                                      ]
                                  ]
                              },
                              {
                                  "id": "fc37f5f9d2b0297b",
                                  "type": "change",
                                  "z": "ae673cf6cd8433a0",
                                  "name": "",
                                  "rules": [
                                      {
                                          "t": "set",
                                          "p": "topic",
                                          "pt": "msg",
                                          "to": "\"0_userdata.0.\"  & $env(\"basePath\") & \".\" & datum & \".\" & topic",
                                          "tot": "jsonata"
                                      }
                                  ],
                                  "action": "",
                                  "property": "",
                                  "from": "",
                                  "to": "",
                                  "reg": false,
                                  "x": 660,
                                  "y": 80,
                                  "wires": [
                                      []
                                  ]
                              },
                              {
                                  "id": "8736b5d7e2d039bf",
                                  "type": "aggregator",
                                  "z": "3146dc7f943a9f88",
                                  "name": "Mean",
                                  "topic": "mean",
                                  "intervalCount": "1",
                                  "intervalUnits": "d",
                                  "submitIncompleteInterval": true,
                                  "submitPerTopic": false,
                                  "aggregationType": "mean",
                                  "x": 330,
                                  "y": 180,
                                  "wires": [
                                      [
                                          "ae4126ab345fb69f"
                                      ]
                                  ]
                              },
                              {
                                  "id": "c628f16d0dd75f88",
                                  "type": "aggregator",
                                  "z": "3146dc7f943a9f88",
                                  "name": "Min",
                                  "topic": "min",
                                  "intervalCount": "1",
                                  "intervalUnits": "d",
                                  "submitIncompleteInterval": true,
                                  "submitPerTopic": false,
                                  "aggregationType": "min",
                                  "x": 330,
                                  "y": 120,
                                  "wires": [
                                      [
                                          "73aeeccad69fe289"
                                      ]
                                  ]
                              },
                              {
                                  "id": "433c29573c06f6d3",
                                  "type": "aggregator",
                                  "z": "3146dc7f943a9f88",
                                  "name": "Max",
                                  "topic": "max",
                                  "intervalCount": "1",
                                  "intervalUnits": "d",
                                  "submitIncompleteInterval": true,
                                  "submitPerTopic": false,
                                  "aggregationType": "max",
                                  "x": 330,
                                  "y": 240,
                                  "wires": [
                                      [
                                          "b15148679b3cdfe5"
                                      ]
                                  ]
                              },
                              {
                                  "id": "73aeeccad69fe289",
                                  "type": "join",
                                  "z": "3146dc7f943a9f88",
                                  "name": "",
                                  "mode": "custom",
                                  "build": "object",
                                  "property": "payload",
                                  "propertyType": "msg",
                                  "key": "topic",
                                  "joiner": "\\n",
                                  "joinerType": "str",
                                  "accumulate": true,
                                  "timeout": "60",
                                  "count": "3",
                                  "reduceRight": false,
                                  "reduceExp": "",
                                  "reduceInit": "",
                                  "reduceInitType": "",
                                  "reduceFixup": "",
                                  "x": 710,
                                  "y": 120,
                                  "wires": [
                                      [
                                          "7c8ab4f951a11b2c"
                                      ]
                                  ]
                              },
                              {
                                  "id": "7c8ab4f951a11b2c",
                                  "type": "change",
                                  "z": "3146dc7f943a9f88",
                                  "name": "",
                                  "rules": [
                                      {
                                          "t": "set",
                                          "p": "topic",
                                          "pt": "msg",
                                          "to": "meanTmp",
                                          "tot": "str"
                                      }
                                  ],
                                  "action": "",
                                  "property": "",
                                  "from": "",
                                  "to": "",
                                  "reg": false,
                                  "x": 880,
                                  "y": 120,
                                  "wires": [
                                      [
                                          "95c361f9dc2dcb9f"
                                      ]
                                  ]
                              },
                              {
                                  "id": "95c361f9dc2dcb9f",
                                  "type": "subflow:ae673cf6cd8433a0",
                                  "z": "3146dc7f943a9f88",
                                  "name": "Datum in Topic",
                                  "env": [
                                      {
                                          "name": "basePath",
                                          "value": "Heizung2.MonatsTabellen",
                                          "type": "str"
                                      }
                                  ],
                                  "x": 1080,
                                  "y": 120,
                                  "wires": [
                                      [
                                          "3c1d0873dbaa5be4"
                                      ]
                                  ]
                              },
                              {
                                  "id": "ae4126ab345fb69f",
                                  "type": "delay",
                                  "z": "3146dc7f943a9f88",
                                  "name": "",
                                  "pauseType": "delay",
                                  "timeout": "5",
                                  "timeoutUnits": "seconds",
                                  "rate": "1",
                                  "nbRateUnits": "1",
                                  "rateUnits": "second",
                                  "randomFirst": "1",
                                  "randomLast": "5",
                                  "randomUnits": "seconds",
                                  "drop": false,
                                  "allowrate": false,
                                  "outputs": 1,
                                  "x": 500,
                                  "y": 180,
                                  "wires": [
                                      [
                                          "73aeeccad69fe289"
                                      ]
                                  ]
                              },
                              {
                                  "id": "b15148679b3cdfe5",
                                  "type": "delay",
                                  "z": "3146dc7f943a9f88",
                                  "name": "",
                                  "pauseType": "delay",
                                  "timeout": "10",
                                  "timeoutUnits": "seconds",
                                  "rate": "1",
                                  "nbRateUnits": "1",
                                  "rateUnits": "second",
                                  "randomFirst": "1",
                                  "randomLast": "5",
                                  "randomUnits": "seconds",
                                  "drop": false,
                                  "allowrate": false,
                                  "outputs": 1,
                                  "x": 510,
                                  "y": 240,
                                  "wires": [
                                      [
                                          "73aeeccad69fe289"
                                      ]
                                  ]
                              },
                              {
                                  "id": "3c1d0873dbaa5be4",
                                  "type": "change",
                                  "z": "3146dc7f943a9f88",
                                  "name": "Save to Array",
                                  "rules": [
                                      {
                                          "t": "set",
                                          "p": "numDaysOfMonth",
                                          "pt": "msg",
                                          "to": "$moment().endOf(\"month\").date()",
                                          "tot": "jsonata"
                                      },
                                      {
                                          "t": "set",
                                          "p": "array",
                                          "pt": "msg",
                                          "to": "[0..numDaysOfMonth-1].($:=0)",
                                          "tot": "jsonata"
                                      },
                                      {
                                          "t": "set",
                                          "p": "dayOfMonth",
                                          "pt": "msg",
                                          "to": "$moment().date()",
                                          "tot": "jsonata"
                                      },
                                      {
                                          "t": "set",
                                          "p": "payload",
                                          "pt": "msg",
                                          "to": "array#$i.($i=$$.dayOfMonth -1 ? $$.payload : $)",
                                          "tot": "jsonata"
                                      }
                                  ],
                                  "action": "",
                                  "property": "",
                                  "from": "",
                                  "to": "",
                                  "reg": false,
                                  "x": 780,
                                  "y": 220,
                                  "wires": [
                                      [
                                          "642675605be1e9ba"
                                      ]
                                  ]
                              },
                              {
                                  "id": "12be244299d16c40",
                                  "type": "ioBroker out",
                                  "z": "3146dc7f943a9f88",
                                  "name": "",
                                  "topic": "",
                                  "ack": "true",
                                  "autoCreate": "true",
                                  "stateName": "",
                                  "role": "",
                                  "payloadType": "",
                                  "readonly": "false",
                                  "stateUnit": "°C",
                                  "stateMin": "",
                                  "stateMax": "",
                                  "x": 1140,
                                  "y": 220,
                                  "wires": []
                              },
                              {
                                  "id": "642675605be1e9ba",
                                  "type": "json",
                                  "z": "3146dc7f943a9f88",
                                  "name": "",
                                  "property": "payload",
                                  "action": "",
                                  "pretty": false,
                                  "x": 970,
                                  "y": 220,
                                  "wires": [
                                      [
                                          "12be244299d16c40"
                                      ]
                                  ]
                              },
                              {
                                  "id": "ced5eb48c2a75d2e",
                                  "type": "ioBroker in",
                                  "z": "3146dc7f943a9f88",
                                  "name": "Aussentemperatur",
                                  "attrname": "payload",
                                  "topic": "mqtt.0.vitocal.outside_temperature",
                                  "payloadType": "value",
                                  "onlyack": "",
                                  "func": "all",
                                  "gap": "",
                                  "fireOnStart": "false",
                                  "outFormat": "MQTT",
                                  "x": 130,
                                  "y": 180,
                                  "wires": [
                                      [
                                          "8736b5d7e2d039bf",
                                          "c628f16d0dd75f88",
                                          "433c29573c06f6d3"
                                      ]
                                  ]
                              }
                          ]
                          
                          mickym 1 Reply Last reply Reply Quote 0
                          • mickym
                            mickym Most Active @MartyBr last edited by

                            @martybr Warum die delay Nodes?
                            bei der JOIN Node:

                            c1854594-3d88-4356-bae5-fdbef924f7b6-image.png

                            Wenn Du den Haken rausmachst, dann wartet diee JOIN Node bis sie von allen aggregator Nodes ihre Nachricht bekommen hat.

                            9ae1ee57-7028-4524-a848-e02e215556c8-image.png

                            [
                               {
                                   "id": "ae673cf6cd8433a0",
                                   "type": "subflow",
                                   "name": "Datum in Topic",
                                   "info": "",
                                   "category": "",
                                   "in": [
                                       {
                                           "x": 60,
                                           "y": 80,
                                           "wires": [
                                               {
                                                   "id": "2e1ea06b2e94bf1a"
                                               }
                                           ]
                                       }
                                   ],
                                   "out": [
                                       {
                                           "x": 820,
                                           "y": 80,
                                           "wires": [
                                               {
                                                   "id": "fc37f5f9d2b0297b",
                                                   "port": 0
                                               }
                                           ]
                                       }
                                   ],
                                   "env": [
                                       {
                                           "name": "basePath",
                                           "type": "str",
                                           "value": "Test1.Test2"
                                       }
                                   ],
                                   "meta": {},
                                   "color": "#DDAA99"
                               },
                               {
                                   "id": "2e1ea06b2e94bf1a",
                                   "type": "change",
                                   "z": "ae673cf6cd8433a0",
                                   "name": "",
                                   "rules": [
                                       {
                                           "t": "set",
                                           "p": "datum",
                                           "pt": "msg",
                                           "to": "$moment().locale('de').format('YYYY.MMMM')",
                                           "tot": "jsonata"
                                       }
                                   ],
                                   "action": "",
                                   "property": "",
                                   "from": "",
                                   "to": "",
                                   "reg": false,
                                   "x": 230,
                                   "y": 80,
                                   "wires": [
                                       [
                                           "0e8de9437c3c420a"
                                       ]
                                   ]
                               },
                               {
                                   "id": "0e8de9437c3c420a",
                                   "type": "change",
                                   "z": "ae673cf6cd8433a0",
                                   "name": "März zu Maerz",
                                   "rules": [
                                       {
                                           "t": "change",
                                           "p": "datum",
                                           "pt": "msg",
                                           "from": "März",
                                           "fromt": "str",
                                           "to": "Maerz",
                                           "tot": "str"
                                       }
                                   ],
                                   "action": "",
                                   "property": "",
                                   "from": "",
                                   "to": "",
                                   "reg": false,
                                   "x": 440,
                                   "y": 80,
                                   "wires": [
                                       [
                                           "fc37f5f9d2b0297b"
                                       ]
                                   ]
                               },
                               {
                                   "id": "fc37f5f9d2b0297b",
                                   "type": "change",
                                   "z": "ae673cf6cd8433a0",
                                   "name": "",
                                   "rules": [
                                       {
                                           "t": "set",
                                           "p": "topic",
                                           "pt": "msg",
                                           "to": "\"0_userdata.0.\"  & $env(\"basePath\") & \".\" & datum & \".\" & topic",
                                           "tot": "jsonata"
                                       }
                                   ],
                                   "action": "",
                                   "property": "",
                                   "from": "",
                                   "to": "",
                                   "reg": false,
                                   "x": 660,
                                   "y": 80,
                                   "wires": [
                                       []
                                   ]
                               },
                               {
                                   "id": "8736b5d7e2d039bf",
                                   "type": "aggregator",
                                   "z": "7e6af0015415146d",
                                   "name": "Mean",
                                   "topic": "mean",
                                   "intervalCount": "1",
                                   "intervalUnits": "d",
                                   "submitIncompleteInterval": true,
                                   "submitPerTopic": false,
                                   "aggregationType": "mean",
                                   "x": 350,
                                   "y": 7480,
                                   "wires": [
                                       [
                                           "73aeeccad69fe289"
                                       ]
                                   ]
                               },
                               {
                                   "id": "c628f16d0dd75f88",
                                   "type": "aggregator",
                                   "z": "7e6af0015415146d",
                                   "name": "Min",
                                   "topic": "min",
                                   "intervalCount": "1",
                                   "intervalUnits": "d",
                                   "submitIncompleteInterval": true,
                                   "submitPerTopic": false,
                                   "aggregationType": "min",
                                   "x": 350,
                                   "y": 7420,
                                   "wires": [
                                       [
                                           "73aeeccad69fe289"
                                       ]
                                   ]
                               },
                               {
                                   "id": "433c29573c06f6d3",
                                   "type": "aggregator",
                                   "z": "7e6af0015415146d",
                                   "name": "Max",
                                   "topic": "max",
                                   "intervalCount": "1",
                                   "intervalUnits": "d",
                                   "submitIncompleteInterval": true,
                                   "submitPerTopic": false,
                                   "aggregationType": "max",
                                   "x": 350,
                                   "y": 7540,
                                   "wires": [
                                       [
                                           "73aeeccad69fe289"
                                       ]
                                   ]
                               },
                               {
                                   "id": "73aeeccad69fe289",
                                   "type": "join",
                                   "z": "7e6af0015415146d",
                                   "name": "",
                                   "mode": "custom",
                                   "build": "object",
                                   "property": "payload",
                                   "propertyType": "msg",
                                   "key": "topic",
                                   "joiner": "\\n",
                                   "joinerType": "str",
                                   "accumulate": false,
                                   "timeout": "",
                                   "count": "3",
                                   "reduceRight": false,
                                   "reduceExp": "",
                                   "reduceInit": "",
                                   "reduceInitType": "",
                                   "reduceFixup": "",
                                   "x": 530,
                                   "y": 7480,
                                   "wires": [
                                       [
                                           "7c8ab4f951a11b2c"
                                       ]
                                   ]
                               },
                               {
                                   "id": "7c8ab4f951a11b2c",
                                   "type": "change",
                                   "z": "7e6af0015415146d",
                                   "name": "",
                                   "rules": [
                                       {
                                           "t": "set",
                                           "p": "topic",
                                           "pt": "msg",
                                           "to": "meanTmp",
                                           "tot": "str"
                                       }
                                   ],
                                   "action": "",
                                   "property": "",
                                   "from": "",
                                   "to": "",
                                   "reg": false,
                                   "x": 720,
                                   "y": 7480,
                                   "wires": [
                                       [
                                           "95c361f9dc2dcb9f"
                                       ]
                                   ]
                               },
                               {
                                   "id": "95c361f9dc2dcb9f",
                                   "type": "subflow:ae673cf6cd8433a0",
                                   "z": "7e6af0015415146d",
                                   "name": "Datum in Topic",
                                   "env": [
                                       {
                                           "name": "basePath",
                                           "value": "Heizung2.MonatsTabellen",
                                           "type": "str"
                                       }
                                   ],
                                   "x": 920,
                                   "y": 7480,
                                   "wires": [
                                       [
                                           "3c1d0873dbaa5be4"
                                       ]
                                   ]
                               },
                               {
                                   "id": "3c1d0873dbaa5be4",
                                   "type": "change",
                                   "z": "7e6af0015415146d",
                                   "name": "Save to Array",
                                   "rules": [
                                       {
                                           "t": "set",
                                           "p": "numDaysOfMonth",
                                           "pt": "msg",
                                           "to": "$moment().endOf(\"month\").date()",
                                           "tot": "jsonata"
                                       },
                                       {
                                           "t": "set",
                                           "p": "array",
                                           "pt": "msg",
                                           "to": "[0..numDaysOfMonth-1].($:=0)",
                                           "tot": "jsonata"
                                       },
                                       {
                                           "t": "set",
                                           "p": "dayOfMonth",
                                           "pt": "msg",
                                           "to": "$moment().date()",
                                           "tot": "jsonata"
                                       },
                                       {
                                           "t": "set",
                                           "p": "payload",
                                           "pt": "msg",
                                           "to": "array#$i.($i=$$.dayOfMonth -1 ? $$.payload : $)",
                                           "tot": "jsonata"
                                       }
                                   ],
                                   "action": "",
                                   "property": "",
                                   "from": "",
                                   "to": "",
                                   "reg": false,
                                   "x": 1120,
                                   "y": 7480,
                                   "wires": [
                                       [
                                           "642675605be1e9ba"
                                       ]
                                   ]
                               },
                               {
                                   "id": "642675605be1e9ba",
                                   "type": "json",
                                   "z": "7e6af0015415146d",
                                   "name": "",
                                   "property": "payload",
                                   "action": "",
                                   "pretty": false,
                                   "x": 1290,
                                   "y": 7480,
                                   "wires": [
                                       [
                                           "12be244299d16c40"
                                       ]
                                   ]
                               },
                               {
                                   "id": "ced5eb48c2a75d2e",
                                   "type": "ioBroker in",
                                   "z": "7e6af0015415146d",
                                   "name": "Aussentemperatur",
                                   "attrname": "payload",
                                   "topic": "mqtt.0.vitocal.outside_temperature",
                                   "payloadType": "value",
                                   "onlyack": "",
                                   "func": "all",
                                   "gap": "",
                                   "fireOnStart": "false",
                                   "outFormat": "MQTT",
                                   "x": 150,
                                   "y": 7480,
                                   "wires": [
                                       [
                                           "8736b5d7e2d039bf",
                                           "c628f16d0dd75f88",
                                           "433c29573c06f6d3"
                                       ]
                                   ]
                               },
                               {
                                   "id": "12be244299d16c40",
                                   "type": "ioBroker out",
                                   "z": "7e6af0015415146d",
                                   "name": "",
                                   "topic": "",
                                   "ack": "true",
                                   "autoCreate": "true",
                                   "stateName": "",
                                   "role": "",
                                   "payloadType": "",
                                   "readonly": "false",
                                   "stateUnit": "°C",
                                   "stateMin": "",
                                   "stateMax": "",
                                   "x": 1420,
                                   "y": 7520,
                                   "wires": []
                               }
                            ]
                            

                            M 1 Reply Last reply Reply Quote 0
                            • M
                              MartyBr @mickym last edited by

                              @mickym
                              Mit den Delay Nodes kommen sie in der richtigen Abfolge. Das war der Grund.

                              mickym 1 Reply Last reply Reply Quote 0
                              • mickym
                                mickym Most Active @MartyBr last edited by mickym

                                @martybr Wieso braucht es eine Abfolge - nur wegen dem Verständnis - es wird doch eh alles in einem Objekt gesammelt. Im Prinzip ist die Reihenfolge der Eigenschaften in einem Objekt doch völlig egal.

                                Wenn man unbedingt eine Reihenfolge erzwingen wird, dann strukturiert man das Objekt einfach um

                                a6c962b9-b851-4e5c-8f25-a4368c2c043e-image.png

                                Hier zum Ausprobieren:

                                [
                                   {
                                       "id": "c0fbc5b325e9ee2b",
                                       "type": "join",
                                       "z": "7e6af0015415146d",
                                       "name": "",
                                       "mode": "custom",
                                       "build": "object",
                                       "property": "payload",
                                       "propertyType": "msg",
                                       "key": "topic",
                                       "joiner": "\\n",
                                       "joinerType": "str",
                                       "accumulate": false,
                                       "timeout": "",
                                       "count": "3",
                                       "reduceRight": false,
                                       "reduceExp": "",
                                       "reduceInit": "",
                                       "reduceInitType": "",
                                       "reduceFixup": "",
                                       "x": 690,
                                       "y": 6840,
                                       "wires": [
                                           [
                                               "3a61e25c93e112af",
                                               "435389345c46e069"
                                           ]
                                       ]
                                   },
                                   {
                                       "id": "5c037052db7f4603",
                                       "type": "inject",
                                       "z": "7e6af0015415146d",
                                       "name": "",
                                       "props": [
                                           {
                                               "p": "payload"
                                           },
                                           {
                                               "p": "topic",
                                               "vt": "str"
                                           }
                                       ],
                                       "repeat": "",
                                       "crontab": "",
                                       "once": false,
                                       "onceDelay": 0.1,
                                       "topic": "min",
                                       "payload": "19",
                                       "payloadType": "num",
                                       "x": 510,
                                       "y": 6800,
                                       "wires": [
                                           [
                                               "86eed7a3587a28dd"
                                           ]
                                       ]
                                   },
                                   {
                                       "id": "e37f98364b345ba6",
                                       "type": "inject",
                                       "z": "7e6af0015415146d",
                                       "name": "",
                                       "props": [
                                           {
                                               "p": "payload"
                                           },
                                           {
                                               "p": "topic",
                                               "vt": "str"
                                           }
                                       ],
                                       "repeat": "",
                                       "crontab": "",
                                       "once": false,
                                       "onceDelay": 0.1,
                                       "topic": "mean",
                                       "payload": "20",
                                       "payloadType": "num",
                                       "x": 500,
                                       "y": 6840,
                                       "wires": [
                                           [
                                               "86eed7a3587a28dd"
                                           ]
                                       ]
                                   },
                                   {
                                       "id": "7750f86da52a7e7a",
                                       "type": "inject",
                                       "z": "7e6af0015415146d",
                                       "name": "",
                                       "props": [
                                           {
                                               "p": "payload"
                                           },
                                           {
                                               "p": "topic",
                                               "vt": "str"
                                           }
                                       ],
                                       "repeat": "",
                                       "crontab": "",
                                       "once": false,
                                       "onceDelay": 0.1,
                                       "topic": "max",
                                       "payload": "22",
                                       "payloadType": "num",
                                       "x": 510,
                                       "y": 6880,
                                       "wires": [
                                           [
                                               "86eed7a3587a28dd"
                                           ]
                                       ]
                                   },
                                   {
                                       "id": "91e8242275e261cf",
                                       "type": "debug",
                                       "z": "7e6af0015415146d",
                                       "name": "Objekt",
                                       "active": true,
                                       "tosidebar": true,
                                       "console": false,
                                       "tostatus": false,
                                       "complete": "payload",
                                       "targetType": "msg",
                                       "statusVal": "",
                                       "statusType": "auto",
                                       "x": 1050,
                                       "y": 6840,
                                       "wires": []
                                   },
                                   {
                                       "id": "3a61e25c93e112af",
                                       "type": "change",
                                       "z": "7e6af0015415146d",
                                       "name": "Formatiere Objekt",
                                       "rules": [
                                           {
                                               "t": "set",
                                               "p": "payload",
                                               "pt": "msg",
                                               "to": "payload.{\t    \"min\": min, \t    \"mean\": mean, \t    \"max\": max\t}",
                                               "tot": "jsonata"
                                           }
                                       ],
                                       "action": "",
                                       "property": "",
                                       "from": "",
                                       "to": "",
                                       "reg": false,
                                       "x": 870,
                                       "y": 6840,
                                       "wires": [
                                           [
                                               "91e8242275e261cf"
                                           ]
                                       ]
                                   },
                                   {
                                       "id": "435389345c46e069",
                                       "type": "debug",
                                       "z": "7e6af0015415146d",
                                       "name": "unsortiert",
                                       "active": true,
                                       "tosidebar": true,
                                       "console": false,
                                       "tostatus": false,
                                       "complete": "payload",
                                       "targetType": "msg",
                                       "statusVal": "",
                                       "statusType": "auto",
                                       "x": 840,
                                       "y": 6780,
                                       "wires": []
                                   },
                                   {
                                       "id": "86eed7a3587a28dd",
                                       "type": "junction",
                                       "z": "7e6af0015415146d",
                                       "x": 600,
                                       "y": 6840,
                                       "wires": [
                                           [
                                               "c0fbc5b325e9ee2b"
                                           ]
                                       ]
                                   }
                                ]
                                

                                Es ist wichtig, dass Du diese einfachen Umstrukturierungsmöglichkeiten von Objekten verstehst, das ist ein riesiger Vorteil gegenüber den Puzzlefreunden. Du kannst die "Attribute" umbenennen, welche weglassen, welche hinzufügen etc.

                                https://docs.jsonata.org/construction#object-constructors

                                M 1 Reply Last reply Reply Quote 0
                                • M
                                  MartyBr @mickym last edited by

                                  @mickym
                                  Der Flow funktioniert (natürlich 😊 ) und ich habe ihn direkt in meinen Testflow eingebaut.

                                  JSONata scheint ja mächtige Funktionen zu haben.
                                  Das habe ich was zu lesen.

                                  mickym 1 Reply Last reply Reply Quote 0
                                  • mickym
                                    mickym Most Active @MartyBr last edited by

                                    @martybr sagte in Wert in dynamische Struktur im ioBroker ablegen:

                                    JSONata scheint ja mächtige Funktionen zu haben.

                                    Ja und was ich nicht verstehe, dass auch die Puzzlefreunde viel zu wenige Gebrauch von dieser tollen Bibliothek machen:
                                    d313bc8c-55fe-4c80-967e-d03620d4e04c-image.png

                                    M 1 Reply Last reply Reply Quote 0
                                    • M
                                      MartyBr last edited by

                                      @mickym
                                      Ich habe mal eine Suche über das Forum laufen lassen. Es sind schon einige Threads dazu im Forum. Nach meiner kurzen Recherche mit Durchweg sehr positiver Resonanz.
                                      Das motiviert weiter 👍

                                      1 Reply Last reply Reply Quote 0
                                      • M
                                        MartyBr @mickym last edited by

                                        @mickym
                                        Ich habe ein neues Problem, wo ich nicht weiterkomme.

                                        Die Idee ist, einen Datenpunkt (den täglichen Strombezug) um 00:05 Uhr mit einem Zeitstempel vom Vortag (also von dem Tag, an dem der Strombezug angefallen ist) in Influxdb2 zu speichern.

                                        In Blockly gibt es dazu entsprechende Funktionsblöcke, die ich aktuell zum speichern nutze.

                                        Meine Vorarbeit hier:

                                        1. Generiere globale Variable "gestern" mit dem Vortagsdatum
                                        2. Setze timestamp auf "gestern"
                                        3. Speicher Datenpunkt in Influxdb

                                        Der Punkt 3 scheitert.

                                        Hier der Flow:
                                        Bildschirmfoto 2025-02-11 um 20.36.16.png

                                        Hier der Fehler:
                                        Bildschirmfoto 2025-02-11 um 20.36.35.png

                                        Hier der Code:

                                        [
                                            {
                                                "id": "3af60aa82603a460",
                                                "type": "inject",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "",
                                                "props": [
                                                    {
                                                        "p": "payload"
                                                    },
                                                    {
                                                        "p": "topic",
                                                        "vt": "str"
                                                    }
                                                ],
                                                "repeat": "",
                                                "crontab": "",
                                                "once": false,
                                                "onceDelay": 0.1,
                                                "topic": "",
                                                "payload": "",
                                                "payloadType": "date",
                                                "x": 160,
                                                "y": 840,
                                                "wires": [
                                                    [
                                                        "7ccee6b8c9cf5ec1"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "7ccee6b8c9cf5ec1",
                                                "type": "change",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "",
                                                "rules": [
                                                    {
                                                        "t": "set",
                                                        "p": "payload",
                                                        "pt": "msg",
                                                        "to": "$moment().locale('de').add(-24,'hours')",
                                                        "tot": "jsonata"
                                                    }
                                                ],
                                                "action": "",
                                                "property": "",
                                                "from": "",
                                                "to": "",
                                                "reg": false,
                                                "x": 370,
                                                "y": 840,
                                                "wires": [
                                                    [
                                                        "1ea6bb475e356038"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "1ea6bb475e356038",
                                                "type": "change",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "",
                                                "rules": [
                                                    {
                                                        "t": "set",
                                                        "p": "payload",
                                                        "pt": "msg",
                                                        "to": "gestern",
                                                        "tot": "global"
                                                    }
                                                ],
                                                "action": "",
                                                "property": "",
                                                "from": "",
                                                "to": "",
                                                "reg": false,
                                                "x": 610,
                                                "y": 840,
                                                "wires": [
                                                    []
                                                ]
                                            },
                                            {
                                                "id": "f26c4899a33b8475",
                                                "type": "debug",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "debug 189",
                                                "active": true,
                                                "tosidebar": true,
                                                "console": false,
                                                "tostatus": false,
                                                "complete": "false",
                                                "statusVal": "",
                                                "statusType": "auto",
                                                "x": 630,
                                                "y": 920,
                                                "wires": []
                                            },
                                            {
                                                "id": "406857da365d597c",
                                                "type": "debug",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "debug 190",
                                                "active": true,
                                                "tosidebar": true,
                                                "console": false,
                                                "tostatus": false,
                                                "complete": "false",
                                                "statusVal": "",
                                                "statusType": "auto",
                                                "x": 390,
                                                "y": 920,
                                                "wires": []
                                            },
                                            {
                                                "id": "b8a9409a42dbae35",
                                                "type": "debug",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "debug 188",
                                                "active": true,
                                                "tosidebar": true,
                                                "console": false,
                                                "tostatus": false,
                                                "complete": "false",
                                                "statusVal": "",
                                                "statusType": "auto",
                                                "x": 150,
                                                "y": 920,
                                                "wires": []
                                            },
                                            {
                                                "id": "12f8e712328509a0",
                                                "type": "inject",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "",
                                                "props": [
                                                    {
                                                        "p": "payload"
                                                    },
                                                    {
                                                        "p": "topic",
                                                        "vt": "str"
                                                    }
                                                ],
                                                "repeat": "",
                                                "crontab": "",
                                                "once": false,
                                                "onceDelay": 0.1,
                                                "topic": "test",
                                                "payload": "gestern",
                                                "payloadType": "global",
                                                "x": 170,
                                                "y": 980,
                                                "wires": [
                                                    [
                                                        "b8a9409a42dbae35",
                                                        "8529604e9d2970d9"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "8529604e9d2970d9",
                                                "type": "change",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "",
                                                "rules": [
                                                    {
                                                        "t": "set",
                                                        "p": "payload",
                                                        "pt": "msg",
                                                        "to": "",
                                                        "tot": "date"
                                                    }
                                                ],
                                                "action": "",
                                                "property": "",
                                                "from": "",
                                                "to": "",
                                                "reg": false,
                                                "x": 390,
                                                "y": 980,
                                                "wires": [
                                                    [
                                                        "a7394618f04eb825",
                                                        "406857da365d597c"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "a7394618f04eb825",
                                                "type": "change",
                                                "z": "3ebdbbcf49e0ac40",
                                                "name": "",
                                                "rules": [
                                                    {
                                                        "t": "set",
                                                        "p": "topic",
                                                        "pt": "msg",
                                                        "to": "test-topic2",
                                                        "tot": "str"
                                                    }
                                                ],
                                                "action": "",
                                                "property": "",
                                                "from": "",
                                                "to": "",
                                                "reg": false,
                                                "x": 600,
                                                "y": 980,
                                                "wires": [
                                                    [
                                                        "f26c4899a33b8475",
                                                        "031edbcc8819c8f7"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "031edbcc8819c8f7",
                                                "type": "influxdb batch",
                                                "z": "3ebdbbcf49e0ac40",
                                                "influxdb": "4d3e21e6d3a637e2",
                                                "precision": "",
                                                "retentionPolicy": "",
                                                "name": "",
                                                "database": "database",
                                                "precisionV18FluxV20": "ms",
                                                "retentionPolicyV18Flux": "",
                                                "org": "Home",
                                                "bucket": "iobroker",
                                                "x": 650,
                                                "y": 1080,
                                                "wires": []
                                            },
                                            {
                                                "id": "4d3e21e6d3a637e2",
                                                "type": "influxdb",
                                                "hostname": "127.0.0.1",
                                                "port": "8086",
                                                "protocol": "http",
                                                "database": "database",
                                                "name": "influx2",
                                                "usetls": false,
                                                "tls": "",
                                                "influxdbVersion": "2.0",
                                                "url": "http://192.168.178.111:8086",
                                                "timeout": "",
                                                "rejectUnauthorized": false
                                            }
                                        ]
                                        

                                        Im Forum wird über Probleme beim Ändern vom Timestamp beim speichern in Influx diskutiert. Gibt es einen Tipp, wie ich den Datenpunkt mit dem geänderten Timestamp in Influxdb2 speichern kann?

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

                                          Timestamps kannst Du meiner Meinung nicht mit den influx Out Node setzen, sondern Du brauchst die Batch Nodes.

                                          In die Batch Nodes kommen Objekte

                                          c14197a3-bf34-4e2d-b9bd-70f45fc4d12d-image.png

                                          Falls Du noch tags hast, dann ist das genauso ein Objekt wie fields.

                                          fcb9a742-eae8-443a-a81e-d41c1966733e-image.png

                                          M 1 Reply Last reply Reply Quote 0
                                          • M
                                            MartyBr @mickym last edited by

                                            @mickym
                                            Okay, probiere ich aus.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            1.0k
                                            Online

                                            31.7k
                                            Users

                                            79.7k
                                            Topics

                                            1.3m
                                            Posts

                                            2
                                            91
                                            4041
                                            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