Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Node-Red
    5. [gelöst] String in Objekt umwandeln

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    [gelöst] String in Objekt umwandeln

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

      @mickym noch etwas einfacher - aber in meinen Augen noch nicht optimal. 😉

      Helfen kann hier auch der JSONATA

      39adc4c6-f7bf-4839-b9bd-3e25ab4a24d5-image.png

      572704c7-ab56-42a8-8afc-83061e856920-image.png

      [
         {
             "id": "8d316bcb.d5a0a8",
             "type": "change",
             "z": "54b226bc.0793e8",
             "name": "",
             "rules": [
                 {
                     "t": "set",
                     "p": "payload",
                     "pt": "msg",
                     "to": "{\t    \"hue\":$match(payload,/\\d+/)[0].match,\t    \"saturation\":$match(payload,/\\d+/)[1].match,\t    \"brightness\":$match(payload,/\\d+/)[2].match\t}\t",
                     "tot": "jsonata"
                 }
             ],
             "action": "",
             "property": "",
             "from": "",
             "to": "",
             "reg": false,
             "x": 780,
             "y": 2160,
             "wires": [
                 [
                     "93d9d8b5.26ff98"
                 ]
             ]
         },
         {
             "id": "93d9d8b5.26ff98",
             "type": "debug",
             "z": "54b226bc.0793e8",
             "name": "",
             "active": true,
             "tosidebar": true,
             "console": false,
             "tostatus": false,
             "complete": "false",
             "statusVal": "",
             "statusType": "auto",
             "x": 970,
             "y": 2160,
             "wires": []
         },
         {
             "id": "56febbc6.3c4944",
             "type": "inject",
             "z": "54b226bc.0793e8",
             "name": "",
             "props": [
                 {
                     "p": "payload"
                 }
             ],
             "repeat": "",
             "crontab": "",
             "once": false,
             "onceDelay": 0.1,
             "topic": "",
             "payload": "hsv(237,100,60)",
             "payloadType": "str",
             "x": 560,
             "y": 2160,
             "wires": [
                 [
                     "8d316bcb.d5a0a8"
                 ]
             ]
         }
      ]
      


      63a72bae-189b-444f-ab20-3a3ca7c17a3e-image.png 3c7b3122-61e5-4304-88f0-a3ee0b3d1b3c-image.png

      Das geht aber noch eleganter. 😉 ... probiere noch aus. 😉

      mit diesem JSONATA Ausdruck

      $match(payload,/\d+/)[*].$number(match)
      

      kann jedenfalls numerische Ganzzahlen aus einem String so einer Parameterliste rausholen und in ein Array verwandeln und dann wie herkömmlich vorgehen

      175e5e66-25b4-497c-befb-d314d147e126-image.png

      [
         {
             "id": "114d95e.3ff196a",
             "type": "change",
             "z": "54b226bc.0793e8",
             "name": "",
             "rules": [
                 {
                     "t": "set",
                     "p": "payload",
                     "pt": "msg",
                     "to": "$match(payload,/\\d+/)[*].$number(match)",
                     "tot": "jsonata"
                 }
             ],
             "action": "",
             "property": "",
             "from": "",
             "to": "",
             "reg": false,
             "x": 790,
             "y": 2380,
             "wires": [
                 [
                     "204302c4.255aee",
                     "1d234b38.633fb5"
                 ]
             ]
         },
         {
             "id": "e72c3eb5.d2b11",
             "type": "inject",
             "z": "54b226bc.0793e8",
             "name": "",
             "props": [
                 {
                     "p": "payload"
                 }
             ],
             "repeat": "",
             "crontab": "",
             "once": false,
             "onceDelay": 0.1,
             "topic": "",
             "payload": "temp(47,4464)",
             "payloadType": "str",
             "x": 560,
             "y": 2360,
             "wires": [
                 [
                     "114d95e.3ff196a"
                 ]
             ]
         },
         {
             "id": "43843b4c.3323c4",
             "type": "inject",
             "z": "54b226bc.0793e8",
             "name": "",
             "props": [
                 {
                     "p": "payload"
                 }
             ],
             "repeat": "",
             "crontab": "",
             "once": false,
             "onceDelay": 0.1,
             "topic": "",
             "payload": "hsv(237,100,60)",
             "payloadType": "str",
             "x": 560,
             "y": 2420,
             "wires": [
                 [
                     "114d95e.3ff196a"
                 ]
             ]
         },
         {
             "id": "db63c4ff.bbc2b8",
             "type": "debug",
             "z": "54b226bc.0793e8",
             "name": "",
             "active": true,
             "tosidebar": true,
             "console": false,
             "tostatus": false,
             "complete": "false",
             "statusVal": "",
             "statusType": "auto",
             "x": 1370,
             "y": 2380,
             "wires": []
         },
         {
             "id": "204302c4.255aee",
             "type": "switch",
             "z": "54b226bc.0793e8",
             "name": "",
             "property": "$count(payload)",
             "propertyType": "jsonata",
             "rules": [
                 {
                     "t": "eq",
                     "v": "2",
                     "vt": "num"
                 },
                 {
                     "t": "eq",
                     "v": "3",
                     "vt": "num"
                 }
             ],
             "checkall": "true",
             "repair": false,
             "outputs": 2,
             "x": 970,
             "y": 2380,
             "wires": [
                 [
                     "e361c073.0c974"
                 ],
                 [
                     "5152e3fb.9b736c"
                 ]
             ]
         },
         {
             "id": "e361c073.0c974",
             "type": "change",
             "z": "54b226bc.0793e8",
             "name": "",
             "rules": [
                 {
                     "t": "set",
                     "p": "payload",
                     "pt": "msg",
                     "to": "{\t    \"brightness\": payload[0]\t}",
                     "tot": "jsonata"
                 }
             ],
             "action": "",
             "property": "",
             "from": "",
             "to": "",
             "reg": false,
             "x": 1170,
             "y": 2340,
             "wires": [
                 [
                     "db63c4ff.bbc2b8"
                 ]
             ]
         },
         {
             "id": "1d234b38.633fb5",
             "type": "debug",
             "z": "54b226bc.0793e8",
             "name": "",
             "active": true,
             "tosidebar": true,
             "console": false,
             "tostatus": false,
             "complete": "false",
             "statusVal": "",
             "statusType": "auto",
             "x": 1030,
             "y": 2300,
             "wires": []
         },
         {
             "id": "5152e3fb.9b736c",
             "type": "change",
             "z": "54b226bc.0793e8",
             "name": "",
             "rules": [
                 {
                     "t": "set",
                     "p": "payload",
                     "pt": "msg",
                     "to": "{\t    \"hue\": payload[0],\t    \"saturation\": payload[1],\t    \"brightness\": payload[2]\t}",
                     "tot": "jsonata"
                 }
             ],
             "action": "",
             "property": "",
             "from": "",
             "to": "",
             "reg": false,
             "x": 1170,
             "y": 2420,
             "wires": [
                 [
                     "db63c4ff.bbc2b8"
                 ]
             ]
         }
      ]
      

      Wie gesagt die Iteration in einem Objekt geht wahrscheinlich auch noch einfacher - der Vorteil zu der vorigen Variante ist, dass nur einmal das Array gebildet wird:

      1b4c0311-ba41-4109-903c-476903df6109-image.png

      [
          {
              "id": "8fda0f96.094af",
              "type": "change",
              "z": "54b226bc.0793e8",
              "name": "",
              "rules": [
                  {
                      "t": "set",
                      "p": "payload",
                      "pt": "msg",
                      "to": "(\t   $x := $match(payload,/\\d+/)[*].$number(match);\t   $x := {\t       \"hue\" : $x[0],\t       \"saturation\" : $x[1],\t       \"brightness\" : $x[2]\t            }\t   )",
                      "tot": "jsonata"
                  }
              ],
              "action": "",
              "property": "",
              "from": "",
              "to": "",
              "reg": false,
              "x": 840,
              "y": 2640,
              "wires": [
                  [
                      "15cd076b.9d4e69"
                  ]
              ]
          }
      ]
      
      mickym 1 Reply Last reply Reply Quote 0
      • mickym
        mickym Most Active @mickym last edited by

        @mickym So ich habe nun hier meine endgültige Version - einfacher bekomme ich es noch nicht hin:

        Aber ist wieder ein Einzeiler, wobei ich immernoch ein function definieren muss:

        8ef875b3-73b3-477c-9078-28caa32c187f-image.png

        $match($.payload,/\d+/)[*].$number(match) ~> function($x) {
           {
               "hue" : $x[0],
               "saturation" : $x[1],
               "brightness" : $x[2]
                    } 
        }
        
        Claus1985 0 1 Reply Last reply Reply Quote 0
        • mickym
          mickym Most Active @Claus1985 0 last edited by

          @claus1985-0

          Hier noch eine interessante Lösung - mit der CSV Node - habe ich erst gerade im NodeRed Forum gelesen. Da wird die Umwandlung in Zahlen automatisch vorgenommen, wenn es geht.

          730876e8-b563-4438-8f4d-010d7db0c542-image.png

          [
             {
                 "id": "2676e699.24d21a",
                 "type": "inject",
                 "z": "54b226bc.0793e8",
                 "name": "",
                 "props": [
                     {
                         "p": "payload"
                     }
                 ],
                 "repeat": "",
                 "crontab": "",
                 "once": false,
                 "onceDelay": 0.1,
                 "topic": "",
                 "payload": "hsv(237,100,60)",
                 "payloadType": "str",
                 "x": 480,
                 "y": 2700,
                 "wires": [
                     [
                         "d898bd42.c9aa3"
                     ]
                 ]
             },
             {
                 "id": "d898bd42.c9aa3",
                 "type": "change",
                 "z": "54b226bc.0793e8",
                 "name": "",
                 "rules": [
                     {
                         "t": "change",
                         "p": "payload",
                         "pt": "msg",
                         "from": ".*\\((.*)\\)",
                         "fromt": "re",
                         "to": "$1",
                         "tot": "str"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 700,
                 "y": 2700,
                 "wires": [
                     [
                         "3e8a2638.f0148a",
                         "7b3a7061.a068"
                     ]
                 ]
             },
             {
                 "id": "7b3a7061.a068",
                 "type": "csv",
                 "z": "54b226bc.0793e8",
                 "name": "",
                 "sep": ",",
                 "hdrin": "",
                 "hdrout": "none",
                 "multi": "one",
                 "ret": "\\n",
                 "temp": "",
                 "skip": "0",
                 "strings": true,
                 "include_empty_strings": "",
                 "include_null_values": "",
                 "x": 890,
                 "y": 2700,
                 "wires": [
                     [
                         "b521ebd1.5b01c8"
                     ]
                 ]
             },
             {
                 "id": "20b20f88.7ed18",
                 "type": "debug",
                 "z": "54b226bc.0793e8",
                 "name": "",
                 "active": true,
                 "tosidebar": true,
                 "console": false,
                 "tostatus": false,
                 "complete": "false",
                 "statusVal": "",
                 "statusType": "auto",
                 "x": 1270,
                 "y": 2700,
                 "wires": []
             },
             {
                 "id": "3e8a2638.f0148a",
                 "type": "debug",
                 "z": "54b226bc.0793e8",
                 "name": "",
                 "active": true,
                 "tosidebar": true,
                 "console": false,
                 "tostatus": false,
                 "complete": "false",
                 "statusVal": "",
                 "statusType": "auto",
                 "x": 950,
                 "y": 2760,
                 "wires": []
             },
             {
                 "id": "b521ebd1.5b01c8",
                 "type": "change",
                 "z": "54b226bc.0793e8",
                 "name": "",
                 "rules": [
                     {
                         "t": "move",
                         "p": "payload.col1",
                         "pt": "msg",
                         "to": "payload.hue",
                         "tot": "msg"
                     },
                     {
                         "t": "move",
                         "p": "payload.col2",
                         "pt": "msg",
                         "to": "payload.saturation",
                         "tot": "msg"
                     },
                     {
                         "t": "move",
                         "p": "payload.col3",
                         "pt": "msg",
                         "to": "payload.brightness",
                         "tot": "msg"
                     }
                 ],
                 "action": "",
                 "property": "",
                 "from": "",
                 "to": "",
                 "reg": false,
                 "x": 1070,
                 "y": 2700,
                 "wires": [
                     [
                         "20b20f88.7ed18"
                     ]
                 ]
             }
          ]
          

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

            @mickym sehr elegant und kompakt!
            Eins hab ich vergessen, ist mir grad beim ausprobieren aufgefallen. Ist es möglich in dem Programm analog Brightness, Hue und Saturation noch On (Boolean) mit einzufügen, dass autom. gesetzt wird je nach Brightness Wert (Brightness = 0 > false, Brighhness grösser 0 > true)?

            Danke und Gruß,

            Claus

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

              @claus1985-0 sagte in String in Objekt umwandeln:

              @mickym sehr elegant und kompakt!
              Eins hab ich vergessen, ist mir grad beim ausprobieren aufgefallen. Ist es möglich in dem Programm analog Brightness, Hue und Saturation noch On (Boolean) mit einzufügen, dass autom. gesetzt wird je nach Brightness Wert (Brightness = 0 > false, Brighhness grösser 0 > true)?

              Danke und Gruß,

              Claus

              Meinst Du so?

              f47e2098-b56f-474c-8dd9-e85f74806464-image.png

              [
                 {
                     "id": "8d316bcb.d5a0a8",
                     "type": "change",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "rules": [
                         {
                             "t": "set",
                             "p": "payload",
                             "pt": "msg",
                             "to": "$match($.payload,/\\d+/)[*].$number(match) ~> function($x) {\t   {\t       \"hue\" : $x[0],\t       \"saturation\" : $x[1],\t       \"brightness\" : $x[2],\t       \"on\" : $x[2] > 0 ? true : false\t            } \t}",
                             "tot": "jsonata"
                         }
                     ],
                     "action": "",
                     "property": "",
                     "from": "",
                     "to": "",
                     "reg": false,
                     "x": 770,
                     "y": 2040,
                     "wires": [
                         [
                             "93d9d8b5.26ff98"
                         ]
                     ]
                 },
                 {
                     "id": "93d9d8b5.26ff98",
                     "type": "debug",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "active": true,
                     "tosidebar": true,
                     "console": false,
                     "tostatus": false,
                     "complete": "false",
                     "statusVal": "",
                     "statusType": "auto",
                     "x": 960,
                     "y": 2040,
                     "wires": []
                 },
                 {
                     "id": "56febbc6.3c4944",
                     "type": "inject",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "props": [
                         {
                             "p": "payload"
                         }
                     ],
                     "repeat": "",
                     "crontab": "",
                     "once": false,
                     "onceDelay": 0.1,
                     "topic": "",
                     "payload": "hsv(237,100,60)",
                     "payloadType": "str",
                     "x": 540,
                     "y": 2020,
                     "wires": [
                         [
                             "8d316bcb.d5a0a8"
                         ]
                     ]
                 },
                 {
                     "id": "4d7bedbb.68d9b4",
                     "type": "inject",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "props": [
                         {
                             "p": "payload"
                         }
                     ],
                     "repeat": "",
                     "crontab": "",
                     "once": false,
                     "onceDelay": 0.1,
                     "topic": "",
                     "payload": " temp(47,4464)",
                     "payloadType": "str",
                     "x": 540,
                     "y": 1920,
                     "wires": [
                         [
                             "ba81659a.38d878"
                         ]
                     ]
                 },
                 {
                     "id": "ba81659a.38d878",
                     "type": "change",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "rules": [
                         {
                             "t": "set",
                             "p": "payload",
                             "pt": "msg",
                             "to": "$match($.payload,/\\d+/)[*].$number(match) ~> function($x) {\t   {\t       \"brightness\" : $x[0],\t       \"colortemp\" : $x[1],\t       \"on\" : $x[0] > 0 ? true : false\t            } \t}",
                             "tot": "jsonata"
                         }
                     ],
                     "action": "",
                     "property": "",
                     "from": "",
                     "to": "",
                     "reg": false,
                     "x": 770,
                     "y": 1940,
                     "wires": [
                         [
                             "ba0163ff.e6896"
                         ]
                     ]
                 },
                 {
                     "id": "ba0163ff.e6896",
                     "type": "debug",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "active": true,
                     "tosidebar": true,
                     "console": false,
                     "tostatus": false,
                     "complete": "false",
                     "statusVal": "",
                     "statusType": "auto",
                     "x": 960,
                     "y": 1940,
                     "wires": []
                 },
                 {
                     "id": "1dedf46.62a380c",
                     "type": "inject",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "props": [
                         {
                             "p": "payload"
                         }
                     ],
                     "repeat": "",
                     "crontab": "",
                     "once": false,
                     "onceDelay": 0.1,
                     "topic": "",
                     "payload": " temp(0,4464)",
                     "payloadType": "str",
                     "x": 550,
                     "y": 1960,
                     "wires": [
                         [
                             "ba81659a.38d878"
                         ]
                     ]
                 },
                 {
                     "id": "d4ab5b3a.f7bcb8",
                     "type": "inject",
                     "z": "54b226bc.0793e8",
                     "name": "",
                     "props": [
                         {
                             "p": "payload"
                         }
                     ],
                     "repeat": "",
                     "crontab": "",
                     "once": false,
                     "onceDelay": 0.1,
                     "topic": "",
                     "payload": "hsv(237,100,0)",
                     "payloadType": "str",
                     "x": 540,
                     "y": 2060,
                     "wires": [
                         [
                             "8d316bcb.d5a0a8"
                         ]
                     ]
                 }
              ]
              

              Anderenfalls halt mit Switch abprüfen und gesondert schalten.

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

                @mickym Mega, funktioniert perfekt!! Vielen, vielen Dank! ✌
                Ich bin inzwischen übrigens auch beim umgekehrten Weg etwas weitergekommen dank Deinen Tipps und einem Code aus dem NodeRed Forum (siehe Function im Code):

                [
                   {
                       "id": "d75f0ada.a524f8",
                       "type": "debug",
                       "z": "f3f0ca0.5f2f538",
                       "name": "Aus Homekit umgewandelt Werte",
                       "active": true,
                       "tosidebar": true,
                       "console": false,
                       "tostatus": false,
                       "complete": "payload",
                       "targetType": "msg",
                       "statusVal": "",
                       "statusType": "auto",
                       "x": 3560,
                       "y": 3360,
                       "wires": []
                   },
                   {
                       "id": "16d7556083bcce80",
                       "type": "function",
                       "z": "f3f0ca0.5f2f538",
                       "name": "",
                       "func": "let store = context.get('store') || {\"Brightness\":100,\"Saturation\":28,\"Hue\":335}\n\nObject.assign (store, msg.payload)\n\ncontext.set('store', store); \n\nmsg.payload = store;\n\nvar hue = msg.payload.Hue;\nvar sat = msg.payload.Saturation;\nvar bri = msg.payload.Brightness;\nreturn {payload: [hue, sat, bri]};",
                       "outputs": 1,
                       "noerr": 0,
                       "initialize": "",
                       "finalize": "",
                       "libs": [],
                       "x": 2880,
                       "y": 3360,
                       "wires": [
                           [
                               "b9f34451.c1aa38"
                           ]
                       ]
                   },
                   {
                       "id": "b9f34451.c1aa38",
                       "type": "change",
                       "z": "f3f0ca0.5f2f538",
                       "name": "In String umwandeln",
                       "rules": [
                           {
                               "t": "set",
                               "p": "payload",
                               "pt": "msg",
                               "to": "$string(msg.payload)",
                               "tot": "jsonata"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 3080,
                       "y": 3360,
                       "wires": [
                           [
                               "90af8445.678f58"
                           ]
                       ]
                   },
                   {
                       "id": "90af8445.678f58",
                       "type": "change",
                       "z": "f3f0ca0.5f2f538",
                       "name": "String anpassen",
                       "rules": [
                           {
                               "t": "change",
                               "p": "payload",
                               "pt": "msg",
                               "from": "[",
                               "fromt": "str",
                               "to": "hsv(",
                               "tot": "str"
                           },
                           {
                               "t": "change",
                               "p": "payload",
                               "pt": "msg",
                               "from": "]",
                               "fromt": "str",
                               "to": ")",
                               "tot": "str"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 3300,
                       "y": 3360,
                       "wires": [
                           [
                               "d75f0ada.a524f8"
                           ]
                       ]
                   },
                   {
                       "id": "2e057f29.73b3e",
                       "type": "switch",
                       "z": "f3f0ca0.5f2f538",
                       "name": "",
                       "property": "payload",
                       "propertyType": "msg",
                       "rules": [
                           {
                               "t": "cont",
                               "v": "payload.On",
                               "vt": "msg"
                           },
                           {
                               "t": "else"
                           }
                       ],
                       "checkall": "true",
                       "repair": false,
                       "outputs": 2,
                       "x": 2730,
                       "y": 3340,
                       "wires": [
                           [
                               "faad214e.ac7d2"
                           ],
                           [
                               "16d7556083bcce80"
                           ]
                       ]
                   },
                   {
                       "id": "2cd24509.aee27a",
                       "type": "debug",
                       "z": "f3f0ca0.5f2f538",
                       "name": "Aus Homekit On/Off",
                       "active": true,
                       "tosidebar": true,
                       "console": false,
                       "tostatus": false,
                       "complete": "payload",
                       "targetType": "msg",
                       "statusVal": "",
                       "statusType": "auto",
                       "x": 3440,
                       "y": 3320,
                       "wires": []
                   },
                   {
                       "id": "faad214e.ac7d2",
                       "type": "change",
                       "z": "f3f0ca0.5f2f538",
                       "name": "Boolean2Integer",
                       "rules": [
                           {
                               "t": "change",
                               "p": "payload.On",
                               "pt": "msg",
                               "from": "true",
                               "fromt": "bool",
                               "to": "0",
                               "tot": "num"
                           },
                           {
                               "t": "change",
                               "p": "payload.On",
                               "pt": "msg",
                               "from": "false",
                               "fromt": "bool",
                               "to": "off",
                               "tot": "str"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 2900,
                       "y": 3320,
                       "wires": [
                           [
                               "ae33f17a.3a4c1"
                           ]
                       ]
                   },
                   {
                       "id": "ae33f17a.3a4c1",
                       "type": "change",
                       "z": "f3f0ca0.5f2f538",
                       "name": "Set playoad.On to payload",
                       "rules": [
                           {
                               "t": "move",
                               "p": "payload.On",
                               "pt": "msg",
                               "to": "payload",
                               "tot": "msg"
                           },
                           {
                               "t": "delete",
                               "p": "payload.On",
                               "pt": "msg"
                           }
                       ],
                       "action": "",
                       "property": "",
                       "from": "",
                       "to": "",
                       "reg": false,
                       "x": 3130,
                       "y": 3320,
                       "wires": [
                           [
                               "2cd24509.aee27a"
                           ]
                       ]
                   }
                ]
                

                Homekit schickt immer nur den sich ändernden Wert (z.B. nur Hue oder nur Saturation oder nur Brightness), das Zielsystem benötigt aber immer einen vollständigen Ausdruck mit allen drei Werten.
                Ich habe oben nun eine Funktion, welche alle eingehenden Werte speichert, konsolidiert und dann zusammen als eine Nachricht weitergibt. Falls noch keine Werte kamen greift sie auf default Werte zurück.

                Ein Problem habe ich noch mit dem Code der Funktion:
                Wenn sich der Wert On von true auf false und dann wieder auf true ändert wäre es gut, wenn er auf die Default Werte zurückgreift und diese weitergibt (immer wenn die Lampe aus- und wieder eingeschaltet wird).
                Er soll also nur dann die konsolidierten Werte senden, wenn die Lampe zwischendrin nicht ausgeschaltet wurde.

                Hast Du eine Idee wie ich die Funktion dafür anpassen müsste?

                Danke und Gruß,

                Claus

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

                  @claus1985-0 Na Du kannst ja wenn On=false ist, den Context in der Function Node einfach löschen, beim nächsten Mal werden dann true ist es dann wie bei Neuinitialisierung.

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

                    @mickym Gute, Idee! Kannst Du mir da mit der Syntax weiterhelfen? Bekomme es nicht gelöst 😕

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

                      @claus1985-0 sagte in String in Objekt umwandeln:

                      @mickym Gute, Idee! Kannst Du mir da mit der Syntax weiterhelfen? Bekomme es nicht gelöst 😕

                      c87e974d-4aa8-405e-af4a-44d9fcad74fd-image.png

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

                        @mickym Vielen Dank für Deine Hilfe! 🙂
                        Mit der Zeile funktioniert es nun allerdings kann ich die Lampe nicht mehr ausschalten 😄
                        Wenn ich ausschalte ist ja die if Bedingung wahr und führt zum Default was wiederum zum Einschalten der
                        Lampe führt.

                        Wenn ich in der letzten Zeile if (msg.payload.On) einfüge schickt er keine Nachrichten mehr,
                        wenn kein .On dabei ist 🙄

                        if (!msg.payload.On) context.set('store', undefined);
                        let store = context.get('store') || {"Brightness":100,"Saturation":28,"Hue":33}
                        
                        Object.assign (store, msg.payload)
                        
                        context.set('store', store); 
                        
                        msg.payload = store;
                        
                        var hue = msg.payload.Hue;
                        var sat = msg.payload.Saturation;
                        var bri = msg.payload.Brightness;
                        if (msg.payload.On) return {payload: [hue, sat, bri]};
                        

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

                          @claus1985-0 Na das zum Schluß ist ja klar, mach das einfach wieder rückgängig und wie ursprünlgich.

                          Dann nimmst halt meine 1. Zeile und setzt sie hinter das msg.payload=store. Dann wird die Nachricht nochmal wie vorher geschickt, aber der Kontext gelöscht und somit werden die Defaultwerte werden erst bei der nächsten Nachricht aktiv.

                          Schöner ist halt wenn man das alles via Flow Variablen macht - dann implementiert man Logiken im Flow und nicht in einer function Node. Aber egal .

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

                          Support us

                          ioBroker
                          Community Adapters
                          Donate

                          1.0k
                          Online

                          31.7k
                          Users

                          79.7k
                          Topics

                          1.3m
                          Posts

                          3
                          17
                          1469
                          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