String to object conversion

Hi there,
I am currently struggling with updating my Node Red intergration of Loxone and IKEA Tradfri Panel.

I recently was able to get an array with brightness value and color temp out of my Loxone server but they now decided to change the output to a string:

temp(46,3840)

I need to turn this into an object like here:

{"brightness":211,"color_temp":4700}

As I am a complete beginner to those things I would need some help on how to get the brightness and color_temp value out of the string.

Many Thanky for your help

Here is an example using a change node and JSONata expression

first it matches the numbers
then i loops though the matches and converts the strings to numbers. finally it takes the numbers and creates the object.

[{"id":"d72d6c96.dacd","type":"inject","z":"7f59364f045fd16d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"temp(46,3840)","payloadType":"str","x":230,"y":580,"wires":[["a7cfb606.aecfc"]]},{"id":"a7cfb606.aecfc","type":"change","z":"7f59364f045fd16d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[[$match($$.payload, /\\d+/).match.$number($)]].{\"brightness\":$[0],\"color_temp\":$[1]}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":580,"wires":[["a966cb14.c37eb"]]},{"id":"a966cb14.c37eb","type":"debug","z":"7f59364f045fd16d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":600,"wires":[]}]

Hi E1cid,
thank your for helping out. I do not understand the code but it works. Many many thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.