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. Function node erstellen

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Function node erstellen

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

      Ich hätte da mal ein Anliegen:
      da ich mich mit Java-Befehlen nicht so auskenne bzw. gar nicht, würde ich gerne ein payload aus dreien erstellen. Wert aus den drei Iobroker-Werten soll am ende dieses Format habe:

      {
      "payload":{
      "hsv": {
      "hue": 358,
      "staturation": 96,
      "brightness": 100
      }
      }
      }
      

      kann mir jemand dazu die drei function-nodes erstellen?

      Asgothian mickym 2 Replies Last reply Reply Quote 0
      • Asgothian
        Asgothian Developer @Matthias1234 last edited by

        @matthias1234

        Ich fürchte ich verstehe Deine Frage nicht.

        • Java nutzt der ioBroker nativ nicht
        • Welche 3 ioBroker Werte sollen denn zu diesem JSON zusammen gebaut werden ?
        • in welchem Zusammenhang soll das passieren ?

        A.

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

          @matthias1234

          Du musst halt anstelle der Inject-Nodes die entsprechenden iobroker in Nodes verkabeln. Ich habe es jetzt mit einer flow Variablen, anstelle einer function Node gemacht - da das dann ohne Programmcode geht. Diese Lösung hat dann den Vorteil, dass sich wenn alle Parameter voll sind - sich nur noch 1 Parameter ändern braucht und Du bekommst dann jeweils das ganze Objekt geliefert.

          c4d0fdb9-c4d5-490e-8d92-524ce6440401-image.png

          hier zum Importieren:

          [
             {
                 "id": "9b64da83.381b98",
                 "type": "inject",
                 "z": "6e170384.60c96c",
                 "name": "hue",
                 "props": [
                     {
                         "p": "payload"
                     }
                 ],
                 "repeat": "",
                 "crontab": "",
                 "once": false,
                 "onceDelay": 0.1,
                 "topic": "",
                 "payload": "358",
                 "payloadType": "num",
                 "x": 1910,
                 "y": 3300,
                 "wires": [
                     [
                         "44952956.f71358"
                     ]
                 ]
             },
             {
                 "id": "ed8d575f.f2a648",
                 "type": "inject",
                 "z": "6e170384.60c96c",
                 "name": "staturation",
                 "props": [
                     {
                         "p": "payload"
                     }
                 ],
                 "repeat": "",
                 "crontab": "",
                 "once": false,
                 "onceDelay": 0.1,
                 "topic": "",
                 "payload": "358",
                 "payloadType": "num",
                 "x": 1900,
                 "y": 3340,
                 "wires": [
                     [
                         "5b4fc7bb.4f2408"
                     ]
                 ]
             },
             {
                 "id": "5534abf1.d25fb4",
                 "type": "inject",
                 "z": "6e170384.60c96c",
                 "name": "brightness",
                 "props": [
                     {
                         "p": "payload"
                     }
                 ],
                 "repeat": "",
                 "crontab": "",
                 "once": false,
                 "onceDelay": 0.1,
                 "topic": "",
                 "payload": "100",
                 "payloadType": "num",
                 "x": 1900,
                 "y": 3380,
                 "wires": [
                     [
                         "39a42fef.233e1"
                     ]
                 ]
             },
             {
                 "id": "44952956.f71358",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "set",
                         "p": "hsv.hue",
                         "pt": "flow",
                         "to": "payload",
                         "tot": "msg"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2090,
                 "y": 3300,
                 "wires": [
                     [
                         "f0b73ac7.8b2ff8"
                     ]
                 ]
             },
             {
                 "id": "5b4fc7bb.4f2408",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "set",
                         "p": "hsv.saturation",
                         "pt": "flow",
                         "to": "payload",
                         "tot": "msg"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2110,
                 "y": 3340,
                 "wires": [
                     [
                         "f0b73ac7.8b2ff8"
                     ]
                 ]
             },
             {
                 "id": "39a42fef.233e1",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "set",
                         "p": "hsv.brightness",
                         "pt": "flow",
                         "to": "payload",
                         "tot": "msg"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2110,
                 "y": 3380,
                 "wires": [
                     [
                         "f0b73ac7.8b2ff8"
                     ]
                 ]
             },
             {
                 "id": "f0b73ac7.8b2ff8",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "set",
                         "p": "payload",
                         "pt": "msg",
                         "to": "{}",
                         "tot": "json"
                     },
                     {
                         "t": "set",
                         "p": "payload.hsv",
                         "pt": "msg",
                         "to": "hsv",
                         "tot": "flow"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2390,
                 "y": 3340,
                 "wires": [
                     [
                         "a370119d.88939",
                         "696bb18f.c3732"
                     ]
                 ]
             },
             {
                 "id": "a370119d.88939",
                 "type": "debug",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "active": true,
                 "tosidebar": true,
                 "console": false,
                 "tostatus": false,
                 "complete": "true",
                 "targetType": "full",
                 "statusVal": "",
                 "statusType": "auto",
                 "x": 2570,
                 "y": 3300,
                 "wires": []
             },
             {
                 "id": "696bb18f.c3732",
                 "type": "json",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "property": "payload",
                 "action": "",
                 "pretty": false,
                 "x": 2570,
                 "y": 3340,
                 "wires": [
                     [
                         "737c2aed.c930a4"
                     ]
                 ]
             },
             {
                 "id": "737c2aed.c930a4",
                 "type": "debug",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "active": true,
                 "tosidebar": true,
                 "console": false,
                 "tostatus": false,
                 "complete": "true",
                 "targetType": "full",
                 "statusVal": "",
                 "statusType": "auto",
                 "x": 2710,
                 "y": 3340,
                 "wires": []
             }
          ]
          

          Wenn Dein Node Red Adapter nur Strings liefert, dann musst halt vorher noch in Zahlenwerte konvertieren. Ich empfehle das eh umzustellen - aber das bedeutet je nachdem was Du schon implementiert hast gehörigen Umstellungsaufwand.

          Hier noch eine elegantere Möglichkeit - ohne Flow Variable - dafür bekommst Du nur vollständige Objekte zurück - erst wenn alle 3 Nodes Werte geliefert haben:

          2a618835-eaee-43ba-a899-2860f98a0bca-image.png

          [
             {
                 "id": "4cf4c2be.b6899c",
                 "type": "inject",
                 "z": "6e170384.60c96c",
                 "name": "hue",
                 "props": [
                     {
                         "p": "payload"
                     }
                 ],
                 "repeat": "",
                 "crontab": "",
                 "once": false,
                 "onceDelay": 0.1,
                 "topic": "",
                 "payload": "358",
                 "payloadType": "num",
                 "x": 1890,
                 "y": 3460,
                 "wires": [
                     [
                         "6db9d1aa.c3c81"
                     ]
                 ]
             },
             {
                 "id": "2217fcc6.5dd9b4",
                 "type": "inject",
                 "z": "6e170384.60c96c",
                 "name": "staturation",
                 "props": [
                     {
                         "p": "payload"
                     }
                 ],
                 "repeat": "",
                 "crontab": "",
                 "once": false,
                 "onceDelay": 0.1,
                 "topic": "",
                 "payload": "358",
                 "payloadType": "num",
                 "x": 1880,
                 "y": 3500,
                 "wires": [
                     [
                         "a2b9e60e.263838"
                     ]
                 ]
             },
             {
                 "id": "9ab6b1e9.10bb2",
                 "type": "inject",
                 "z": "6e170384.60c96c",
                 "name": "brightness",
                 "props": [
                     {
                         "p": "payload"
                     }
                 ],
                 "repeat": "",
                 "crontab": "",
                 "once": false,
                 "onceDelay": 0.1,
                 "topic": "",
                 "payload": "100",
                 "payloadType": "num",
                 "x": 1880,
                 "y": 3540,
                 "wires": [
                     [
                         "48711847.1c5d48"
                     ]
                 ]
             },
             {
                 "id": "6db9d1aa.c3c81",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "set",
                         "p": "topic",
                         "pt": "msg",
                         "to": "hue",
                         "tot": "str"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2060,
                 "y": 3460,
                 "wires": [
                     [
                         "72cce25d.16a08c"
                     ]
                 ]
             },
             {
                 "id": "a2b9e60e.263838",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "set",
                         "p": "topic",
                         "pt": "msg",
                         "to": "saturation",
                         "tot": "str"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2060,
                 "y": 3500,
                 "wires": [
                     [
                         "72cce25d.16a08c"
                     ]
                 ]
             },
             {
                 "id": "48711847.1c5d48",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "set",
                         "p": "topic",
                         "pt": "msg",
                         "to": "brightness",
                         "tot": "str"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2060,
                 "y": 3540,
                 "wires": [
                     [
                         "72cce25d.16a08c"
                     ]
                 ]
             },
             {
                 "id": "72cce25d.16a08c",
                 "type": "join",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "mode": "custom",
                 "build": "object",
                 "property": "payload",
                 "propertyType": "msg",
                 "key": "topic",
                 "joiner": "\\n",
                 "joinerType": "str",
                 "accumulate": true,
                 "timeout": "",
                 "count": "3",
                 "reduceRight": false,
                 "reduceExp": "",
                 "reduceInit": "",
                 "reduceInitType": "",
                 "reduceFixup": "",
                 "x": 2260,
                 "y": 3500,
                 "wires": [
                     [
                         "5a9662a.438b29c"
                     ]
                 ]
             },
             {
                 "id": "d17d0760.b685c8",
                 "type": "debug",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "active": true,
                 "tosidebar": true,
                 "console": false,
                 "tostatus": false,
                 "complete": "true",
                 "targetType": "full",
                 "statusVal": "",
                 "statusType": "auto",
                 "x": 2750,
                 "y": 3500,
                 "wires": []
             },
             {
                 "id": "5a9662a.438b29c",
                 "type": "change",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "rules": [
                     {
                         "t": "move",
                         "p": "payload",
                         "pt": "msg",
                         "to": "hsv",
                         "tot": "msg"
                     },
                     {
                         "t": "move",
                         "p": "hsv",
                         "pt": "msg",
                         "to": "payload.hsv",
                         "tot": "msg"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 2420,
                 "y": 3500,
                 "wires": [
                     [
                         "4624a586.319bac"
                     ]
                 ]
             },
             {
                 "id": "4624a586.319bac",
                 "type": "json",
                 "z": "6e170384.60c96c",
                 "name": "",
                 "property": "payload",
                 "action": "",
                 "pretty": false,
                 "x": 2610,
                 "y": 3500,
                 "wires": [
                     [
                         "d17d0760.b685c8"
                     ]
                 ]
             }
          ]
          

          Im topic steht dann der letzte Wert, der geliefert hat. Falls Du das nicht willst - kannst natürlich in der letzten Change Node auch noch die msg.topic löschen.

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

            @mickym

            also das Ergebnis war das richtige hat aber leider nicht funktioniert.

            {"hue":230,"saturation":190,"brightness":70}
            

            den wert bekomme ich aus einem Alexa-flow und gebe ihn weiter an den Color-converter HSV->CSS das funktioniert super. Die Lampe spuckt aber über den iobroker die werte getrennt aus und deswegen möchte ich sie zusammenführen.

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

              @matthias1234 Na dann musst Du sagen warum? Vielleicht brauchst ein anderes Format? Hast Du ggf. in Zahlen konvertiert - kommt bei Dir auch das gleiche raus, wie in meinem Screenshot oder sind Deine Zahlen in Anführungszeichen? Beschreib doch mal die Quelle in der steht, was als Input erwartet wird ... usw.

              Sonst kann man Dir kaum helfen, wenn das Ergebnis das ist, was Du wolltest, aber das was Du wolltest nicht funktioniert. 😉 😉

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

                @mickym und ja meine zahlen stehen in Anführungszeichen.

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

                  @matthias1234 Das ist wenn man diese unselige Option in dem Node Red Adapter angehakt hat - dann bekommst Du alles als Strings raus. Wie gesagt, wenn DU den Haken rausnimmst hast Du ggf. einen ziemlichen Umstellungsaufwand in Deinen Flows.

                  Also einfach die Werte in Zahlen wandeln. Ich verstehe das aber schon richtig - dass Du die Werte aus den iobroker Datenpunkten wieder zusammenführen willst. Deine Alexa spukt ja ansonsten den JSON schon aus.

                  Um den Input aus den iobroker in Nodes in Zahlen zu konvertieren hängst Du noch folgende Change Node dazwischen:

                  f524eeca-8a31-4a4c-b6c3-57c61649b064-image.png

                  cc71eab3-71a8-40b8-a5ad-4671f19a91fc-image.png

                  Ausserdem wolltest Du ja die Werte als Eigenschaft des Objektes hsv. Vielleicht brauchst Du das ja nicht. Aus der Alexa-Node kommt kein Objekt hsv raus - sondern scheint einfacher JSON String zu sein (als payload). In dem Fall halt einfach in den letzten Change Nodes die Zuordnung zum hsv Objekt rausbehmen.

                  Ausserdem, wenn das so aus einer Alexa Node rauskommt und Du es konvertierst - warum speicherst Du das Orginal aus der Alexa Nodes nicht einfach in einer Variablen und verwendest es erst später wieder.
                  Oft bekommt man halt die Informationen immer noch bruchstückhaft.

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

                    @mickym hab es heute morgen versucht und klappt jetzt genau richtig. Danke!!!

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

                    Support us

                    ioBroker
                    Community Adapters
                    Donate

                    948
                    Online

                    31.6k
                    Users

                    79.6k
                    Topics

                    1.3m
                    Posts

                    node-red
                    3
                    8
                    747
                    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