# Calculating with flow variables in function node

**URL:** <https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036>\
**Category:** General\
**Tags:** function-node\
**Created:** [11 February 2023 13:07 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036 "2023-02-11T13:07:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmmmm](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kmmmm](https://discourse.nodered.org/u/kmmmm)\
**Post date:** [11 February 2023 13:07 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036/1 "2023-02-11T13:07:42Z")

</div>

**strong text** Hi, 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:

```auto
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 😉

í`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!  
km

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [11 February 2023 13:28 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036/2 "2023-02-11T13:28:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2023 16:49 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036/3 "2023-02-11T16:49:15Z")

</div>

> [@kmmmm](#):
>
> `Number.flow.get("t")`

Also Number is a function, so it would be  
`Number(flow.get("t"))`

---

<div class="post-metadata">

**Author:** ![kmmmm](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kmmmm](https://discourse.nodered.org/u/kmmmm)\
**Post date:** [13 February 2023 08:31 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036/4 "2023-02-13T08:31:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [13 February 2023 08:50 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036/5 "2023-02-13T08:50:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kmmmm](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kmmmm](https://discourse.nodered.org/u/kmmmm)\
**Post date:** [16 February 2023 18:52 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036/6 "2023-02-16T18:52:18Z")

</div>

thx jbudd had only one active 🙄

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 April 2023 18:52 UTC](https://discourse.nodered.org/t/calculating-with-flow-variables-in-function-node/75036/7 "2023-04-17T18:52:57Z")

</div>

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