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 ?
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.
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!
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.
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.