How to split UDP message

Im getting UDP message from my weather station in this format:

payload: "tempinc=25.8 humidityin=52 baromrelhpa=1013.82 baromabshpa=988.01 tempc=17.8 humidity=86 winddir=350 windspeedkmh=1.13 windgustkmh=1.77 maxdailygust=29.45 rainratemm=0.0 eventrainmm=6.3 hourlyrainmm=0.0 dailyrainmm=6.3 weeklyrainmm=23.29 monthlyrainmm=23.29 totalrainmm=396.49 solarradiation=0.00 uv=0 wh65batt=0 freq=868M model=WS2900_V2.01.10 dewptc=15.4 windchillc=17.8 feelslikec=17.8 heatindexc=17.8 windspdkmh_avg10m=0.16 winddir_avg10m=346 windgustkmh_max10m=1.77 brightness=0.0 sunhours=5.7 ptrend1=2 pchange1=0.8 wnowlvl=2 wnowtxt=unstable ptrend3=-1 pchange3=0.6 wproglvl=5 wprogtxt="nice for a long time""

I need to split it to separate MQTT topics likes:

"FOSHK/tempinc=25.8"
"FOSHK/humidityin=52"
...

for using sensors in Home Assistant.

Do you have any idea how to do this?

Hello Radek ... you need some javascript in a Function node.
Not the cleanest way to process this but here's my attempt

[{"id":"ae6ac6774bba3285","type":"inject","z":"9af9141769558c7a","name":"get","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"tempinc=25.8 humidityin=52 baromrelhpa=1013.82 baromabshpa=988.01 tempc=17.8 humidity=86 winddir=350 windspeedkmh=1.13 windgustkmh=1.77 maxdailygust=29.45 rainratemm=0.0 eventrainmm=6.3 hourlyrainmm=0.0 dailyrainmm=6.3 weeklyrainmm=23.29 monthlyrainmm=23.29 totalrainmm=396.49 solarradiation=0.00 uv=0 wh65batt=0 freq=868M model=WS2900_V2.01.10 dewptc=15.4 windchillc=17.8 feelslikec=17.8 heatindexc=17.8 windspdkmh_avg10m=0.16 winddir_avg10m=346 windgustkmh_max10m=1.77 brightness=0.0 sunhours=5.7 ptrend1=2 pchange1=0.8 wnowlvl=2 wnowtxt=unstable ptrend3=-1 pchange3=0.6 wproglvl=5 wprogtxt=\"nice for a long time\"","payloadType":"str","x":370,"y":540,"wires":[["904297a1bdcc7270","be093a984e271310"]]},{"id":"0e45d5c1f62c5a1a","type":"debug","z":"9af9141769558c7a","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":540,"wires":[]},{"id":"904297a1bdcc7270","type":"function","z":"9af9141769558c7a","name":"Array to Object","func":"let obj = {};\n\n\nlet wprogtxt = msg.payload.split(\" wprogtxt=\")[1].replace(/\\\"/g, \"\")    // special case\nlet data = msg.payload.split(\" wprogtxt=\")[0]\n//node.warn(data);\n\ndata = data.split(\" \")\ndata.forEach( el => {\n    let arr = el.split(\"=\")\n    obj[`FOSHK/${arr[0]}`] = !isNaN(arr[1]) ? Number(arr[1]) : arr[1]\n})\n\nobj[`FOSHK/wprogtxt`] = wprogtxt;   // add back the special case\n\nmsg.payload = obj;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":540,"wires":[["0e45d5c1f62c5a1a"]]},{"id":"be093a984e271310","type":"debug","z":"9af9141769558c7a","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":480,"y":460,"wires":[]}]

It works perfectly. Thanks!!

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