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. JSON oder JavaScript Objekt in iobroker Datenpunkte zerlegen

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    JSON oder JavaScript Objekt in iobroker Datenpunkte zerlegen

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

      @frank579 Na dann hast Du leider Deine ganze Node ersetzt - Du solltest eigentlich nur wie unter beschrieben den Subflow nehmen.

      2f7f5dd2-198e-4a7f-8a55-c2e3f431860e-image.png

      F 1 Reply Last reply Reply Quote 0
      • F
        Frank579 @mickym last edited by

        @mickym hatte ich auch so gemacht, dacht ich ... 🙂 schaue ich direkt mal nach

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

          @frank579 sagte in JSON oder JavaScript Objekt in iobroker Datenpunkte zerlegen:

          @mickym hatte ich auch so gemacht, dacht ich ... 🙂 schaue ich direkt mal nach

          Standardmässig steht in der Node

          665e4a8d-64c4-43af-b044-e5aa4ed78211-image.png

          Daher das objRoot.

          Da musst Du wieder den eigenen Namen eintragen unter dem das unter 0_userdata.0 auftauchen soll und wenn Du einen ganzen Baum schreiben willst, muss das keepTopic auf true.

          1 Reply Last reply Reply Quote 0
          • F
            Frank579 last edited by

            @mickym genau so war es.
            wenn ich jetzt wieder den ganzen baum vom 3EM haben möchte bekomme ich immer den im log :

            	1 Nov 15:55:58 - [error] [json:6908c423c0496cdd] Unexpected token o in JSON at position 0
            

            hast du eine idee was das sein könnte komme aber auch so klar benötige ja eigentlich nicht den ganzen Baum ist ja in den Mqtt-Adapter Datenpunkten schon drin, aber evtl. käme ich dann ohne den für die shellies klar nur mit node red, evtl. nehme ich mir auch was viel vor 🙄

            mickym 2 Replies Last reply Reply Quote 0
            • mickym
              mickym Most Active @Frank579 last edited by

              @frank579 Ja hab noch einen Fehler gefunden - das Problem ist, dass er Zahlen als JSON Objekte erkennt, Strings aber nicht, da kommt dann dieser Fehler. Nächste Version folgt. 😉

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

                @frank579 So nächste Version. 😉 - Ist wieder etwas komplexer, aber ich hoffe jetzt passt es:

                [
                   {
                       "id": "6e802f1553b18149",
                       "type": "subflow",
                       "name": "JSON or Obj to IOBroker",
                       "info": "# Creates an IOBroker tree\n\nThis node creates an IOBroker tree out of an Java-Object or JSON String.\n\nThe object tree will be created under 0_userdata.0\nIn addition to the JSON-String or Java Object as `msg.payload` it is necessary to specify a `msg.top` properity in addition to the msg-Object.\n\nThe object tree will be created under 0_userdata.0\n\nExisting `msg.topic` entries will be deleted.\nAn iobroker-out node has to be appended to this subflow node. It is not part of the subflow itself. No topic should be specified in the iobroker out node.\n\nIs `msg.top` property isn't defined, the `top` property of the subflow-node is used. \n\nIn the properties of the subflow node a new property `keepTopic` has been added. Default is _false_ to keep the current behaviour. If set to _true_ then the originial topic will be placed between the `top` property of the subflow node and the property of the analyzed JSON object.\n\n**Attention:**\nIf msg.top and top is empty, all msg.topics (msg.topic) will be directly prefixed with 0_userdata.0. . \n\n**Update 13.09.2022:**\nSpaces in topics of objects are no longer replaced with underscores in objects. No differences between all data types.\n\n# Erstellt einen Objektbaum im ioBroker\n\nDiese Node erstellt einen Objektbaum im ioBroker aus einem JAVA Objekt bzw. einem JSON String. \n\nDer Baum wird in jedem Fall unter 0_userdata.0 erstellt und zwar unter dem Topic der in` msg.top` mitgegeben wurde. In der `msg.payload` befindet sich dann der JSON String oder das entsprechende Objekt.\n\nExistierende `msg.topic `Einträge werden gelöscht.\nEin entsprechende iobroker-out Node muss an den Flow angehängt werden. Sie ist nicht Bestandteil des Subflows. In dieser iobroker-out Node darf kein Topic angegeben werden. \n\nFalls msg.top nicht definiert wurde, wird der `top`-Wert der Subflow-Node verwendet.\n\nIn den Eigenschaften der Subflow-Node wurde ein neuer Parameter `keepTopic` hinzugefügt. Standardwert ist _false_, um das bisherige Verhalten beizubehalten. Setzt man die Eigenschaft auf _true_, dann wird das originale Topic zwischen der `top` Eigenschaft der Subflow-Node und Eigenschaft des analysierten JSON Objektes eingefügt.\n\n**Achtung:**\nWenn top und msg.top leer ist, werden alle msg.topics (msg.topic) direkt unter dem Präfix 0_userdata.0., angelegt bzw. ausgegeben. \n\n**Update 13.09.2022:**\nLeerzeichen werden in Topics von Objekten nicht mehr durch Unterstriche ersetzt. Es gibt keine Unterschiede mehr zwischen den Datentypen.",
                       "category": "",
                       "in": [
                           {
                               "x": 60,
                               "y": 160,
                               "wires": [
                                   {
                                       "id": "554b8c663bcb46c2"
                                   }
                               ]
                           }
                       ],
                       "out": [
                           {
                               "x": 2620,
                               "y": 280,
                               "wires": [
                                   {
                                       "id": "0962842ebd23e0d7",
                                       "port": 0
                                   }
                               ]
                           }
                       ],
                       "env": [
                           {
                               "name": "top",
                               "type": "str",
                               "value": "objRoot"
                           },
                           {
                               "name": "keepTopic",
                               "type": "bool",
                               "value": "false"
                           }
                       ],
                       "meta": {},
                       "color": "#E2D96E",
                       "icon": "node-red/batch.svg"
                   },
                   {
                       "id": "3e11e8338f694832",
                       "type": "split",
                       "z": "6e802f1553b18149",
                       "name": "split object",
                       "splt": "\\n",
                       "spltType": "str",
                       "arraySplt": 1,
                       "arraySpltType": "len",
                       "stream": false,
                       "addname": "key",
                       "x": 1370,
                       "y": 160,
                       "wires": [
                           [
                               "0562a4249c8b856b"
                           ]
                       ]
                   },
                   {
                       "id": "0562a4249c8b856b",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "add key to topic",
                       "rules": [
                           {
                               "t": "set",
                               "p": "stateName",
                               "pt": "msg",
                               "to": "key",
                               "tot": "msg"
                           },
                           {
                               "t": "set",
                               "p": "topic",
                               "pt": "msg",
                               "to": "topic  & '.' & key",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 1560,
                       "y": 160,
                       "wires": [
                           [
                               "ddc90985bef0fafa"
                           ]
                       ]
                   },
                   {
                       "id": "ddc90985bef0fafa",
                       "type": "switch",
                       "z": "6e802f1553b18149",
                       "name": "is type?",
                       "property": "payload",
                       "propertyType": "msg",
                       "rules": [
                           {
                               "t": "istype",
                               "v": "array",
                               "vt": "array"
                           },
                           {
                               "t": "istype",
                               "v": "object",
                               "vt": "object"
                           },
                           {
                               "t": "else"
                           }
                       ],
                       "checkall": "true",
                       "repair": false,
                       "outputs": 3,
                       "x": 1740,
                       "y": 160,
                       "wires": [
                           [
                               "bfce19b206660fbe"
                           ],
                           [
                               "3e11e8338f694832"
                           ],
                           [
                               "1a8c03d866b85b12"
                           ]
                       ]
                   },
                   {
                       "id": "bfce19b206660fbe",
                       "type": "split",
                       "z": "6e802f1553b18149",
                       "name": "split array",
                       "splt": "\\n",
                       "spltType": "str",
                       "arraySplt": 1,
                       "arraySpltType": "len",
                       "stream": false,
                       "addname": "",
                       "x": 780,
                       "y": 280,
                       "wires": [
                           [
                               "e89927810c6d75ec"
                           ]
                       ]
                   },
                   {
                       "id": "e89927810c6d75ec",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "add index to topic",
                       "rules": [
                           {
                               "t": "set",
                               "p": "topic",
                               "pt": "msg",
                               "to": "topic  & '.' & parts.index",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 970,
                       "y": 280,
                       "wires": [
                           [
                               "a4d1a5d04564dc77"
                           ]
                       ]
                   },
                   {
                       "id": "f5d52c6a57d08904",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "finalize msg.topic",
                       "rules": [
                           {
                               "t": "set",
                               "p": "top",
                               "pt": "msg",
                               "to": "'0_userdata.0.' & top",
                               "tot": "jsonata"
                           },
                           {
                               "t": "set",
                               "p": "topic",
                               "pt": "msg",
                               "to": "top & '.' & topic",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 2170,
                       "y": 240,
                       "wires": [
                           [
                               "0962842ebd23e0d7"
                           ]
                       ]
                   },
                   {
                       "id": "1a8c03d866b85b12",
                       "type": "switch",
                       "z": "6e802f1553b18149",
                       "name": "is msg.top != null",
                       "property": "top",
                       "propertyType": "msg",
                       "rules": [
                           {
                               "t": "nnull"
                           },
                           {
                               "t": "null"
                           }
                       ],
                       "checkall": "true",
                       "repair": false,
                       "outputs": 2,
                       "x": 1950,
                       "y": 280,
                       "wires": [
                           [
                               "f5d52c6a57d08904"
                           ],
                           [
                               "74c895ce724750de"
                           ]
                       ]
                   },
                   {
                       "id": "e023fe88445ce43e",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "",
                       "rules": [
                           {
                               "t": "delete",
                               "p": "topic",
                               "pt": "msg"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 350,
                       "y": 200,
                       "wires": [
                           [
                               "3649300b4c233b10"
                           ]
                       ]
                   },
                   {
                       "id": "3649300b4c233b10",
                       "type": "switch",
                       "z": "6e802f1553b18149",
                       "name": "is type?",
                       "property": "payload",
                       "propertyType": "msg",
                       "rules": [
                           {
                               "t": "istype",
                               "v": "json",
                               "vt": "json"
                           },
                           {
                               "t": "istype",
                               "v": "array",
                               "vt": "array"
                           },
                           {
                               "t": "istype",
                               "v": "object",
                               "vt": "object"
                           },
                           {
                               "t": "else"
                           }
                       ],
                       "checkall": "true",
                       "repair": false,
                       "outputs": 4,
                       "x": 600,
                       "y": 160,
                       "wires": [
                           [
                               "fc7913a8524badb7"
                           ],
                           [
                               "bfce19b206660fbe"
                           ],
                           [
                               "3e11e8338f694832"
                           ],
                           [
                               "9ac3cc3681e8b6c6"
                           ]
                       ]
                   },
                   {
                       "id": "1b8480cd2df7ba3f",
                       "type": "comment",
                       "z": "6e802f1553b18149",
                       "name": "Array",
                       "info": "",
                       "x": 600,
                       "y": 280,
                       "wires": []
                   },
                   {
                       "id": "b3541807672be040",
                       "type": "comment",
                       "z": "6e802f1553b18149",
                       "name": "object",
                       "info": "",
                       "x": 1340,
                       "y": 100,
                       "wires": []
                   },
                   {
                       "id": "a4d1a5d04564dc77",
                       "type": "switch",
                       "z": "6e802f1553b18149",
                       "name": "is type?",
                       "property": "payload",
                       "propertyType": "msg",
                       "rules": [
                           {
                               "t": "istype",
                               "v": "object",
                               "vt": "object"
                           },
                           {
                               "t": "istype",
                               "v": "array",
                               "vt": "array"
                           },
                           {
                               "t": "else"
                           }
                       ],
                       "checkall": "true",
                       "repair": false,
                       "outputs": 3,
                       "x": 1160,
                       "y": 280,
                       "wires": [
                           [
                               "3e11e8338f694832"
                           ],
                           [
                               "bfce19b206660fbe"
                           ],
                           [
                               "a096a93bb82b7a93"
                           ]
                       ]
                   },
                   {
                       "id": "74c895ce724750de",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "finalize msg.topic",
                       "rules": [
                           {
                               "t": "set",
                               "p": "top",
                               "pt": "msg",
                               "to": "top",
                               "tot": "env"
                           },
                           {
                               "t": "set",
                               "p": "top",
                               "pt": "msg",
                               "to": "'0_userdata.0.' & top",
                               "tot": "jsonata"
                           },
                           {
                               "t": "set",
                               "p": "topic",
                               "pt": "msg",
                               "to": "top & '.' & topic",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 2170,
                       "y": 320,
                       "wires": [
                           [
                               "0962842ebd23e0d7"
                           ]
                       ]
                   },
                   {
                       "id": "554b8c663bcb46c2",
                       "type": "switch",
                       "z": "6e802f1553b18149",
                       "name": "",
                       "property": "keepTopic",
                       "propertyType": "env",
                       "rules": [
                           {
                               "t": "true"
                           },
                           {
                               "t": "false"
                           }
                       ],
                       "checkall": "true",
                       "repair": false,
                       "outputs": 2,
                       "x": 170,
                       "y": 160,
                       "wires": [
                           [
                               "e30ba9f0483285e4"
                           ],
                           [
                               "e023fe88445ce43e"
                           ]
                       ]
                   },
                   {
                       "id": "e30ba9f0483285e4",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "",
                       "rules": [
                           {
                               "t": "change",
                               "p": "topic",
                               "pt": "msg",
                               "from": "/",
                               "fromt": "str",
                               "to": ".",
                               "tot": "str"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 350,
                       "y": 120,
                       "wires": [
                           [
                               "3649300b4c233b10"
                           ]
                       ]
                   },
                   {
                       "id": "0962842ebd23e0d7",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "translate invalid chars in topic",
                       "rules": [
                           {
                               "t": "change",
                               "p": "topic",
                               "pt": "msg",
                               "from": "..",
                               "fromt": "str",
                               "to": ".",
                               "tot": "str"
                           },
                           {
                               "t": "change",
                               "p": "topic",
                               "pt": "msg",
                               "from": "€",
                               "fromt": "str",
                               "to": "EUR",
                               "tot": "str"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 2430,
                       "y": 280,
                       "wires": [
                           []
                       ]
                   },
                   {
                       "id": "9ac3cc3681e8b6c6",
                       "type": "change",
                       "z": "6e802f1553b18149",
                       "name": "set topic, if empty",
                       "rules": [
                           {
                               "t": "set",
                               "p": "topic",
                               "pt": "msg",
                               "to": "topic ? topic : $type(payload)\t",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 950,
                       "y": 200,
                       "wires": [
                           [
                               "a096a93bb82b7a93"
                           ]
                       ]
                   },
                   {
                       "id": "fc7913a8524badb7",
                       "type": "json",
                       "z": "6e802f1553b18149",
                       "name": "",
                       "property": "payload",
                       "action": "obj",
                       "pretty": false,
                       "x": 750,
                       "y": 100,
                       "wires": [
                           [
                               "d9e7bdd4c48a8aa1"
                           ]
                       ]
                   },
                   {
                       "id": "d9e7bdd4c48a8aa1",
                       "type": "switch",
                       "z": "6e802f1553b18149",
                       "name": "is type?",
                       "property": "payload",
                       "propertyType": "msg",
                       "rules": [
                           {
                               "t": "istype",
                               "v": "array",
                               "vt": "array"
                           },
                           {
                               "t": "istype",
                               "v": "object",
                               "vt": "object"
                           },
                           {
                               "t": "else"
                           }
                       ],
                       "checkall": "true",
                       "repair": false,
                       "outputs": 3,
                       "x": 900,
                       "y": 100,
                       "wires": [
                           [
                               "1520be42bcc2145e"
                           ],
                           [
                               "1520be42bcc2145e"
                           ],
                           [
                               "9ac3cc3681e8b6c6"
                           ]
                       ]
                   },
                   {
                       "id": "a096a93bb82b7a93",
                       "type": "junction",
                       "z": "6e802f1553b18149",
                       "x": 1380,
                       "y": 280,
                       "wires": [
                           [
                               "1a8c03d866b85b12"
                           ]
                       ]
                   },
                   {
                       "id": "1520be42bcc2145e",
                       "type": "junction",
                       "z": "6e802f1553b18149",
                       "x": 480,
                       "y": 20,
                       "wires": [
                           [
                               "3649300b4c233b10"
                           ]
                       ]
                   },
                   {
                       "id": "436b84bced4aeddd",
                       "type": "subflow:6e802f1553b18149",
                       "z": "393214410c8f2f15",
                       "name": "",
                       "x": 590,
                       "y": 840,
                       "wires": [
                           [
                               "624a03b2c28140de"
                           ]
                       ]
                   }
                ]
                

                Außerdem werden jetzt (!!!) wenn gar kein topic gesetzt ist, das topic gelöscht werden soll und von Anfang an skalare Werte übergeben werden, einfach als topic der Datentyp gesetzt. Damit sollte das mit dem . am Ende nicht mehr vorkommen. Das lag an skalaren Typen ohne topic.

                6a1af9c8-a604-4ba1-800a-cb9b3d07a2a5-image.png

                Ich hoffe passt jetzt.

                @Frank579 - eine kurze Rückmeldung wäre Klasse, dann ändere ich den Flow im 1. Post wieder.

                F 1 Reply Last reply Reply Quote 1
                • F
                  Frank579 @mickym last edited by

                  @mickym
                  Auf den ersten Blick sieht alles gut aus, log bleibt sauber 🙂
                  Top Arbeit von dir 👍

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

                    @frank579 Gut, dann übernehm ich diese Version mal in den ersten Post - Historie hab ich schon geändert.

                    Danke für Rückmeldung.

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

                      @mickym sagte in JSON oder JavaScript Objekt in iobroker Datenpunkte zerlegen:

                      @noah3112 Das ist Deine mqtt-IN Node - da hast wahrscheinlich angegeben, dass es sich um ein analysiertes JSON Objekt handelt.

                      bc3bbca0-c313-4237-9707-082a99708bd3-image.png

                      Du musst das nur wieder auf String und Buffer umstellen - der Subflow wandelt Strings automatisch um. Das Problem mit der Analyse eines analysierten JSON Objektes der mqtt-In Node schmeisst den Fehler bei Analyse des Objekts bei normalen Strings. Ich hab das im Node Red Forum schon moniert und hoffe, dass es in der Version 3 behoben wird. Also einfach wieder auf String und Buffer umstellen.

                      Falls es Dich interessiert habe ich das Problem hier beschrieben.
                      https://discourse.nodered.org/t/improvement-of-mqtt-in-nodes/55445/17

                      Falls Du in anderen Situationen trotzdem die Funktion des analysierten JSON Objektes in Deiner mqtt-IN Node nutzen willst und aber auch teilweise Strings hast, dann kann man dass auch mit einer Catch NOde abfangen. In dem Fall kann aber der Subflow damit umgehen, da die erste Switch Node sogar den Typ JSON String kennt. 😉

                      Grundsätzlich kannst Du dich schon verlassen, welche Node einen Fehler verursacht:

                      f73f675a-df9b-4fc3-9a50-1c811db3e033-image.png

                      Also die Node "zigbee2mqtt to iobroker"

                      Also lange Rede - kurzer Sinn - einfach wieder auf Auto-Erkennung (string or buffer) umstellen.

                      Dieses Thema ist übrigens seit der neuest Node-Red Version (also NodeRed Adapter 4.0.0) nicht mehr relevant. Das JSON-Objekt wird nun auch bei Strings und skalaren Werten von der mqtt-IN Node richtig interpretiert:

                      61b8dcbd-57cf-464b-ba68-d46ab62b46d2-image.png

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

                        So ich habe die Eingangsanleitung aktualisiert, damit man sich die Änderungen nicht alle aus dem Thread zusammensuchen muss. 😉

                        W 2 Replies Last reply Reply Quote 1
                        • W
                          warp-it @mickym last edited by

                          @mickym said in JSON oder JavaScript Objekt in iobroker Datenpunkte zerlegen:

                          So ich habe die Eingangsanleitung aktualisiert, damit man sich die Änderungen nicht alle aus dem Thread zusammensuchen muss. 😉

                          Extrem cool, vielen Dank!

                          1 Reply Last reply Reply Quote 0
                          • W
                            warp-it @mickym last edited by

                            @mickym

                            Mit Deinem Subflow versuche ich per ModbusTCP Daten aus einer Huawei Photovoltaik einzulesen. Soweit funktioniert das auch, aber ich verstehe die Inhalte des entstehenden Array nicht:

                            01cc401b-2e76-44c0-8769-b1c7e449a5b1-image.png
                            0660b769-586f-455e-bdf6-b252c4617969-image.png

                            37109-37110 sieht gut aus, teilt man den Wert durch 100 erhält man den korrekten Strom-Wert.
                            Aus 37107-37108 hätte ich im Ziel-Array einen dreistelligen negativen Wert erwartet, aber nicht zwei Werte über 65000?

                            Was raffe ich da wieder nicht? 😉

                            Viele Grüße
                            Heinrich

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

                              @warp-it Ich denke da bist du in diesem Thread an der falschen Adresse. 😉 - Der Subflow macht nichts anderes als ein Objekt zu zerlegen und in eigene Datenpunkte zu schreiben.

                              In diesem Objekt sind die Werte ja schon enthalten:
                              030f323a-bb6e-4772-a6e1-d770650d1dd2-image.png

                              Und dieser Subflow macht nichts weiter als diese Daten auszusplitten. Wie Du auf die anderen Werte kommst, ist eine Modbus Geschichte.

                              Aus 37107-37108 hätte ich im Ziel-Array einen dreistelligen negativen Wert erwartet, aber nicht zwei Werte über 65000?

                              Sowas kann ich ja gar nicht nachvollziehen. Das würde ich in dem anderen Thread mit den Modbus Spezialisten diskutieren. Falls Du die Buffer Node nutzt, dann muss man halt mit den Daten schauen, was Du da rechnest.

                              Dieser Flow - verändert grundsätzlich KEINE Originalwerte.

                              W 1 Reply Last reply Reply Quote 0
                              • W
                                warp-it @mickym last edited by

                                @mickym said in JSON oder JavaScript Objekt in iobroker Datenpunkte zerlegen:

                                Der Subflow macht nichts anderes als ein Objekt zu zerlegen und in eigene Datenpunkte zu schreiben.

                                In der alten Variante, in der die Felder einzeln ausgelesen werden, scheint aber auch nix gerechnet zu werden:

                                0221234a-01f5-4c72-96aa-ff3ecf3fe7e3-image.png

                                c212528b-2ebb-417b-bad3-63ca72f41b9d-image.png

                                Naja, von der alten Variante wollte ich ja ursprünglich weg, weil wohl durch das gehäufte wiederholte Auslesen der einzelnen Felder haufenweise Logeinträge entstanden sind, die aber durch das von @joschipp empfohlene Update von node-red-contrib-modbus tatsächlich verschwunden sind.

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

                                  @warp-it Nun wie gesagt, wenn es der falsche 32bit Wert ist (be statt le) signed oder unsigned - kann ganz schnell eine komischen Wert erzeugen. Wie gesagt, dein Objekt enthielt ja bereits die 65xxx.

                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    harald07 last edited by harald07

                                    @mickym Hallo und vielen Dank für das teilen Deines Wissen.

                                    Ich habe dein Beispiel zum Einlesen einer Ordnerstruktur aus dem ioBroker nach gebaut.
                                    545e4e74-c3ff-4535-9872-ce45360751fc-image.png

                                    Als Resultat erhalte ich diese Ausgabe:

                                    {
                                        "Dc.Power": -207.4,
                                        "InstalledCapacity": 1400,
                                        "ConsumedAmphours": -116,
                                        "Capacity": 1284,
                                        "Soc": 92.2,
                                        "TimeToGo": 768059.9,
                                        "Balancing": 0,
                                        "Dc.Voltage": 53.18,
                                        "Dc.Current": -3.9,
                                        "Dc.Temperature": 25.4,
                                        "Info.MaxChargeVoltage": 55.3,
                                        "Info.MaxChargeCurrent": 340,
                                        "Info.MaxDischargeCurrent": 425,
                                        "History.ChargeCycles": 46,
                                        "History.MinimumVoltage": 34.43,
                                        "History.MaximumVoltage": 58.77,
                                        "History.TotalAhDrawn": -60168.2,
                                        "System.MinVoltageCellId": "P4_Z2",
                                        "System.MinCellVoltage": 3.322,
                                        "System.MaxVoltageCellId": "P4_Z1",
                                        "System.MaxCellVoltage": 3.324,
                                        "System.NrOfModulesOnline": 5,
                                        "System.NrOfModulesOffline": 0,
                                        "System.NrOfModulesBlockingCharge": 0,
                                        "System.NrOfModulesBlockingDischarge": 0,
                                        "Io.AllowToCharge": 1,
                                        "Io.AllowToDischarge": 1,
                                        "Io.AllowToBalance": 1
                                    }
                                    

                                    Das json möchte per MQTT an an einen Treiber in VenusOS senden. Der Treiber erwartet die Daten in diesem Format:

                                    {
                                        "Dc": {
                                            "Power": 321.6,                       
                                            "Voltage": 52.7,                      
                                            "Current": 6.10,                      
                                            "Temperature": 23                     
                                        },
                                        "InstalledCapacity": 200.0,               
                                        "ConsumedAmphours": 74.5,                 
                                        "Capacity": 125.5,                        
                                        "Soc": 63,                                
                                        "TimeToGo": 43967,                        
                                        "Balancing": 0,
                                        "Info": {              
                                            "MaxChargeVoltage": 55.2,             
                                            "MaxChargeCurrent": 80.0,             
                                            "MaxDischargeCurrent": 120.0          
                                        },
                                        "History": {
                                            "ChargeCycles": 5,                    
                                            "MinimumVoltage": 40.8,               
                                            "MaximumVoltage": 58.4,               
                                            "TotalAhDrawn": 1057.3                
                                        },
                                        "System": {
                                            "MinVoltageCellId": "C3",             
                                            "MinCellVoltage": 3.392,              
                                            "MaxVoltageCellId": "C15",            
                                            "MaxCellVoltage": 3.417,                            
                                    
                                            "NrOfModulesOnline": 0,               
                                            "NrOfModulesOffline": 0,              
                                    
                                            "NrOfModulesBlockingCharge": 0,       
                                            "NrOfModulesBlockingDischarge": 0     
                                        },
                                        "Io": {
                                            "AllowToCharge": 0,                   
                                            "AllowToDischarge": 0,                
                                            "AllowToBalance": 0,                 
                                        }
                                    }
                                    

                                    Kannst Du mir sagen wie ich das hinbekommen könnte?

                                    Viele Grüße
                                    Harald

                                    Es ist schon Wahnsinn was mittlerweile alles geht.
                                    Ich habe inzwischen die Lösung von ChatGPT bekommen. ChatGPT hat einen Code ausgespuckt den ich nur noch in eine function Node kopieren brauchte.

                                    var inputJson = JSON.parse(msg.payload);
                                    
                                    var outputJson = {
                                        "Dc": {
                                            "Power": inputJson["Dc.Power"],
                                            "Voltage": inputJson["Dc.Voltage"],
                                            "Current": inputJson["Dc.Current"],
                                            "Temperature": inputJson["Dc.Temperature"]
                                        },
                                        "InstalledCapacity": inputJson["InstalledCapacity"],
                                        "ConsumedAmphours": inputJson["ConsumedAmphours"],
                                        "Capacity": inputJson["Capacity"],
                                        "Soc": inputJson["Soc"],
                                        "TimeToGo": inputJson["TimeToGo"],
                                        "Balancing": inputJson["Balancing"],
                                        "Info": {
                                            "MaxChargeVoltage": inputJson["Info.MaxChargeVoltage"],
                                            "MaxChargeCurrent": inputJson["Info.MaxChargeCurrent"],
                                            "MaxDischargeCurrent": inputJson["Info.MaxDischargeCurrent"]
                                        },
                                        "History": {
                                            "ChargeCycles": inputJson["History.ChargeCycles"],
                                            "MinimumVoltage": inputJson["History.MinimumVoltage"],
                                            "MaximumVoltage": inputJson["History.MaximumVoltage"],
                                            "TotalAhDrawn": inputJson["History.TotalAhDrawn"]
                                        },
                                        "System": {
                                            "MinVoltageCellId": inputJson["System.MinVoltageCellId"],
                                            "MinCellVoltage": inputJson["System.MinCellVoltage"],
                                            "MaxVoltageCellId": inputJson["System.MaxVoltageCellId"],
                                            "MaxCellVoltage": inputJson["System.MaxCellVoltage"],
                                            "NrOfModulesOnline": inputJson["System.NrOfModulesOnline"],
                                            "NrOfModulesOffline": inputJson["System.NrOfModulesOffline"],
                                            "NrOfModulesBlockingCharge": inputJson["System.NrOfModulesBlockingCharge"],
                                            "NrOfModulesBlockingDischarge": inputJson["System.NrOfModulesBlockingDischarge"]
                                        },
                                        "Io": {
                                            "AllowToCharge": inputJson["Io.AllowToCharge"],
                                            "AllowToDischarge": inputJson["Io.AllowToDischarge"],
                                            "AllowToBalance": inputJson["Io.AllowToBalance"]
                                        }
                                    };
                                    
                                    msg.payload = outputJson;
                                    return msg;
                                    

                                    Wahnsinn!!!

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

                                      So ich habe wieder mal eine neue Version des Subflows erstellt, der verhindert dass Punkte in den Objekteigenschaften enthalten sind und somit ggf. den iobroker durcheinander bringt.

                                      Hier nun wieder eine neue Version:

                                      [
                                         {
                                             "id": "6e802f1553b18149",
                                             "type": "subflow",
                                             "name": "JSON or Obj to IOBroker",
                                             "info": "# Creates an IOBroker tree\n\nThis node creates an IOBroker tree out of an Java-Object or JSON String.\n\nThe object tree will be created under 0_userdata.0\nIn addition to the JSON-String or Java Object as `msg.payload` it is necessary to specify a `msg.top` properity in addition to the msg-Object.\n\nThe object tree will be created under 0_userdata.0\n\nExisting `msg.topic` entries will be deleted.\nAn iobroker-out node has to be appended to this subflow node. It is not part of the subflow itself. No topic should be specified in the iobroker out node.\n\nIs `msg.top` property isn't defined, the `top` property of the subflow-node is used. \n\nIn the properties of the subflow node a new property `keepTopic` has been added. Default is _false_ to keep the current behaviour. If set to _true_ then the originial topic will be placed between the `top` property of the subflow node and the property of the analyzed JSON object.\n\n**Attention:**\nIf msg.top and top is empty, all msg.topics (msg.topic) will be directly prefixed with 0_userdata.0. . \n\n**Update 13.09.2022:**\nSpaces in topics of objects are no longer replaced with underscores in objects. No differences between all data types.\n\n# Erstellt einen Objektbaum im ioBroker\n\nDiese Node erstellt einen Objektbaum im ioBroker aus einem JAVA Objekt bzw. einem JSON String. \n\nDer Baum wird in jedem Fall unter 0_userdata.0 erstellt und zwar unter dem Topic der in` msg.top` mitgegeben wurde. In der `msg.payload` befindet sich dann der JSON String oder das entsprechende Objekt.\n\nExistierende `msg.topic `Einträge werden gelöscht.\nEin entsprechende iobroker-out Node muss an den Flow angehängt werden. Sie ist nicht Bestandteil des Subflows. In dieser iobroker-out Node darf kein Topic angegeben werden. \n\nFalls msg.top nicht definiert wurde, wird der `top`-Wert der Subflow-Node verwendet.\n\nIn den Eigenschaften der Subflow-Node wurde ein neuer Parameter `keepTopic` hinzugefügt. Standardwert ist _false_, um das bisherige Verhalten beizubehalten. Setzt man die Eigenschaft auf _true_, dann wird das originale Topic zwischen der `top` Eigenschaft der Subflow-Node und Eigenschaft des analysierten JSON Objektes eingefügt.\n\n**Achtung:**\nWenn top und msg.top leer ist, werden alle msg.topics (msg.topic) direkt unter dem Präfix 0_userdata.0., angelegt bzw. ausgegeben. \n\n**Update 13.09.2022:**\nLeerzeichen werden in Topics von Objekten nicht mehr durch Unterstriche ersetzt. Es gibt keine Unterschiede mehr zwischen den Datentypen.",
                                             "category": "",
                                             "in": [
                                                 {
                                                     "x": 60,
                                                     "y": 160,
                                                     "wires": [
                                                         {
                                                             "id": "554b8c663bcb46c2"
                                                         }
                                                     ]
                                                 }
                                             ],
                                             "out": [
                                                 {
                                                     "x": 2620,
                                                     "y": 280,
                                                     "wires": [
                                                         {
                                                             "id": "0962842ebd23e0d7",
                                                             "port": 0
                                                         }
                                                     ]
                                                 }
                                             ],
                                             "env": [
                                                 {
                                                     "name": "top",
                                                     "type": "str",
                                                     "value": "objRoot"
                                                 },
                                                 {
                                                     "name": "keepTopic",
                                                     "type": "bool",
                                                     "value": "false"
                                                 }
                                             ],
                                             "meta": {},
                                             "color": "#E2D96E",
                                             "icon": "node-red/batch.svg"
                                         },
                                         {
                                             "id": "3e11e8338f694832",
                                             "type": "split",
                                             "z": "6e802f1553b18149",
                                             "name": "split object",
                                             "splt": "\\n",
                                             "spltType": "str",
                                             "arraySplt": 1,
                                             "arraySpltType": "len",
                                             "stream": false,
                                             "addname": "key",
                                             "x": 1370,
                                             "y": 160,
                                             "wires": [
                                                 [
                                                     "0562a4249c8b856b"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "0562a4249c8b856b",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "add key to topic",
                                             "rules": [
                                                 {
                                                     "t": "set",
                                                     "p": "stateName",
                                                     "pt": "msg",
                                                     "to": "key",
                                                     "tot": "msg"
                                                 },
                                                 {
                                                     "t": "change",
                                                     "p": "key",
                                                     "pt": "msg",
                                                     "from": ".",
                                                     "fromt": "str",
                                                     "to": "_",
                                                     "tot": "str"
                                                 },
                                                 {
                                                     "t": "set",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "to": "topic  & '.' & key",
                                                     "tot": "jsonata"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 1560,
                                             "y": 160,
                                             "wires": [
                                                 [
                                                     "ddc90985bef0fafa"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "ddc90985bef0fafa",
                                             "type": "switch",
                                             "z": "6e802f1553b18149",
                                             "name": "is type?",
                                             "property": "payload",
                                             "propertyType": "msg",
                                             "rules": [
                                                 {
                                                     "t": "istype",
                                                     "v": "array",
                                                     "vt": "array"
                                                 },
                                                 {
                                                     "t": "istype",
                                                     "v": "object",
                                                     "vt": "object"
                                                 },
                                                 {
                                                     "t": "else"
                                                 }
                                             ],
                                             "checkall": "true",
                                             "repair": false,
                                             "outputs": 3,
                                             "x": 1740,
                                             "y": 160,
                                             "wires": [
                                                 [
                                                     "bfce19b206660fbe"
                                                 ],
                                                 [
                                                     "3e11e8338f694832"
                                                 ],
                                                 [
                                                     "1a8c03d866b85b12"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "bfce19b206660fbe",
                                             "type": "split",
                                             "z": "6e802f1553b18149",
                                             "name": "split array",
                                             "splt": "\\n",
                                             "spltType": "str",
                                             "arraySplt": 1,
                                             "arraySpltType": "len",
                                             "stream": false,
                                             "addname": "",
                                             "x": 780,
                                             "y": 280,
                                             "wires": [
                                                 [
                                                     "e89927810c6d75ec"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "e89927810c6d75ec",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "add index to topic",
                                             "rules": [
                                                 {
                                                     "t": "set",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "to": "topic  & '.' & parts.index",
                                                     "tot": "jsonata"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 970,
                                             "y": 280,
                                             "wires": [
                                                 [
                                                     "a4d1a5d04564dc77"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "f5d52c6a57d08904",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "finalize msg.topic",
                                             "rules": [
                                                 {
                                                     "t": "set",
                                                     "p": "top",
                                                     "pt": "msg",
                                                     "to": "'0_userdata.0.' & top",
                                                     "tot": "jsonata"
                                                 },
                                                 {
                                                     "t": "set",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "to": "top & '.' & topic",
                                                     "tot": "jsonata"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 2170,
                                             "y": 240,
                                             "wires": [
                                                 [
                                                     "0962842ebd23e0d7"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "1a8c03d866b85b12",
                                             "type": "switch",
                                             "z": "6e802f1553b18149",
                                             "name": "is msg.top != null",
                                             "property": "top",
                                             "propertyType": "msg",
                                             "rules": [
                                                 {
                                                     "t": "nnull"
                                                 },
                                                 {
                                                     "t": "null"
                                                 }
                                             ],
                                             "checkall": "true",
                                             "repair": false,
                                             "outputs": 2,
                                             "x": 1950,
                                             "y": 280,
                                             "wires": [
                                                 [
                                                     "f5d52c6a57d08904"
                                                 ],
                                                 [
                                                     "74c895ce724750de"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "e023fe88445ce43e",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "",
                                             "rules": [
                                                 {
                                                     "t": "delete",
                                                     "p": "topic",
                                                     "pt": "msg"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 350,
                                             "y": 200,
                                             "wires": [
                                                 [
                                                     "3649300b4c233b10"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "3649300b4c233b10",
                                             "type": "switch",
                                             "z": "6e802f1553b18149",
                                             "name": "is type?",
                                             "property": "payload",
                                             "propertyType": "msg",
                                             "rules": [
                                                 {
                                                     "t": "istype",
                                                     "v": "json",
                                                     "vt": "json"
                                                 },
                                                 {
                                                     "t": "istype",
                                                     "v": "array",
                                                     "vt": "array"
                                                 },
                                                 {
                                                     "t": "istype",
                                                     "v": "object",
                                                     "vt": "object"
                                                 },
                                                 {
                                                     "t": "else"
                                                 }
                                             ],
                                             "checkall": "true",
                                             "repair": false,
                                             "outputs": 4,
                                             "x": 600,
                                             "y": 160,
                                             "wires": [
                                                 [
                                                     "fc7913a8524badb7"
                                                 ],
                                                 [
                                                     "bfce19b206660fbe"
                                                 ],
                                                 [
                                                     "3e11e8338f694832"
                                                 ],
                                                 [
                                                     "9ac3cc3681e8b6c6"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "1b8480cd2df7ba3f",
                                             "type": "comment",
                                             "z": "6e802f1553b18149",
                                             "name": "Array",
                                             "info": "",
                                             "x": 600,
                                             "y": 280,
                                             "wires": []
                                         },
                                         {
                                             "id": "b3541807672be040",
                                             "type": "comment",
                                             "z": "6e802f1553b18149",
                                             "name": "object",
                                             "info": "",
                                             "x": 1340,
                                             "y": 100,
                                             "wires": []
                                         },
                                         {
                                             "id": "a4d1a5d04564dc77",
                                             "type": "switch",
                                             "z": "6e802f1553b18149",
                                             "name": "is type?",
                                             "property": "payload",
                                             "propertyType": "msg",
                                             "rules": [
                                                 {
                                                     "t": "istype",
                                                     "v": "object",
                                                     "vt": "object"
                                                 },
                                                 {
                                                     "t": "istype",
                                                     "v": "array",
                                                     "vt": "array"
                                                 },
                                                 {
                                                     "t": "else"
                                                 }
                                             ],
                                             "checkall": "true",
                                             "repair": false,
                                             "outputs": 3,
                                             "x": 1160,
                                             "y": 280,
                                             "wires": [
                                                 [
                                                     "3e11e8338f694832"
                                                 ],
                                                 [
                                                     "bfce19b206660fbe"
                                                 ],
                                                 [
                                                     "a096a93bb82b7a93"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "74c895ce724750de",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "finalize msg.topic",
                                             "rules": [
                                                 {
                                                     "t": "set",
                                                     "p": "top",
                                                     "pt": "msg",
                                                     "to": "top",
                                                     "tot": "env"
                                                 },
                                                 {
                                                     "t": "set",
                                                     "p": "top",
                                                     "pt": "msg",
                                                     "to": "'0_userdata.0.' & top",
                                                     "tot": "jsonata"
                                                 },
                                                 {
                                                     "t": "set",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "to": "top & '.' & topic",
                                                     "tot": "jsonata"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 2170,
                                             "y": 320,
                                             "wires": [
                                                 [
                                                     "0962842ebd23e0d7"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "554b8c663bcb46c2",
                                             "type": "switch",
                                             "z": "6e802f1553b18149",
                                             "name": "",
                                             "property": "keepTopic",
                                             "propertyType": "env",
                                             "rules": [
                                                 {
                                                     "t": "true"
                                                 },
                                                 {
                                                     "t": "false"
                                                 }
                                             ],
                                             "checkall": "true",
                                             "repair": false,
                                             "outputs": 2,
                                             "x": 170,
                                             "y": 160,
                                             "wires": [
                                                 [
                                                     "e30ba9f0483285e4"
                                                 ],
                                                 [
                                                     "e023fe88445ce43e"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "e30ba9f0483285e4",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "",
                                             "rules": [
                                                 {
                                                     "t": "change",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "from": "/",
                                                     "fromt": "str",
                                                     "to": ".",
                                                     "tot": "str"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 350,
                                             "y": 120,
                                             "wires": [
                                                 [
                                                     "3649300b4c233b10"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "0962842ebd23e0d7",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "translate invalid chars in topic",
                                             "rules": [
                                                 {
                                                     "t": "change",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "from": "..",
                                                     "fromt": "str",
                                                     "to": ".",
                                                     "tot": "str"
                                                 },
                                                 {
                                                     "t": "change",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "from": "€",
                                                     "fromt": "str",
                                                     "to": "EUR",
                                                     "tot": "str"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 2430,
                                             "y": 280,
                                             "wires": [
                                                 []
                                             ]
                                         },
                                         {
                                             "id": "9ac3cc3681e8b6c6",
                                             "type": "change",
                                             "z": "6e802f1553b18149",
                                             "name": "set topic, if empty",
                                             "rules": [
                                                 {
                                                     "t": "set",
                                                     "p": "topic",
                                                     "pt": "msg",
                                                     "to": "topic ? topic : $type(payload)\t",
                                                     "tot": "jsonata"
                                                 }
                                             ],
                                             "action": "",
                                             "property": "",
                                             "from": "",
                                             "to": "",
                                             "reg": false,
                                             "x": 950,
                                             "y": 200,
                                             "wires": [
                                                 [
                                                     "a096a93bb82b7a93"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "fc7913a8524badb7",
                                             "type": "json",
                                             "z": "6e802f1553b18149",
                                             "name": "",
                                             "property": "payload",
                                             "action": "obj",
                                             "pretty": false,
                                             "x": 750,
                                             "y": 100,
                                             "wires": [
                                                 [
                                                     "d9e7bdd4c48a8aa1"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "d9e7bdd4c48a8aa1",
                                             "type": "switch",
                                             "z": "6e802f1553b18149",
                                             "name": "is type?",
                                             "property": "payload",
                                             "propertyType": "msg",
                                             "rules": [
                                                 {
                                                     "t": "istype",
                                                     "v": "array",
                                                     "vt": "array"
                                                 },
                                                 {
                                                     "t": "istype",
                                                     "v": "object",
                                                     "vt": "object"
                                                 },
                                                 {
                                                     "t": "else"
                                                 }
                                             ],
                                             "checkall": "true",
                                             "repair": false,
                                             "outputs": 3,
                                             "x": 900,
                                             "y": 100,
                                             "wires": [
                                                 [
                                                     "1520be42bcc2145e"
                                                 ],
                                                 [
                                                     "1520be42bcc2145e"
                                                 ],
                                                 [
                                                     "9ac3cc3681e8b6c6"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "a096a93bb82b7a93",
                                             "type": "junction",
                                             "z": "6e802f1553b18149",
                                             "x": 1380,
                                             "y": 280,
                                             "wires": [
                                                 [
                                                     "1a8c03d866b85b12"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "1520be42bcc2145e",
                                             "type": "junction",
                                             "z": "6e802f1553b18149",
                                             "x": 480,
                                             "y": 20,
                                             "wires": [
                                                 [
                                                     "3649300b4c233b10"
                                                 ]
                                             ]
                                         },
                                         {
                                             "id": "8d36fab85a67b5f5",
                                             "type": "subflow:6e802f1553b18149",
                                             "z": "7e6af0015415146d",
                                             "name": "",
                                             "x": 550,
                                             "y": 3860,
                                             "wires": [
                                                 []
                                             ]
                                         }
                                      ]
                                      

                                      Ein evtl. Update muss wieder selektiv durchgeführt werden, in dem nur der Subflow ersetzt wird. Genau ist es hier beschrieben:
                                      https://forum.iobroker.net/post/856928

                                      1 Reply Last reply Reply Quote 0
                                      • icebear
                                        icebear last edited by

                                        Hallo,

                                        Ich habe mir in Node-Red einen Flow erstellt, der mir die Preise für 'current' , 'today' und 'tomorrow' abholt und in einem Datenpunkt als json ablegt

                                        siehe hier:tib_Price.png

                                        jetzt würde ich gerne aus dieser json für 'today' und 'tomorrow' jeweils den 'niedrigsten' , 'höchsten' und den durchschnittlichen Preis extrahieren und in einen eigenen Datenpunkt schreiben.

                                        Ich hab aber leider keine Ahnung wie ich das anstellen muß, sprich ich weiß wohl das ich das mittels eines function node realisieren kann der die json zerlegt, aber leider gehen mein Kenntnisse nich soweit.

                                        Vielleicht kann ja einer helfen

                                        Gruß
                                        Holger

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

                                          @icebear Du wandelst den JSON String mit einer JSON Node in ein Objekt um. Dann extrahierst Du den Wert, der Dich interessiert in dem Du die payload auf den Pfad zum den entsprechenden Wert setzt. Du gehst also mit der Maus neben den Wert und kopierst den Pfad und setzt die payload auf diesen Pfad:

                                          copy path.gif

                                          Nun hast Du 3 Möglichkeiten:

                                          1. Das Maximum und Minimum kannst Du entweder kodieren und mit einer Function Node in dem entsprechenden Kontext speichern.
                                          2. Du kodierst gar nichts und speicherst das Maximum oder Minimum im Flow Kontext.

                                          In beiden Fällen setzt Du jeden Tag mit einer Inject Node wieder zurück, wenn Du willst.

                                          1. Du installierst Dir die aggregate Node , die Dir Minimum und Maximum pro Zeiteinheit also pro Tag ausgibt.

                                          Falls Du Dich für eine der 3 Möglichkeiten entschieden hast, können wir das konkretisieren.

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

                                            @mickym

                                            Ich hatte die aggregate node schon installiert, hatte ich aber garnich auf dem Schirm.

                                            Ich hab jetzt nochmal einen einfachen flow erstellt, der mir mit einem template node die aktuellen preise von tibber abholt.

                                            siehe hier:tib_array.png

                                            wie krieg ich das jetzt in die aggregate node rein

                                            Gruß
                                            Holger

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            981
                                            Online

                                            31.7k
                                            Users

                                            79.7k
                                            Topics

                                            1.3m
                                            Posts

                                            node-red
                                            13
                                            114
                                            18487
                                            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