# Receive a reading, then set a flag to be read in another totally separate flow ... help needed

**URL:** <https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135>\
**Category:** General\
**Created:** [30 December 2023 15:34 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135 "2023-12-30T15:34:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [30 December 2023 15:34 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/1 "2023-12-30T15:34:42Z")

</div>

I have tried for hours to get this to work and searched on here and internet.  
It seems a very simple task but I cannot get it to work,

A electricity meter reading is received randomly, due to house demand.  
I have a `Change node` that waits for a change in the reading.  
This reading is made global, so any flow can pick it up.

The problem ...  
I then want to set a flag, which can be picked up on a separate flow on a different tab.  
This flow would then wait until the flag is set to **true** , but I cannot get this to work.

I tried setting my own `msg.electricity_reading` using a change node, to set it to **true** and picking that up, but that did not work ?

I only ever used **msg.payload** so I may not understand how creating my own **msg.something**  
works ?

This gives me **undefined** on a debug msg

![05](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/737d7a25a3aa949104b5b8301cdd31ed09b9c065.png)

Any help would be appreciated , thanks

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 December 2023 15:42 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/2 "2023-12-30T15:42:20Z")

</div>

Instead of setting a global, use link out node, then in any flow use a link in node and link it to the link out node. You can have multiple link in nodes connected to link out nodes.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [30 December 2023 15:54 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/3 "2023-12-30T15:54:25Z")

</div>

Hi thanks for that, I do use **link nodes** on various other flows, never occurred to me use one after a **change node**.

From doing coding on Arduino I use **flags** a lot, so i assumed it would be the correct thing to do on NodeRED.

Funny how we go down a path then ask someone and now the solution is obvious !

Thanks

---

<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:** [30 December 2023 17:36 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/4 "2023-12-30T17:36:20Z")

</div>

> [@questuk](#):
>
> never occurred to me use one after a **change node**.

You don't need the Change node, just send a message to the other flow using the link node and do whatever is required then.

> [@questuk](#):
>
> on Arduino I use **flags** a lot, so i assumed it would be the correct thing to do on NodeRED.

The node-red way is to send messages, avoid using flow and global context whenever practical.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [30 December 2023 22:23 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/5 "2023-12-30T22:23:30Z")

</div>

Thanks Colin, I will do both of those 👍

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [31 December 2023 08:35 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/6 "2023-12-31T08:35:46Z")

</div>

Hi,

I am now using the **Link node** , which is much better than using **Globals**.  
But I do have one problem and I am not sure if there is a better way ?

@ 23.59 I save the total electricity used to a database using a Global.  
@ 00.00 the meter reading is set for a new day to 0.0

Can I somehow use a Link node and some other node to do the above @ 23.59 ?  
Then I am not reliant on a Global anymore.

Thanks

 ![01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/5234bcf1a6e39a679d2ed482deb089d111a723fe.png)

---

<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:** [31 December 2023 13:40 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/7 "2023-12-31T13:40:03Z")

</div>

> [@questuk](#):
>
> do the above @ 23.59

Do what exactly?

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [31 December 2023 16:34 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/8 "2023-12-31T16:34:53Z")

</div>

> [@questuk](#):
>
> Can I somehow use a Link node and some other node to do the above @ 23.59 ?  
> Then I am not reliant on a Global anymore.

Don't try to prevent using any programming pattern - but try to use what fits best to your demands:  
[`Context`](https://nodered.org/docs/user-guide/context) (that you named _global_) is the Node-RED way to persist data between several runs of a flow. Thus it's perfect for cumulating meter readings. Just be aware that the 'usual' context store is `in-memory` - therefore not surviving e.g. any power losses.  
The `Link` mechanism is great to organize flows, much like subroutines in other programming languages - or ancient `GoTo` patterns.  
Thus I have the impression it's not an `use either/or`, but a `use both` for your use case!

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [31 December 2023 16:43 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/9 "2023-12-31T16:43:16Z")

</div>

Hi colin,

At midnight the Electricity meter counter needs to be set to 0.0.

I think i have worked it out now ... and it is simple thanks to you and mentioning using Link nodes.  
I have made it very simple.  
 ![01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/bef4cc475616d7b85126d7eb8df4997ac3f34e2d.png)

This sends the correct command to my Arduino to reset the counter.  
I still have to send data to the database, but that should be very similar and just needs to send the correct output and I know how to do that.

As you can see from the previous image, it was a bit complicated and now it's much clearer, the previous version has been successfully working for 4 years.

But now I am redoing all of my project to make it easier to maintain and eventually this should also work in Docker.

Thanks Colin for helping me to think differently to achieve a better outcome.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [31 December 2023 16:45 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/10 "2023-12-31T16:45:33Z")

</div>

Yes I agree and now I am using Links for almost everything, much easier when you click on it and it takes you to it's Link on another flow or flows. 🙂

---

<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:** [29 February 2024 16:46 UTC](https://discourse.nodered.org/t/receive-a-reading-then-set-a-flag-to-be-read-in-another-totally-separate-flow-help-needed/84135/11 "2024-02-29T16:46:14Z")

</div>

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