Split value angleX Y Z

Hello,

I did use the search function, but i need some help.
I have an aqara vibration sensor, then gives svalues.

svalue1: "angleX: 0, angleY: 89, angleZ: 1"

What is want, each value seperate, without the text angelY.
How to do that? Maybe an example?

How does that data get into Node-red?
Is it an object or a string?

Please use a debug node to capture the value in Node-red and post it here.

BX00Cy7yHi

firefox_2023-01-04_20-57-43

Thanks for your support!

In a function node you could use something like:

const input = msg.payload.svalue1
const output = {}
input.split(",").forEach(e=>{
    const angle = e.split(":")[0].trim()
    const value = e.split(":")[1].trim()
    output[angle] = Number(value)
})
msg.output = output

return msg;

which produces

the output stays the same.
Also i need the output seperate of each angle.

Your debug node is looking at the payload only (the solution offered bt @bakman2 puts the answer into msg.output)

You could simply rejig the function to overwrite the original property...

const input = msg.payload.svalue1
msg.payload.svalue1 = Object.fromEntries(input.split(',').map(e => { 
        const parts = e.split(':').map(f => f.trim())
        return [parts[0], Number(parts[1])] 
}))
return msg
1 Like

Thanks, that was the solution!!

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