Function extract value help

hi guys,

I have simple question.
working on some rough data and want to extract just the value in function node:

{"topic":"xiaomi/lounge/th","payload":{"cmd":"report","model":"weather.v1","sid":"158d000201b16a","short_id":33470,"data":"{"temperature":"2803"}"},"qos":0,"retain":false,"_msgid":"cc82776e.9b0708"}

just need numeric value of temperature out of it. Possibly with proper formatting 28.0 instead of 2803.
can anyone help?

thanks

divide by 1000?

Cough :wink:

oops! I’m blaming auto correct!

1 Like

@cismarine - divide by 100

Thanks Paul,
That is the easy part, but how do I get just the numeric value out of the object?

If you attach a debug node to the incoming message, what do you see?

that's output from my mqtt:

{"topic":"xiaomi/lounge/th","payload":{"cmd":"report","model":"weather.v1","sid":"158d000201b16a","short_id":33470,"data":"{"humidity":"9334"}"},"qos":0,"retain":false,"_msgid":"53f2dd35.0db3d4"}

Wire the mqtt-in node to a function-node:

var xm_msg = JSON.parse(msg.payload);

if (xm_msg.data) {
    var data = JSON.parse(xm_msg.data);

    if (data.temperature) {
        msg.payload = {"temperature": Math.round(data.temperature / 100)};
    } else if (data.humidity) {
        msg.payload = {"humidity": Math.round(data.humidity / 100)};
    }
}

return msg;

Thank you very much.

I have tested it and added couple more values.
Now I have follow up question...
How can I send each individual value on different function output?

return [msg1,msg2,msg3,msg4];

TIA

Have you read the docs?

https://nodered.org/docs/writing-functions#multiple-outputs

I suppose you are using several xiaomi devices. If so, you will have to select several parameters (cmd, sid, model). I would use switch nodes to do the job.
Which xiaomi models are you using?

quite a few. Mainly aquara sensors.
I inject their data into mqtt already sorted by device (with separate topics)