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 Kannst Du mal den JSON des kompletten Datenpunktes posten und hier in CodeTags einbetten?

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

        @mickym
        sorry lag an mir hatte das ganze Topic drin wenn ich nur den /Info nehme klappte es bei den anderen ist es ja auch kein JSON 🤦‍♂️ 🤦‍♂️

        Trotzdem danke 👍

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

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

          @mickym
          sorry lag an mir hatte das ganze Topic drin wenn ich nur den /Info nehme klappte es bei den anderen ist es ja auch kein JSON 🤦‍♂️ 🤦‍♂️

          Trotzdem danke 👍

          Hmm aber eigentlich darf es gar keine topics geben, die mit . enden. Was meinst Du mit ganzem topic?

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

            @mickym
            Ich hatte in er node shellies/3EM/# eingetragen teilweise legt der mqtt Adapter die aber selbst schon als datenpunkt an, dacht es läge daran.
            so siehts im MQTT aus
            mqtt 3em.PNG

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

              @frank579 Ich hab den Fehler schon gefunden - ich werkle gerade an einer neuen Version. 😉

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

                So einen neue Version des Subflows - hat sich sogar vereinfacht.

                Einfach mal testen:

                [
                   {
                       "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": "158930afddd0780b",
                       "type": "json",
                       "z": "6e802f1553b18149",
                       "name": "",
                       "property": "payload",
                       "action": "obj",
                       "pretty": false,
                       "x": 550,
                       "y": 160,
                       "wires": [
                           [
                               "3649300b4c233b10"
                           ]
                       ]
                   },
                   {
                       "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": [
                           [
                               "158930afddd0780b"
                           ]
                       ]
                   },
                   {
                       "id": "3649300b4c233b10",
                       "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": 720,
                       "y": 160,
                       "wires": [
                           [
                               "bfce19b206660fbe"
                           ],
                           [
                               "3e11e8338f694832"
                           ],
                           [
                               "a096a93bb82b7a93"
                           ]
                       ]
                   },
                   {
                       "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": [
                           [
                               "158930afddd0780b"
                           ]
                       ]
                   },
                   {
                       "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": "a096a93bb82b7a93",
                       "type": "junction",
                       "z": "6e802f1553b18149",
                       "x": 1380,
                       "y": 280,
                       "wires": [
                           [
                               "1a8c03d866b85b12"
                           ]
                       ]
                   },
                   {
                       "id": "436b84bced4aeddd",
                       "type": "subflow:6e802f1553b18149",
                       "z": "393214410c8f2f15",
                       "name": "",
                       "x": 590,
                       "y": 840,
                       "wires": [
                           []
                       ]
                   }
                ]
                

                Dann wie unten vorgehen: https://forum.iobroker.net/post/856928

                Dort ist ja auch noch die bisherige Version vorhanden.

                EDIT: Sorry waren die Debug Nodes noch drin.

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

                  @mickym
                  Habe es mal schnell getestet irgend was passt jetzt nicht mehr, kann natürlich auch bei mir sein die Werte der Tasmota Steckdose werden nicht mehr aktualisiert...
                  aus der debug Node kommt

                  0_userdata.0.objRoot.ENERGY.Total : msg.payload : number
                  2.689
                  

                  ist das objRoot richtig da stand vorher der Name vom gerät ...

                  mickym 1 Reply Last reply Reply Quote 0
                  • 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
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            1.1k
                                            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