# Formula con nodo function

**URL:** <https://discourse.nodered.org/t/formula-con-nodo-function/47575>\
**Category:** General\
**Created:** [24 June 2021 10:18 UTC](https://discourse.nodered.org/t/formula-con-nodo-function/47575 "2021-06-24T10:18:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidfigueroa](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@davidfigueroa](https://discourse.nodered.org/u/davidfigueroa)\
**Post date:** [24 June 2021 10:18 UTC](https://discourse.nodered.org/t/formula-con-nodo-function/47575/1 "2021-06-24T10:18:57Z")

</div>

How can I create this formula with a function node

 ![formula](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6afc3a869928de91de3f2d3ecc0e99ba08e00720.jpeg)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [24 June 2021 10:23 UTC](https://discourse.nodered.org/t/formula-con-nodo-function/47575/2 "2021-06-24T10:23:03Z")

</div>

Have a look at the MDN docs for the JavaScript `Math` object. That has lots of the functions you'll need (like `Math.sqrt()`)

> **[Math - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math)**
>
> Math is a built-in object that has properties and methods for mathematical constants and functions. It’s not a function object.

You then need to identify how all of those variables (`C` `Smax` `Vn` etc) are provided to the Function - are they message properties? Constants? And so on.

---

<div class="post-metadata">

**Author:** ![davidfigueroa](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@davidfigueroa](https://discourse.nodered.org/u/davidfigueroa)\
**Post date:** [29 June 2021 08:52 UTC](https://discourse.nodered.org/t/formula-con-nodo-function/47575/3 "2021-06-29T08:52:50Z")

</div>

I want Smax, Cn, Vn and CTRn to be non-constant variables and I don't know how to create an array to be able to modify them from a mqtt

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 June 2021 09:03 UTC](https://discourse.nodered.org/t/formula-con-nodo-function/47575/4 "2021-06-29T09:03:12Z")

</div>

Pass Cn, Vn and CTRn in a `msg` to the function block.

Start small...

Start by inserting these values using in a `inject` node and passing them to the function node. Once you have the inject + function working, try to get it working with the MQTT values.

* * *

As a user new to node-red, I think it would benefit you to watch this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<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:** [28 August 2021 09:03 UTC](https://discourse.nodered.org/t/formula-con-nodo-function/47575/5 "2021-08-28T09:03:33Z")

</div>

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