Calculating with flow variables in function node

strong textHi, wanna request help as a beginner.
couldn’t `t find a solution for the topic anywhere by my self.

Issue: get two values from dashboard number node (store them in two flow variables as “t” & “n” ) and one from a sensor with msg.topic = sensor (data import is ok).

now i want to calculate (percentage) with this 3 values in a function node, here is the lack of knowledge.

tried this:

var "f" = { (Number.flow.get("t")   -  Number.flow.get("n")) / Number.msg.topic.sensor};
msg.payload = ["f" +”%”];
return msg;

would be glad for any hint :wink:

í`m also insecure for best practice to store the dashboard values in flow.
direct at the number node or with a extra change node after the number node.

is msg.topic the tight “position” to give the live sensor data in the function node or would it be better anywhere else?

yes - more lack then knowledge

at all it should bring me a sensor calibration flow, based at min-, max-, present-value , cause i couldn`t find a flow about this - if there is a existing one - please let me know.

thanks for your help!

a) Normally sensor data would have the sensor identification in msg.topic and the sensor reading in msg.payload.

b) The dashboard number input node will surely create a numeric value rather than a string.
If you save that to context flow.set("t", msg.payload) then it is stored as a number and you don't need to convert it in your calculation.
Similarly the sensor reading may well be a number not a string.

c) When you declare a variable you don't need to wrap it in quotes.
You don't need the quotes when you use it either :
var f=42
msg.payload = f +"%"
Note that you do need quotes - single or double - round the name of a context variable to indicate that the name is a string, not the name of some other variable.

d) wrapping [f + "%"] in square brackets makes the payload an array (with just one element).
Is that what you intended?

Also Number is a function, so it would be

Thank you for your help and quick reply!

read/set of variable and calculation is solved.

Can you please let me know where is the correct place to store a value (min - max calibration values) so this are always available at start of the flow without active input? In a “value” File or is it possible to write form Numeric dashboard input to the default value of a variable?

There is another issue with dashboard:

  • no sidebar available at dashboard (sure settings to show are enabled)
  • dashboard node is updated (node-red-dashboard and no other one installed)
  • dashboard node removed / install with restart etc. no effort
    Someone any hint?

How many dashboard tabs have you got?
The sidebar is only shown if you have widgets enabled on more than one tabs.

thx jbudd had only one active :roll_eyes:

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