Using variables

Hi, I am familiar with python, and use of variables, but I just can quite get my head around how to use them in Node Red, so would greatly appreciate a working example.
This is the essence of what I am trying to achieve:

  • When the flow starts, in the first node, set a flow variable called "ToiletLight" to 1
  • In the second node, query "ToiletLight", if it == 1 then set "ToiletLight" to 2 then continue to next node
  • The value of "ToiletLight should be visible and usable to this entire flow whilst activated

Thats it, very simple, but couldn't get it working.
Kind regards.

It would be worth reading the node red documentation. Especially the sections on working with messages and context. They're short reads and should be easily digestible as you have a programming background.

At this moment, it seems you are thinking in a classic procedural programming mannor and you need to adjust to the flow based programming methods. Tip: Node red is pretty much totally event based

As a hint...
Use an inject node > change node (set a flow context variable).

Then use a change node to get value back out of flow context.

or use the change node to move the value to a msg element like msg.toiletlight then it will be part of the msg going from node to node.

1 Like

What he said ^

As I attempted to allude to in the statements "it seems you are thinking in a classic procedural programming mannor" & "Node red is pretty much totally event based" this is how we do most things in node red.

Just tack the value on to the msg then pass it to the next node(s) for processing. No variables, no storage, just event based.

1 Like

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