How can I work with ioBroker-variables in Node-red function?

Hi
I want to read sensor-data, store these values in iobroker and later i want to sum the variables in a function-node.

My function code:

var dcPower = env.get("msg.dc.power");
var wallbox1Power = env.get("msg.wallbox1.power");
var wallbox2Power = env.get("msg.wallbox2.power");
var sum = dcPower;
msg.payload;
return msg;

On the bottom flow, is a debug node to determine where the value arrives. Assuming it is msg.payload, use a change node to copy or move this to their own msg property e.g. msg.val1 msg.val2. When the msg arrives at the function node, you will be able to access all the values at the same time from the msg properties you set in the change nodes.

Thanks for your answer.
I set the attribute i the "ioBroker get"-node. In the picture you can see that the variables are stored in the function node, but the sum or payload are empty.

It looks like the values are already in some other msg property. Use the copy path button to grab the path to the value and use that with msg. instead of env.get (env.get is for environment vars not for accessing msg properties)

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

https://nodered.org/docs/user-guide/messages


Ps, it may be necessary to use parseInt or parseFloat to coerce the string values into numbers before doing math operations.

image

I copied the path as described above, but that changes nothing.
Are there other options?

parseInt needs round (not square) brackets.

Also, don't put msg.xxxx in quotes.

I tried. Than I got the message:
"TypeError: Cannot read property 'power' of undefined"

Try msg["dc.power"]

The property name has a . in it (power is not a sub property of dc)

This is known as square bracket notation

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