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

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

Any help would be appreciated , thanks

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.

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

1 Like

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.

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

Thanks Colin, I will do both of those :+1:

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

Do what exactly?

Don't try to prevent using any programming pattern - but try to use what fits best to your demands:
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!

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

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.

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. :slightly_smiling_face:

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