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. Modbuswerte aus Schleife in einzelne Objekten schreiben

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Modbuswerte aus Schleife in einzelne Objekten schreiben

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

      Hallo,
      ich bin in NodeRed noch ein Neuling.
      Habe mir ein Flow besorgt, um meine Hoymiles-Wechselrichter auszulesen, die an einer DTU-Pro S hängen, welche ich mit Modbus TCP auslese.
      Bildschirmfoto 2023-06-03 um 17.59.18.png
      Das Flow an sich funktionert und liest jetzt jedes Panel an meinen WR aus und schmeisst ein Objekt raus, zB. :

      {"data_type":12,"serial_number":"138280427999","port_number":2,"pv_voltage":32.4,"pv_current":6.140000000000001,"grid_voltage":236.3,"grid_frequency":49.95,"pv_power":199.4,"today_production":221.9,"total_production":2418.3,"temperature":55.7,"operating_status":3,"alarm_code":0,"alarm_count":0,"link_status":1,"fixed_value":7,"reserved_1":0,"reserved_2":0,"reserved_3":0,"reserved_4":0,"reserved_5":0,"reserved_6":12}
      

      Jetzt habe ich aber 6 Wechselrichter mit je 6 Panels und es wird durch eine Schleife mit Modbus Request ausgelesen:

      let port_count = 36;
      let modbus_requests = []
      
      for(let i=0;i<port_count;i++){
          const newRequest = {
              "payload":{
                  'fc': 3, 
                  'unitid': 101, 
                  'address': 4096+(i*40), 
                  'quantity': 40
              }
          }
          modbus_requests.push(newRequest)
          
      }
      
      return [modbus_requests];
      

      Und dann in einem Buffer-parser aufebereitet, sodass ich oben den gezeigten Code/Objekt rausbekomme.
      Jetzt habe ich aber das Problem, wenn ich am Ende ein "ioBroker out" hänge, schreibt er mir das zwar in einem DP, aber sobald das nächste Panel in der Schleife kommt, wird der DP wieder überschrieben.

      Wie kann ich den ioBroker Out dazu bringen, für alle 36 Objekte, die nacheinander ausgelesen werden, einen anderen DP zu benutzen bzw anzulegen?

      Bildschirmfoto 2023-06-03 um 17.58.38.png

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

        @tugsi du musst halt für jeden Datenpunkt ein eigenes Topic festlegen

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

          @mickym sagte in Modbuswerte aus Schleife in einzelne Objekten schreiben:

          @tugsi du musst halt für jeden Datenpunkt ein eigenes Topic festlegen

          Was meinst Du mit Topic?
          Also für jede Abfrage ein eigenen Flow? Oder kann ich auch wie bei der Abfrage eine Schleife für die Topics machen?
          Topic habe ich auch offen gelassen, weil wenn ich unter zB userdata.0. ein DP angelegt hatte, hat er mir den gar nicht in der Auswahl angeboten...

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

            @tugsi sagte in Modbuswerte aus Schleife in einzelne Objekten schreiben:

            @mickym sagte in Modbuswerte aus Schleife in einzelne Objekten schreiben:

            @tugsi du musst halt für jeden Datenpunkt ein eigenes Topic festlegen

            Was meinst Du mit Topic?
            Also für jede Abfrage ein eigenen Flow? Oder kann ich auch wie bei der Abfrage eine Schleife für die Topics machen?
            Topic habe ich auch offen gelassen, weil wenn ich unter zB userdata.0. ein DP angelegt hatte, hat er mir den gar nicht in der Auswahl angeboten...

            Die Datenpunkte, die Dir angeboten werden, werden Dir nur bei jedem Adapterstart eingelesen. Keine Ahnung, ob Du in der Buffer Node das Topic wieder überschreibst. Wenn nicht kannst Du ggf. das topic bereits in der function node festlegen. Du kannst aber auch aus der payload ein neues Topic generieren. Wenn Deine payload zum Beispiel wie oben ausschaut und Du 3 Objekte rausbekommst, wobei die port_number unterschiedlich ist, dann setzt Du halt via change node, ein msg.topic auf "0_userdata.0.hoymiles.port." & payload.port_number

            Du schreibst ja nicht unter welchen Datenpunkten Du die Objekte schreiben willst - ausserdem musst Du auch eine JSON Node davor hängen, da Du in den iobroker keine komplexe Datentypen schreiben kannst, wie Arrays oder Objekte.

            Also ist die port_number ein Wert, in der sich die Objekte unterscheiden? Und wohin möchtest Du die Datenpunkte schreiben?

            Ich habs jetzt einfach so gemacht - ihr schreibt halt immer nur die Hälfte was ihr wollt. Voraussetzung ist, dass Du in der Adapterkonfig Fremdobjekte erstellen angehakt hast.

            89b22f67-d5c3-4208-ad76-9505db6e63d8-image.png

            08ac6b6f-12c2-4db8-8ee2-68b68b54bc64-image.png
            Hier als Beispiel zum Import.

            [
               {
                   "id": "7fb54e7fa19c612f",
                   "type": "inject",
                   "z": "7e6af0015415146d",
                   "name": "Objekt",
                   "props": [
                       {
                           "p": "payload"
                       }
                   ],
                   "repeat": "",
                   "crontab": "",
                   "once": false,
                   "onceDelay": 0.1,
                   "topic": "",
                   "payload": "{\"data_type\":12,\"serial_number\":\"138280427999\",\"port_number\":2,\"pv_voltage\":32.4,\"pv_current\":6.140000000000001,\"grid_voltage\":236.3,\"grid_frequency\":49.95,\"pv_power\":199.4,\"today_production\":221.9,\"total_production\":2418.3,\"temperature\":55.7,\"operating_status\":3,\"alarm_code\":0,\"alarm_count\":0,\"link_status\":1,\"fixed_value\":7,\"reserved_1\":0,\"reserved_2\":0,\"reserved_3\":0,\"reserved_4\":0,\"reserved_5\":0,\"reserved_6\":12}",
                   "payloadType": "json",
                   "x": 930,
                   "y": 4340,
                   "wires": [
                       [
                           "10a128254922c3cc",
                           "e019c769996d728d"
                       ]
                   ]
               },
               {
                   "id": "10a128254922c3cc",
                   "type": "debug",
                   "z": "7e6af0015415146d",
                   "name": "payload",
                   "active": true,
                   "tosidebar": true,
                   "console": false,
                   "tostatus": false,
                   "complete": "payload",
                   "targetType": "msg",
                   "statusVal": "",
                   "statusType": "auto",
                   "x": 1120,
                   "y": 4300,
                   "wires": []
               },
               {
                   "id": "e019c769996d728d",
                   "type": "change",
                   "z": "7e6af0015415146d",
                   "name": "",
                   "rules": [
                       {
                           "t": "set",
                           "p": "topic",
                           "pt": "msg",
                           "to": "\"0_userdata.0.hoymiles.port.\" & payload.port_number",
                           "tot": "jsonata"
                       }
                   ],
                   "action": "",
                   "property": "",
                   "from": "",
                   "to": "",
                   "reg": false,
                   "x": 1120,
                   "y": 4360,
                   "wires": [
                       [
                           "739f80baf9eda446",
                           "1436b39512bc3855"
                       ]
                   ]
               },
               {
                   "id": "739f80baf9eda446",
                   "type": "debug",
                   "z": "7e6af0015415146d",
                   "name": "Schreibe Objekt unter topic",
                   "active": true,
                   "tosidebar": true,
                   "console": false,
                   "tostatus": false,
                   "complete": "payload",
                   "targetType": "msg",
                   "statusVal": "",
                   "statusType": "auto",
                   "x": 1400,
                   "y": 4420,
                   "wires": []
               },
               {
                   "id": "1436b39512bc3855",
                   "type": "json",
                   "z": "7e6af0015415146d",
                   "name": "",
                   "property": "payload",
                   "action": "",
                   "pretty": false,
                   "x": 1310,
                   "y": 4360,
                   "wires": [
                       [
                           "6fd6583c31698633"
                       ]
                   ]
               },
               {
                   "id": "6fd6583c31698633",
                   "type": "ioBroker out",
                   "z": "7e6af0015415146d",
                   "name": "",
                   "topic": "",
                   "ack": "true",
                   "autoCreate": "true",
                   "stateName": "",
                   "role": "",
                   "payloadType": "",
                   "readonly": "",
                   "stateUnit": "",
                   "stateMin": "",
                   "stateMax": "",
                   "x": 1500,
                   "y": 4360,
                   "wires": []
               }
            ]
            

            Du musst halt die change Node und die Json Node dazwischenklemmen.

            Solche Informationen stehen im Übrigen alle in der Hilfe zu der Node - auch zu iobroker Out Node.

            3422cf34-f179-449b-9d16-7e47c506cc02-image.png

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

              @mickym sagte in Modbuswerte aus Schleife in einzelne Objekten schreiben:

              ihr schreibt halt immer nur die Hälfte was ihr wollt

              Erstmal Danke mickym, ich komme aus dem Programmierbereich, eigentlich mehr SPS in der Industrie, von daher kenne ich das Problem, man bekommt zu wenig Input ... lach
              Bei mir ist halt leider das Problem, dass ich das Konstrukt NodeRed so gar nicht kenn, habe versucht mich etwas einzulesen, aber zu wenig... denn das mit den msg.topic hatte ich so nicht verstanden..

              jetzt ist mir zu spät, werde es morgen mal anschauen und ausprobieren.
              Leider kann ich den Port nicht als alleiniges Merkmal benutzen.
              Der Port hängt mit der Seriennummer zusammen.
              Jeder Wechselrichter hat 6 Ports, 6 Wechselrichter habe ich und somit habe ich auch 6x Port 1, Port2 ...
              Wenn dann müsste es so aufgeteilt werden in :
              "0_userdata.0.hoymiles.serial_number." & payload.serial_number & ".port." & payload.port_number
              Wenn sowas geht, 2 Variablen zu benutzen?
              Dann hätte man eine Struktur: hoymiles - SN (somit den Wechselrichter) - Port 1-6 und darunter die Werte.
              Im Grunde hatte ich vor, alle erzeugten Leistungen pro WR zusammenzuzählen, anzeigen zu lassen und auch ob Alarm ansteht und die prodzuierte Leistung.

              Wie gesagt, werde morgen mir das in Ruhe mal anschauen, was Du mir zum Import gegeben hast und du weißt ja, die Fragen entstehen meist erst, wenn man bastelt..

              Danke schon mal für Deine Mühen!

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

                @tugsi Ich könnte Dir zwar was über JSONATA basteln, weil ich finde, dass es ja Ziel ist bei NodeRed nicht wieder x Code-Zeilen zu schreiben, aber Du kannst ja auch alles in JS programmieren. Wenn Du alles in einzelne Datenpunkte haben willst, dann empfehle ich Dir meinen Subflow. Ich mach Dir das mal aus dem einen Objekt was Du geliefert hast als Beispiel mit meinem Subflow. Beachte bitte die Hinweise bzgl. Fremderstellung von Objekten aus meinem Thread. https://forum.iobroker.net/topic/43856/json-oder-javascript-objekt-in-iobroker-datenpunkte-zerlegen

                Zur Funktionsweise schau Dir die Hilfe zu der Node ggf. noch an. Du musst die Node nicht mehr importieren, wenn Du den Flow in diesem Post importierst, da die Node Bestandteil des Flows ist. Du musst die Buffer Node noch vorne dran hängen, wobei man die Buffernode wahrscheinlich auch anders hätte konfigurieren können. Ich bin generell kein Freund von function Nodes mit dem Du die Requests erstellst, weil man mit codieren (auch wenn es Dir leichter fällt, viel von der visuellen Ablaufsteuerung kaputt macht). Du hast ja nun eine bestimmte Struktur vorgegeben.

                Damit schreibst Du dann den Rest nicht in ein einzelnen JSON String sondern in einzelne Datenpunkte.

                ab36fa0a-6c12-4e2c-aee1-c1d40c5b21f1-image.png

                68811be4-4bc7-4897-89a8-04b8579f6756-image.png

                [
                   {
                       "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": "d5cbbd656a792986",
                       "type": "subflow:6e802f1553b18149",
                       "z": "7e6af0015415146d",
                       "name": "",
                       "x": 790,
                       "y": 4600,
                       "wires": [
                           [
                               "d123fec5b015bd73"
                           ]
                       ]
                   },
                   {
                       "id": "7fb54e7fa19c612f",
                       "type": "inject",
                       "z": "7e6af0015415146d",
                       "name": "Objekt",
                       "props": [
                           {
                               "p": "payload"
                           }
                       ],
                       "repeat": "",
                       "crontab": "",
                       "once": false,
                       "onceDelay": 0.1,
                       "topic": "",
                       "payload": "{\"data_type\":12,\"serial_number\":\"138280427999\",\"port_number\":2,\"pv_voltage\":32.4,\"pv_current\":6.140000000000001,\"grid_voltage\":236.3,\"grid_frequency\":49.95,\"pv_power\":199.4,\"today_production\":221.9,\"total_production\":2418.3,\"temperature\":55.7,\"operating_status\":3,\"alarm_code\":0,\"alarm_count\":0,\"link_status\":1,\"fixed_value\":7,\"reserved_1\":0,\"reserved_2\":0,\"reserved_3\":0,\"reserved_4\":0,\"reserved_5\":0,\"reserved_6\":12}",
                       "payloadType": "json",
                       "x": 170,
                       "y": 4600,
                       "wires": [
                           [
                               "e019c769996d728d"
                           ]
                       ]
                   },
                   {
                       "id": "e019c769996d728d",
                       "type": "change",
                       "z": "7e6af0015415146d",
                       "name": "",
                       "rules": [
                           {
                               "t": "set",
                               "p": "top",
                               "pt": "msg",
                               "to": "\" hoymiles.serial_number.\" & payload.serial_number & \".port.\" & payload.port_number",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 340,
                       "y": 4600,
                       "wires": [
                           [
                               "7dc32966ba8d0d75"
                           ]
                       ]
                   },
                   {
                       "id": "7dc32966ba8d0d75",
                       "type": "change",
                       "z": "7e6af0015415146d",
                       "name": "",
                       "rules": [
                           {
                               "t": "set",
                               "p": "payload",
                               "pt": "msg",
                               "to": "payload ~> | $ | {}, [\"serial_number\",\"port_number\"]|",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 550,
                       "y": 4600,
                       "wires": [
                           [
                               "d5cbbd656a792986"
                           ]
                       ]
                   },
                   {
                       "id": "d123fec5b015bd73",
                       "type": "ioBroker out",
                       "z": "7e6af0015415146d",
                       "name": "",
                       "topic": "",
                       "ack": "true",
                       "autoCreate": "true",
                       "stateName": "",
                       "role": "",
                       "payloadType": "",
                       "readonly": "true",
                       "stateUnit": "",
                       "stateMin": "",
                       "stateMax": "",
                       "x": 1020,
                       "y": 4600,
                       "wires": []
                   }
                ]
                

                tugsi 1 Reply Last reply Reply Quote 1
                • tugsi
                  tugsi @mickym last edited by

                  @mickym Super danke....
                  Jetzt hatte ich die Zeit und die Muse mir das anzuschauen, die Nacht ist man dann doch nicht mehr so aufnahmefähig...
                  Anfänglich habe ich noch Probleme gehabt, da er mir keine Datenpunkte angelegt hatte, hab zum testen den msg.payload zwischengehangen und gesehen, dass im Grunde alles richtig rausgeht.
                  Abwr wie immer, der Fehler sitzt davor, hatte in der NodeRed-Instanz Fremdobjekte anlegen nicht angekreuzt.

                  Jetzt schreibt er schön die Datenpunkte rein, in der Struktur habe ich aber das Verzeichnis serial_number und port rausgenommen, sodass es dann "nur" .hoymiles."seriennummer"."portnummer". steht, das ist übersichtlicher und reicht ja komplett aus.

                  Aber eines habe ich noch nicht ganz verstanden, Du würdest keine function Node nehmen, aber korrigiere mich, die function Node ist doch die Schleife, die die Abfrage durch die Modbusregister macht.
                  Jedes Register ist ja gleich aufgebaut und hat halt die vorgegebene Struktur.
                  Wie hättest Du es denn gelöst?

                  Hier mal mein kompletter Flow als Export:

                  [
                     {
                         "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": "b2a6d980341900ef",
                         "type": "tab",
                         "label": "Flow 3",
                         "disabled": false,
                         "info": "",
                         "env": []
                     },
                     {
                         "id": "d5cbbd656a792986",
                         "type": "subflow:6e802f1553b18149",
                         "z": "b2a6d980341900ef",
                         "name": "",
                         "x": 810,
                         "y": 540,
                         "wires": [
                             [
                                 "d123fec5b015bd73"
                             ]
                         ]
                     },
                     {
                         "id": "e019c769996d728d",
                         "type": "change",
                         "z": "b2a6d980341900ef",
                         "name": "",
                         "rules": [
                             {
                                 "t": "set",
                                 "p": "top",
                                 "pt": "msg",
                                 "to": "\" hoymiles.\" & payload.serial_number & \".\" & payload.port_number",
                                 "tot": "jsonata"
                             }
                         ],
                         "action": "",
                         "property": "",
                         "from": "",
                         "to": "",
                         "reg": false,
                         "x": 360,
                         "y": 540,
                         "wires": [
                             [
                                 "7dc32966ba8d0d75"
                             ]
                         ]
                     },
                     {
                         "id": "7dc32966ba8d0d75",
                         "type": "change",
                         "z": "b2a6d980341900ef",
                         "name": "",
                         "rules": [
                             {
                                 "t": "set",
                                 "p": "payload",
                                 "pt": "msg",
                                 "to": "payload ~> | $ | {}, [\"serial_number\",\"port_number\"]|",
                                 "tot": "jsonata"
                             }
                         ],
                         "action": "",
                         "property": "",
                         "from": "",
                         "to": "",
                         "reg": false,
                         "x": 570,
                         "y": 540,
                         "wires": [
                             [
                                 "d5cbbd656a792986"
                             ]
                         ]
                     },
                     {
                         "id": "d123fec5b015bd73",
                         "type": "ioBroker out",
                         "z": "b2a6d980341900ef",
                         "name": "",
                         "topic": "",
                         "ack": "true",
                         "autoCreate": "true",
                         "stateName": "",
                         "role": "",
                         "payloadType": "",
                         "readonly": "true",
                         "stateUnit": "",
                         "stateMin": "",
                         "stateMax": "",
                         "x": 1040,
                         "y": 540,
                         "wires": []
                     },
                     {
                         "id": "768bd3e149c2d04e",
                         "type": "inject",
                         "z": "b2a6d980341900ef",
                         "name": "read data",
                         "props": [
                             {
                                 "p": "payload"
                             },
                             {
                                 "p": "topic",
                                 "vt": "str"
                             }
                         ],
                         "repeat": "",
                         "crontab": "",
                         "once": false,
                         "onceDelay": 0.1,
                         "topic": "",
                         "payload": "",
                         "payloadType": "date",
                         "x": 160,
                         "y": 380,
                         "wires": [
                             [
                                 "52c5ac7785f8c2f1"
                             ]
                         ]
                     },
                     {
                         "id": "52c5ac7785f8c2f1",
                         "type": "function",
                         "z": "b2a6d980341900ef",
                         "name": "Create Modbus requests",
                         "func": "// Single HMS-1000-T \n// Two ports / inverter\nlet port_count = 36;\nlet modbus_requests = []\n\nfor(let i=0;i<port_count;i++){\n    const newRequest = {\n        \"payload\":{\n            'fc': 3, \n            'unitid': 101, \n            'address': 4096+(i*40), \n            'quantity': 40\n        }\n    }\n    modbus_requests.push(newRequest)\n    \n}\n\nreturn [modbus_requests];",
                         "outputs": 1,
                         "noerr": 0,
                         "initialize": "",
                         "finalize": "",
                         "libs": [],
                         "x": 370,
                         "y": 380,
                         "wires": [
                             [
                                 "0161a3fd6a26f5b2"
                             ]
                         ]
                     },
                     {
                         "id": "0161a3fd6a26f5b2",
                         "type": "modbus-flex-getter",
                         "z": "b2a6d980341900ef",
                         "name": "",
                         "showStatusActivities": true,
                         "showErrors": false,
                         "showWarnings": true,
                         "logIOActivities": false,
                         "server": "f2783f1226f5760b",
                         "useIOFile": false,
                         "ioFile": "",
                         "useIOForPayload": false,
                         "emptyMsgOnFail": false,
                         "keepMsgProperties": true,
                         "delayOnStart": false,
                         "startDelayTime": "",
                         "x": 630,
                         "y": 380,
                         "wires": [
                             [
                                 "f4234115aef0b5e2"
                             ],
                             []
                         ]
                     },
                     {
                         "id": "f4234115aef0b5e2",
                         "type": "buffer-parser",
                         "z": "b2a6d980341900ef",
                         "name": "Decode Hoymiles microinverter data packet",
                         "data": "payload",
                         "dataType": "msg",
                         "specification": "spec",
                         "specificationType": "ui",
                         "items": [
                             {
                                 "type": "uint8",
                                 "name": "data_type",
                                 "offset": 0,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "hex",
                                 "name": "serial_number",
                                 "offset": 1,
                                 "length": 6,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "port_number",
                                 "offset": 7,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "pv_voltage",
                                 "offset": 8,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "pv_current",
                                 "offset": 10,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.01",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "grid_voltage",
                                 "offset": 12,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "grid_frequency",
                                 "offset": 14,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.01",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "pv_power",
                                 "offset": 16,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "today_production",
                                 "offset": 18,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint32be",
                                 "name": "total_production",
                                 "offset": 20,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.1",
                                 "mask": ""
                             },
                             {
                                 "type": "int16be",
                                 "name": "temperature",
                                 "offset": 24,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "0.1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "operating_status",
                                 "offset": 26,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "alarm_code",
                                 "offset": 28,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint16be",
                                 "name": "alarm_count",
                                 "offset": 30,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "link_status",
                                 "offset": 32,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "fixed_value",
                                 "offset": 33,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "reserved_1",
                                 "offset": 34,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "reserved_2",
                                 "offset": 35,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "reserved_3",
                                 "offset": 36,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "reserved_4",
                                 "offset": 37,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "reserved_5",
                                 "offset": 38,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             },
                             {
                                 "type": "uint8",
                                 "name": "reserved_6",
                                 "offset": 40,
                                 "length": 1,
                                 "offsetbit": 0,
                                 "scale": "1",
                                 "mask": ""
                             }
                         ],
                         "swap1": "",
                         "swap2": "",
                         "swap3": "",
                         "swap1Type": "swap",
                         "swap2Type": "swap",
                         "swap3Type": "swap",
                         "msgProperty": "payload",
                         "msgPropertyType": "str",
                         "resultType": "keyvalue",
                         "resultTypeType": "return",
                         "multipleResult": false,
                         "fanOutMultipleResult": false,
                         "setTopic": true,
                         "outputs": 1,
                         "x": 270,
                         "y": 460,
                         "wires": [
                             [
                                 "e019c769996d728d"
                             ]
                         ]
                     },
                     {
                         "id": "f2783f1226f5760b",
                         "type": "modbus-client",
                         "name": "Hoymiles_modbus",
                         "clienttype": "tcp",
                         "bufferCommands": true,
                         "stateLogEnabled": true,
                         "queueLogEnabled": false,
                         "failureLogEnabled": true,
                         "tcpHost": "192.168.33.140",
                         "tcpPort": "502",
                         "tcpType": "DEFAULT",
                         "serialPort": "/dev/ttyUSB0",
                         "serialType": "RTU-BUFFERD",
                         "serialBaudrate": "9600",
                         "serialDatabits": "8",
                         "serialStopbits": "1",
                         "serialParity": "none",
                         "serialConnectionDelay": "100",
                         "serialAsciiResponseStartDelimiter": "",
                         "unit_id": "101",
                         "commandDelay": "1000",
                         "clientTimeout": "1000",
                         "reconnectOnTimeout": true,
                         "reconnectTimeout": "2000",
                         "parallelUnitIdsAllowed": true
                     }
                  ]
                  

                  Danke für den Support!

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

                    @tugsi sagte in Modbuswerte aus Schleife in einzelne Objekten schreiben:

                    Aber eines habe ich noch nicht ganz verstanden, Du würdest keine function Node nehmen, aber korrigiere mich, die function Node ist doch die Schleife, die die Abfrage durch die Modbusregister macht.
                    Jedes Register ist ja gleich aufgebaut und hat halt die vorgegebene Struktur.
                    Wie hättest Du es denn gelöst?

                    Kann man schon machen. In diesem Fall ist die function Node auch einigermaßen OK. Wenn man es ohne function Node macht, dann erstellt man das Array und erzeugt daraus die Nachrichten.

                    07ea13aa-09bf-4792-a52d-d9ea2c04f02e-image.png

                    Oben Deine Lösung - unten ohne function Node mit identischem Ergebnis:

                    JSONATA ist etwas schwierig - aber wenn man da eintaucht, wahnsinnig elegant und spart Code.

                    Deine ganze Schleife reduziert sich in JSONATA auf:

                    [0..35].{
                                'fc': 3, 
                                'unitid': 101, 
                                'address': 4096+($*40), 
                                'quantity': 40
                            }
                    

                    Das Array wird dann über eine split Node in einzelne Nachrichten aufgeteilt.

                    [
                       {
                           "id": "768bd3e149c2d04e",
                           "type": "inject",
                           "z": "b2a6d980341900ef",
                           "name": "read data",
                           "props": [
                               {
                                   "p": "payload"
                               },
                               {
                                   "p": "topic",
                                   "vt": "str"
                               }
                           ],
                           "repeat": "",
                           "crontab": "",
                           "once": false,
                           "onceDelay": 0.1,
                           "topic": "",
                           "payload": "",
                           "payloadType": "date",
                           "x": 300,
                           "y": 280,
                           "wires": [
                               [
                                   "52c5ac7785f8c2f1"
                               ]
                           ]
                       },
                       {
                           "id": "52c5ac7785f8c2f1",
                           "type": "function",
                           "z": "b2a6d980341900ef",
                           "name": "Create Modbus requests",
                           "func": "// Single HMS-1000-T \n// Two ports / inverter\nlet port_count = 36;\nlet modbus_requests = []\n\nfor(let i=0;i<port_count;i++){\n    const newRequest = {\n        \"payload\":{\n            'fc': 3, \n            'unitid': 101, \n            'address': 4096+(i*40), \n            'quantity': 40\n        }\n    }\n    modbus_requests.push(newRequest)\n    \n}\n\nreturn [modbus_requests];",
                           "outputs": 1,
                           "noerr": 0,
                           "initialize": "",
                           "finalize": "",
                           "libs": [],
                           "x": 510,
                           "y": 280,
                           "wires": [
                               [
                                   "ddc89c423c473244"
                               ]
                           ]
                       },
                       {
                           "id": "bfb98a1bcd67088a",
                           "type": "change",
                           "z": "b2a6d980341900ef",
                           "name": "Create Array with Modbus requests",
                           "rules": [
                               {
                                   "t": "set",
                                   "p": "payload",
                                   "pt": "msg",
                                   "to": "[0..35].{\t            'fc': 3, \t            'unitid': 101, \t            'address': 4096+($*40), \t            'quantity': 40\t        }",
                                   "tot": "jsonata"
                               }
                           ],
                           "action": "",
                           "property": "",
                           "from": "",
                           "to": "",
                           "reg": false,
                           "x": 420,
                           "y": 360,
                           "wires": [
                               [
                                   "b78fe66f2081a4ca"
                               ]
                           ]
                       },
                       {
                           "id": "d3cbeba209165e61",
                           "type": "inject",
                           "z": "b2a6d980341900ef",
                           "name": "read data",
                           "props": [
                               {
                                   "p": "payload"
                               },
                               {
                                   "p": "topic",
                                   "vt": "str"
                               }
                           ],
                           "repeat": "",
                           "crontab": "",
                           "once": false,
                           "onceDelay": 0.1,
                           "topic": "",
                           "payload": "",
                           "payloadType": "date",
                           "x": 180,
                           "y": 360,
                           "wires": [
                               [
                                   "bfb98a1bcd67088a"
                               ]
                           ]
                       },
                       {
                           "id": "ddc89c423c473244",
                           "type": "debug",
                           "z": "b2a6d980341900ef",
                           "name": "Requests",
                           "active": true,
                           "tosidebar": true,
                           "console": false,
                           "tostatus": false,
                           "complete": "payload",
                           "targetType": "msg",
                           "statusVal": "",
                           "statusType": "auto",
                           "x": 820,
                           "y": 360,
                           "wires": []
                       },
                       {
                           "id": "b78fe66f2081a4ca",
                           "type": "split",
                           "z": "b2a6d980341900ef",
                           "name": "",
                           "splt": "\\n",
                           "spltType": "str",
                           "arraySplt": 1,
                           "arraySpltType": "len",
                           "stream": false,
                           "addname": "",
                           "x": 650,
                           "y": 360,
                           "wires": [
                               [
                                   "ddc89c423c473244"
                               ]
                           ]
                       }
                    ]
                    

                    Wie gesagt in Deinem Fall ist die function node auch OK - aber viele verwenden function Nodes und programmieren im Prinzip den ganzen Flow da rein. Du könntest auch noch die Buffer-Node und alle folgenden Nodes in die function Node unterbringen.

                    Wie gesagt in Deinem Fall kann man das schon so lassen, aber ich bin ein Freund davon, es erst ohne function Node zu probieren und nur wenn ich nicht mehr weiterkomme, greife ich darauf zurück.

                    Grundsätzlich sind Schleifen auch nichts anderes als eine Abfolge von Nachrichten, die Du durch die Nodes schickst. 😉 😁

                    Und eine Split Node teilt Dir ein Array oder ein Objekt auf wie ein array.forEach usw.

                    Übrigens JSONATA kannst Du auch in Blockly und in JS nutzen, da ich denke dass Du generell ja eher der Puzzlefraktion angehörst. 😉

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

                      @tugsi Auch mit der Buffer Node - in dem Fall konntest Du meinen Subflow nutzen. Du hättest aber auch darauf verzichten können.

                      Wenn Du das Ganze aus der Buffer-Node Dir nicht als ein Objekt hättest ausgeben lassen:

                      f43b79a9-cb53-49c1-a5f0-27a9480c8797-image.png

                      sondern mit multiple results hättest Du einzelne Nachrichten gehabt und hättest dann mit einer Change Node nur noch das topic modifizieren müssen. Allerdings ist es so mit Seriennummer und Portnummer eleganter.

                      Ich will Dir nur ein paar Ansätze zeigen, wo man mit spielen kann.

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

                        Eine andere Mögllichkeit wäre vielleicht - statt 36 Einzelrequests an verschiedenen Adressen - einen Riesenblock als Buffer einzulesen und dann aufzuteilen. Keine Ahnung ob das geht. Habe kein Modbus. 😉

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

                          @mickym sagte in Modbuswerte aus Schleife in einzelne Objekten schreiben:

                          da ich denke dass Du generell ja eher der Puzzlefraktion angehörst

                          Nicht ganz, ich bin schon etwas älter, komme noch aus der BASIC-Zeit, wo man damals ellenlange Listings aus zB der alten C64-Zeitschrift abgetippt hatte *lach
                          In meinem Job programmiere ich SPSen von Siemens, dort gibt den sogenannten FUP (Funktionsplan), da ist es mit "Kästchen", ich programmiere aber einiges noch sehr gerne in AWL (Anweisungliste), das kommt dem klassischen Programmieren sher nahe.
                          Das größte Problem was ich immer habe, ist der unterschiedliche Syntax, AWL wird so, PHP dann wieder so, JS möchte gerne dies.. Hochkammata, Anführungszeiten...
                          Deswegen bin ich in vielen Fällen froh, wenn man etwas "Fertiges" hat, welches man dann durch ein wenig Try&Error dann näher kennenlernt 😉

                          Eine andere Mögllichkeit wäre vielleicht - statt 36 Einzelrequests an verschiedenen Adressen - einen Riesenblock als Buffer einzulesen und dann aufzuteilen. Keine Ahnung ob das geht. Habe kein Modbus.

                          Theoretisch sollte das klappen, hatte aber dieses Script im Netz gefunden, denn mit dem Modbus-Adapter vom ioBroker habe ich gar keine brauchbaren Daten bekommen, da war ich von NodeRed positiv überrascht...
                          Zusätzlich habe ich noch ein EM24-Zähler mit Modbus-RTU, dazwischen ein RTU-TCP-Wandler, da habe ich das Problem, dass ich nur 10Bytes auslesen kann, möchte ich mehr, habe ich Connection-Error.
                          Aber da brauche ich nur zwei Werte, momentane W und Gesamt kWh, die hole ich mir einzeln raus mit NodeRed.

                          Aber Dank für Deine Mühen und die Muse mir etwas zu zeigen, ich bin da ein Freund von, dass man auch unterschiedliche Wege gehen kann.
                          Und im Bereich der Programmierung hat jeder seine eigenen Werte und bekanntlich führen viele Wege nach Rom 😉
                          Ich werde mir auf jeden Fall Deine Anregungen in Ruhe mal anschauen und testen, wichtig ist jetzt erstmal dass ich die Daten habe und grob sehe wie es funktionert.

                          👍

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

                          Support us

                          ioBroker
                          Community Adapters
                          Donate

                          554
                          Online

                          31.7k
                          Users

                          79.7k
                          Topics

                          1.3m
                          Posts

                          communication
                          2
                          11
                          486
                          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