# How can I create 'functions' that any flow can access?

**URL:** <https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900>\
**Category:** General\
**Created:** [28 April 2022 00:39 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900 "2022-04-28T00:39:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)\
**Post date:** [28 April 2022 00:39 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/1 "2022-04-28T00:39:40Z")

</div>

I'm working on some 'functions' that I can us to keep the states (JSON) of various HA devices but I'd like to keep these as functions instead of a REST flow. Is there a way to create functions that can be use in other flows?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 April 2022 00:48 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/2 "2022-04-28T00:48:41Z")

</div>

Maybe you need to look at/into subflows.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [28 April 2022 01:58 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/3 "2022-04-28T01:58:31Z")

</div>

+1 for Andrew here - plus there is also the link nodes that have been created that seem to offer an alternative to subflows (i think from NR 2.2 onwards)

There is also this that someone posted about a couple of weeks ago that i mean to try and put some time towards as it looks interesting

> **[node-red-contrib-things](https://flows.nodered.org/node/node-red-contrib-things)**
>
> A set of Node-RED nodes that uses an agnostic state management system to keep IOT device states and provide a uniform control system.

and then finally

> **[node-red-contrib-actionflows](https://flows.nodered.org/node/node-red-contrib-actionflows)**
>
> Create extendable, loopable, and reusable design patterns for flows.

Which i started playng with last year and ran out of time and motivation to move anything meaningful to it

Craig

---

<div class="post-metadata">

**Author:** ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)\
**Post date:** [28 April 2022 02:01 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/4 "2022-04-28T02:01:41Z")

</div>

Both are interesting, the first is most interesting. 🙂

---

<div class="post-metadata">

**Author:** ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)\
**Post date:** [28 April 2022 12:47 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/5 "2022-04-28T12:47:54Z")

</div>

I'm still looking at the two nodes above and trying to see if sub-flow is appropriate (I generally keep my special automation in distinct tabs). But it dawned on me that I can store a json object in the global context and add protoypes there. Still needs a lot of work. And I am looking to building a REST like interface to Mongodb (I'm not using Atlas) for other reasons. So lots of thinking and experimenting to do.  
Thanks

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 April 2022 13:50 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/6 "2022-04-28T13:50:11Z")

</div>

Isn't the whole purpose of HA that it is a state machine ?

---

<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:** [28 April 2022 13:50 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/7 "2022-04-28T13:50:19Z")

</div>

> [@ncherry](#):
>
> I generally keep my special automation in distinct tabs

The "link call" node is (pretty much) designed for this purpose.

A subflow is great and all but if you dont want or need the complications of internal state & context or trying to access upper level flow context etc, then try with link call nodes first.  
Think of them as subroutines where you call to a common function (sending in some parameters AKA stuff in the msg) then you get a computed response (with properties of the msg updated from your linked flow)

---

<div class="post-metadata">

**Author:** ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)\
**Post date:** [28 April 2022 15:24 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/8 "2022-04-28T15:24:43Z")

</div>

Actually yes, we need to know the current state to make decisions.

---

<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:** [27 June 2022 15:25 UTC](https://discourse.nodered.org/t/how-can-i-create-functions-that-any-flow-can-access/61900/9 "2022-06-27T15:25:07Z")

</div>

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