How to detect change in a flow or global variable


#1

Is it possible for a custom node to react immediately to a change in a flow/global variable? Is there an event emitted when a function node executes something like global.set("global","value") or when a change node modifies a variable?


#2

If you want notification when something like that changes you may be better off using MQTT rather than global variables.


#3

... or also wire an output from the function node to the custom node. If it's on a different tab use a pair of link nodes. That is what the wires are for.


#4

No, there is no event that is triggered when a variable changes. Also, just because a function node rewrites a variable doesn't mean that it has changed! So this partly depends on what you are trying to achieve.

Generally, if I want to check if something has been updated (not necessarily changed), I will add a timestamp when it is written. Then I can check the timestamp - but that still means that I have to read it again.

MQTT would work but doesn't really help unless you make sure that you don't update the data unless it has actually changed. If you do that, then MQTT is the best approach.


#5

@TotallyInformation, I would settle for rewrite, changed or not.

@Colin and @dceejay, yes of course, I'm using both mqtt and ordinary message passing, but I have a rather special (peculiar?) situation where a large of number of nodes might need to be aware of a change in a variable, and it gets to be messy to wire up dozens of link or mqtt nodes. If the answer is that no such event is available, I can live with that.


#6

well you can have one link out node and loads of link in nodes connected to it to help keep the mess under control


#7

Or one publisher and loads of subscribers :slightly_smiling_face:. Got it.