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

    • Neuer Blog: Fotos und Eindrücke aus Solingen

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    Gelöst: Wert in dynamische Struktur im ioBroker ablegen

    This topic has been deleted. Only users with topic management privileges can see it.
    • 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
                                      • M
                                        MartyBr last edited by

                                        @mickym
                                        Ich habe es mit der Change Node nicht hinbekommen. Mit einer Funktion und der normalen influx-out (nicht influx-batch) funktioniert es. In der Function ziehe ich 12 Stunden ab (43200 Sek.) und schreibe es in Time:

                                        Bildschirmfoto 2025-02-12 um 09.55.33.png

                                        [
                                            {
                                                "id": "88f12c4fab5f8e9b",
                                                "type": "mqtt in",
                                                "z": "2987494fe96ff2fb",
                                                "name": "Vitovent ZuluftTemp",
                                                "topic": "vitocal/ZuluftTemp",
                                                "qos": "0",
                                                "datatype": "auto-detect",
                                                "broker": "bcf16446273a18e6",
                                                "nl": false,
                                                "rap": true,
                                                "rh": 0,
                                                "inputs": 0,
                                                "x": 130,
                                                "y": 1040,
                                                "wires": [
                                                    [
                                                        "0e5f1ebe84c213fc"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "0e5f1ebe84c213fc",
                                                "type": "change",
                                                "z": "2987494fe96ff2fb",
                                                "name": "",
                                                "rules": [
                                                    {
                                                        "t": "set",
                                                        "p": "topic",
                                                        "pt": "msg",
                                                        "to": "zuluft",
                                                        "tot": "str"
                                                    }
                                                ],
                                                "action": "",
                                                "property": "",
                                                "from": "",
                                                "to": "",
                                                "reg": false,
                                                "x": 340,
                                                "y": 1040,
                                                "wires": [
                                                    [
                                                        "a8b5d292c778eeb7"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "a8b5d292c778eeb7",
                                                "type": "function",
                                                "z": "2987494fe96ff2fb",
                                                "name": "function 22",
                                                "func": "function getHistoryTimestamp(seconds) {\n    var historyDate = new Date(Date.now() - (seconds * 1000));\n    return historyDate.getTime();\n}\n\nvar historyTimestamp = getHistoryTimestamp(43200);\n\nmsg.payload = { value: msg.payload, time: historyTimestamp }\n\nreturn msg;",
                                                "outputs": 1,
                                                "timeout": 0,
                                                "noerr": 0,
                                                "initialize": "",
                                                "finalize": "",
                                                "libs": [],
                                                "x": 550,
                                                "y": 1040,
                                                "wires": [
                                                    [
                                                        "7f48f630a7765a4a"
                                                    ]
                                                ]
                                            },
                                            {
                                                "id": "7f48f630a7765a4a",
                                                "type": "influxdb out",
                                                "z": "2987494fe96ff2fb",
                                                "influxdb": "5d7e54ca.019d44",
                                                "name": "outside",
                                                "measurement": "test.test3.outside",
                                                "precision": "",
                                                "retentionPolicy": "",
                                                "database": "database",
                                                "precisionV18FluxV20": "ms",
                                                "retentionPolicyV18Flux": "",
                                                "org": "Home",
                                                "bucket": "iobroker",
                                                "x": 740,
                                                "y": 1040,
                                                "wires": []
                                            },
                                            {
                                                "id": "bcf16446273a18e6",
                                                "type": "mqtt-broker",
                                                "name": "Mosquito",
                                                "broker": "192.168.178.10",
                                                "port": 1883,
                                                "clientid": "",
                                                "autoConnect": true,
                                                "usetls": false,
                                                "protocolVersion": 4,
                                                "keepalive": 60,
                                                "cleansession": true,
                                                "autoUnsubscribe": true,
                                                "birthTopic": "",
                                                "birthQos": "0",
                                                "birthRetain": "false",
                                                "birthPayload": "",
                                                "birthMsg": {},
                                                "closeTopic": "",
                                                "closeQos": "0",
                                                "closeRetain": "false",
                                                "closePayload": "",
                                                "closeMsg": {},
                                                "willTopic": "",
                                                "willQos": "0",
                                                "willRetain": "false",
                                                "willPayload": "",
                                                "willMsg": {},
                                                "userProps": "",
                                                "sessionExpiry": ""
                                            },
                                            {
                                                "id": "5d7e54ca.019d44",
                                                "type": "influxdb",
                                                "hostname": "127.0.0.1",
                                                "port": "8086",
                                                "protocol": "http",
                                                "database": "database",
                                                "name": "Influxdb2",
                                                "usetls": false,
                                                "tls": "d50d0c9f.31e858",
                                                "influxdbVersion": "2.0",
                                                "url": "http://192.168.178.111:8086",
                                                "timeout": "",
                                                "rejectUnauthorized": false
                                            },
                                            {
                                                "id": "d50d0c9f.31e858",
                                                "type": "tls-config",
                                                "name": "",
                                                "cert": "",
                                                "key": "",
                                                "ca": "",
                                                "certname": "",
                                                "keyname": "",
                                                "caname": "",
                                                "servername": "",
                                                "verifyservercert": false
                                            }
                                        ]
                                        

                                        Eigentlich müsste es mit einer Change und JSONata auch funktionieren.

                                        Hier ein Versuch:

                                        [
                                            {
                                                "id": "26d58a13f8c13bd6",
                                                "type": "change",
                                                "z": "2987494fe96ff2fb",
                                                "name": "",
                                                "rules": [
                                                    {
                                                        "t": "set",
                                                        "p": "payload",
                                                        "pt": "msg",
                                                        "to": "payload.{    \"measurement\":msg.payload,    \"timestamp\":$millis() }",
                                                        "tot": "jsonata"
                                                    },
                                                    {
                                                        "t": "set",
                                                        "p": "topic",
                                                        "pt": "msg",
                                                        "to": "zuluft",
                                                        "tot": "str"
                                                    }
                                                ],
                                                "action": "",
                                                "property": "",
                                                "from": "",
                                                "to": "",
                                                "reg": false,
                                                "x": 370,
                                                "y": 800,
                                                "wires": [
                                                    [
                                                        "6a3df3f89e66d61c"
                                                    ]
                                                ]
                                            }
                                        ]
                                        

                                        Leider funktioniert es nicht. Kannst du mir hier einen Tipp geben?

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

                                          @martybr Das ist eigentlich ganz einfach:

                                          c705030e-7ff8-4f7f-be1c-c3e494dfaa28-image.png

                                          1. Da die payload kein Objekt sondern ein skalarer Wert ist, kann auch kein Objekt neu definiert werden. Also musst Du der payload Eigenschaft einfach ein Objekt zuweisen.
                                          2. In einer ChangeNode gibst Du das Wurzelobjekt - also das Nachrichtenobjekt msg - nie an. Das ist in der ChangeNode bereits festgelegt, deswegen kann man auch nicht auf Eigenschaften außerhalb des Nachrichtenobjektes zugreifen.

                                          Deine ChangeNode hätte als bereits wie folgt funktioniert:

                                          94254ba6-f965-4089-82a4-45397591c8de-image.png

                                          Um die gleiche Ausgabe wie mit Deinem Javascriptcode zu erhalten:

                                          function getHistoryTimestamp(seconds) {
                                              var historyDate = new Date(Date.now() - (seconds * 1000));
                                              return historyDate.getTime();
                                          }
                                          
                                          var historyTimestamp = getHistoryTimestamp(43200);
                                          
                                          msg.payload = { value: msg.payload, time: historyTimestamp }
                                          
                                          return msg;
                                          

                                          schreibst Du in JSONATA also nur folgendes:

                                          {
                                             "value":payload,
                                             "time": $millis() -43200*1000
                                          }
                                          

                                          87a7bba6-3113-46a7-9b98-d953b8690fe2-image.png

                                          Hier wieder alles zusammen zum Import:

                                          [
                                              {
                                                  "id": "88f12c4fab5f8e9b",
                                                  "type": "mqtt in",
                                                  "z": "3b40b768dd849499",
                                                  "d": true,
                                                  "name": "Vitovent ZuluftTemp",
                                                  "topic": "vitocal/ZuluftTemp",
                                                  "qos": "0",
                                                  "datatype": "auto-detect",
                                                  "broker": "bcf16446273a18e6",
                                                  "nl": false,
                                                  "rap": true,
                                                  "rh": 0,
                                                  "inputs": 0,
                                                  "x": 310,
                                                  "y": 160,
                                                  "wires": [
                                                      [
                                                          "0e5f1ebe84c213fc"
                                                      ]
                                                  ]
                                              },
                                              {
                                                  "id": "0e5f1ebe84c213fc",
                                                  "type": "change",
                                                  "z": "3b40b768dd849499",
                                                  "name": "",
                                                  "rules": [
                                                      {
                                                          "t": "set",
                                                          "p": "topic",
                                                          "pt": "msg",
                                                          "to": "zuluft",
                                                          "tot": "str"
                                                      }
                                                  ],
                                                  "action": "",
                                                  "property": "",
                                                  "from": "",
                                                  "to": "",
                                                  "reg": false,
                                                  "x": 540,
                                                  "y": 220,
                                                  "wires": [
                                                      [
                                                          "a8b5d292c778eeb7"
                                                      ]
                                                  ]
                                              },
                                              {
                                                  "id": "a8b5d292c778eeb7",
                                                  "type": "function",
                                                  "z": "3b40b768dd849499",
                                                  "name": "function 22",
                                                  "func": "function getHistoryTimestamp(seconds) {\n    var historyDate = new Date(Date.now() - (seconds * 1000));\n    return historyDate.getTime();\n}\n\nvar historyTimestamp = getHistoryTimestamp(43200);\n\nmsg.payload = { value: msg.payload, time: historyTimestamp }\n\nreturn msg;",
                                                  "outputs": 1,
                                                  "timeout": 0,
                                                  "noerr": 0,
                                                  "initialize": "",
                                                  "finalize": "",
                                                  "libs": [],
                                                  "x": 750,
                                                  "y": 220,
                                                  "wires": [
                                                      [
                                                          "7f48f630a7765a4a",
                                                          "d844ef86e37ba92c"
                                                      ]
                                                  ]
                                              },
                                              {
                                                  "id": "7f48f630a7765a4a",
                                                  "type": "influxdb out",
                                                  "z": "3b40b768dd849499",
                                                  "d": true,
                                                  "influxdb": "5d7e54ca.019d44",
                                                  "name": "outside",
                                                  "measurement": "test.test3.outside",
                                                  "precision": "",
                                                  "retentionPolicy": "",
                                                  "database": "database",
                                                  "precisionV18FluxV20": "ms",
                                                  "retentionPolicyV18Flux": "",
                                                  "org": "Home",
                                                  "bucket": "iobroker",
                                                  "x": 940,
                                                  "y": 220,
                                                  "wires": []
                                              },
                                              {
                                                  "id": "26d58a13f8c13bd6",
                                                  "type": "change",
                                                  "z": "3b40b768dd849499",
                                                  "d": true,
                                                  "name": "",
                                                  "rules": [
                                                      {
                                                          "t": "set",
                                                          "p": "payload",
                                                          "pt": "msg",
                                                          "to": "{\t   \"measurement\":payload,\t   \"timestamp\":$millis() \t}",
                                                          "tot": "jsonata"
                                                      },
                                                      {
                                                          "t": "set",
                                                          "p": "topic",
                                                          "pt": "msg",
                                                          "to": "zuluft",
                                                          "tot": "str"
                                                      }
                                                  ],
                                                  "action": "",
                                                  "property": "",
                                                  "from": "",
                                                  "to": "",
                                                  "reg": false,
                                                  "x": 570,
                                                  "y": 340,
                                                  "wires": [
                                                      [
                                                          "7adb8e9803e35709"
                                                      ]
                                                  ]
                                              },
                                              {
                                                  "id": "7b4222c2e177b48f",
                                                  "type": "inject",
                                                  "z": "3b40b768dd849499",
                                                  "name": "",
                                                  "props": [
                                                      {
                                                          "p": "payload"
                                                      },
                                                      {
                                                          "p": "topic",
                                                          "vt": "str"
                                                      }
                                                  ],
                                                  "repeat": "",
                                                  "crontab": "",
                                                  "once": false,
                                                  "onceDelay": 0.1,
                                                  "topic": "",
                                                  "payload": "21",
                                                  "payloadType": "num",
                                                  "x": 310,
                                                  "y": 220,
                                                  "wires": [
                                                      [
                                                          "0e5f1ebe84c213fc",
                                                          "26d58a13f8c13bd6",
                                                          "18c22fa209a126c5"
                                                      ]
                                                  ]
                                              },
                                              {
                                                  "id": "d844ef86e37ba92c",
                                                  "type": "debug",
                                                  "z": "3b40b768dd849499",
                                                  "name": "Ausgabe",
                                                  "active": true,
                                                  "tosidebar": true,
                                                  "console": false,
                                                  "tostatus": false,
                                                  "complete": "payload",
                                                  "targetType": "msg",
                                                  "statusVal": "",
                                                  "statusType": "auto",
                                                  "x": 940,
                                                  "y": 160,
                                                  "wires": []
                                              },
                                              {
                                                  "id": "7adb8e9803e35709",
                                                  "type": "debug",
                                                  "z": "3b40b768dd849499",
                                                  "name": "Ausgabe JSONATA",
                                                  "active": true,
                                                  "tosidebar": true,
                                                  "console": false,
                                                  "tostatus": false,
                                                  "complete": "payload",
                                                  "targetType": "msg",
                                                  "statusVal": "",
                                                  "statusType": "auto",
                                                  "x": 830,
                                                  "y": 340,
                                                  "wires": []
                                              },
                                              {
                                                  "id": "18c22fa209a126c5",
                                                  "type": "change",
                                                  "z": "3b40b768dd849499",
                                                  "name": "",
                                                  "rules": [
                                                      {
                                                          "t": "set",
                                                          "p": "payload",
                                                          "pt": "msg",
                                                          "to": "{\"value\":payload,\"time\": $millis() -43200*1000}",
                                                          "tot": "jsonata"
                                                      }
                                                  ],
                                                  "action": "",
                                                  "property": "",
                                                  "from": "",
                                                  "to": "",
                                                  "reg": false,
                                                  "x": 570,
                                                  "y": 280,
                                                  "wires": [
                                                      [
                                                          "a547d2d79fafb77f"
                                                      ]
                                                  ]
                                              },
                                              {
                                                  "id": "a547d2d79fafb77f",
                                                  "type": "debug",
                                                  "z": "3b40b768dd849499",
                                                  "name": "Ausgabe JSONATA mit identischer Ausgabe",
                                                  "active": true,
                                                  "tosidebar": true,
                                                  "console": false,
                                                  "tostatus": false,
                                                  "complete": "payload",
                                                  "targetType": "msg",
                                                  "statusVal": "",
                                                  "statusType": "auto",
                                                  "x": 890,
                                                  "y": 280,
                                                  "wires": []
                                              },
                                              {
                                                  "id": "14c452221e5c975e",
                                                  "type": "change",
                                                  "z": "3b40b768dd849499",
                                                  "name": "",
                                                  "rules": [
                                                      {
                                                          "t": "set",
                                                          "p": "payload",
                                                          "pt": "msg",
                                                          "to": "payload.{    \"measurement\":msg.payload,    \"timestamp\":$millis() }",
                                                          "tot": "jsonata"
                                                      },
                                                      {
                                                          "t": "set",
                                                          "p": "topic",
                                                          "pt": "msg",
                                                          "to": "zuluft",
                                                          "tot": "str"
                                                      }
                                                  ],
                                                  "action": "",
                                                  "property": "",
                                                  "from": "",
                                                  "to": "",
                                                  "reg": false,
                                                  "x": 670,
                                                  "y": 420,
                                                  "wires": [
                                                      []
                                                  ]
                                              },
                                              {
                                                  "id": "bcf16446273a18e6",
                                                  "type": "mqtt-broker",
                                                  "name": "Mosquito",
                                                  "broker": "192.168.178.10",
                                                  "port": 1883,
                                                  "clientid": "",
                                                  "autoConnect": true,
                                                  "usetls": false,
                                                  "protocolVersion": 4,
                                                  "keepalive": 60,
                                                  "cleansession": true,
                                                  "autoUnsubscribe": true,
                                                  "birthTopic": "",
                                                  "birthQos": "0",
                                                  "birthRetain": "false",
                                                  "birthPayload": "",
                                                  "birthMsg": {},
                                                  "closeTopic": "",
                                                  "closeQos": "0",
                                                  "closeRetain": "false",
                                                  "closePayload": "",
                                                  "closeMsg": {},
                                                  "willTopic": "",
                                                  "willQos": "0",
                                                  "willRetain": "false",
                                                  "willPayload": "",
                                                  "willMsg": {},
                                                  "userProps": "",
                                                  "sessionExpiry": ""
                                              },
                                              {
                                                  "id": "5d7e54ca.019d44",
                                                  "type": "influxdb",
                                                  "hostname": "127.0.0.1",
                                                  "port": "8086",
                                                  "protocol": "http",
                                                  "database": "database",
                                                  "name": "Influxdb2",
                                                  "usetls": false,
                                                  "tls": "d50d0c9f.31e858",
                                                  "influxdbVersion": "2.0",
                                                  "url": "http://192.168.178.111:8086",
                                                  "timeout": "",
                                                  "rejectUnauthorized": false
                                              },
                                              {
                                                  "id": "d50d0c9f.31e858",
                                                  "type": "tls-config",
                                                  "name": "",
                                                  "cert": "",
                                                  "key": "",
                                                  "ca": "",
                                                  "certname": "",
                                                  "keyname": "",
                                                  "caname": "",
                                                  "servername": "",
                                                  "verifyservercert": false
                                              }
                                          ]
                                          

                                          3-5 ms Laufzeitunterschied ist rasend schnell - diesen Unterschied musst du verkraften. 😉 (wobei die ChangeNode in dem Fall schneller ist, als die function Node).

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

                                            @mickym
                                            Wenn ich vom mqtt triggere, dann ist der Laufzeitunterschied nur 1 ms, aber weiterhin zugunsten der JSONata-Version.
                                            Das klappt perfekt.

                                            Eine Frage dazu:
                                            Ich möchte das täglich um Mitternacht + 1 Minute triggern. Dazu habe ich den cron-plus genommen. Dieser verändert aber den msg.payload. Wo setze ich den Node am besten hin?

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            913
                                            Online

                                            31.7k
                                            Users

                                            79.9k
                                            Topics

                                            1.3m
                                            Posts

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