How to handle variables at node-RED

I’m just started for a couple of days with HA, migrating from a Homey.
In Homey I could easely use vars (Boolean, number and string) to pass true different flows.
For Example:

I’m using a Remotec Multi button.
When one button is pushed I like to set a boolean which can used in an other flow.
Boolean: Sleeping.
If Sleeping is false keep the light on until boolean sleeping is set to true.
From then on switch on light for a small period on a PIR activation.

Is that a difficult task in node-RED?

In node red is called context, you have node, flow or global. For what you want you need either flow or global. The context can be declared with change or function nodes and can be retrieved in multiple nodes. The left sidebar has a tab named context where you can see all of them as they are being defined.

If you need more information on how to use context you can refer to nodered docs

https://nodered.org/docs/user-guide/context

1 Like

Thank you very much.
I start to understand it.
I did check the URL you mentioned.

Is it possible to give a simple example for me in node-RED?
example:
Que1: If a switch is pushed make a global boolean “sleep” true and store it at a file.
Que2: If boolean “sleep” changed to true, switch off light

Thanks for the help.

By default nodered stores context in memory, this behaviour can be changed in settings.js, so context survives the software restarts or system reboots. Check the docs for that.

[{"id":"423cc4ff.dbf75c","type":"server-state-changed","z":"5db76bc2.b15b94","name":"","server":"d5ce5cec.92bc8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.useless_switch","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":900,"y":420,"wires":[["c5cf4235.6086d","892510e2.52bc1"]]},{"id":"c5cf4235.6086d","type":"change","z":"5db76bc2.b15b94","name":"","rules":[{"t":"set","p":"useless_switch_2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":460,"wires":[[]]},{"id":"892510e2.52bc1","type":"function","z":"5db76bc2.b15b94","name":"","func":"flow.set('useless_switch_1',msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":1180,"y":400,"wires":[["40ba1f59.74ee3"]]},{"id":"e20c5fe2.451ff","type":"status","z":"5db76bc2.b15b94","name":"","scope":["40ba1f59.74ee3"],"x":800,"y":560,"wires":[["f3c0fede.94b3b"]]},{"id":"40ba1f59.74ee3","type":"function","z":"5db76bc2.b15b94","name":"status","func":"node.status({text:\"Just text status\"});\nreturn msg;","outputs":1,"noerr":0,"x":1310,"y":400,"wires":[[]]},{"id":"f3c0fede.94b3b","type":"debug","z":"5db76bc2.b15b94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":970,"y":560,"wires":[]},{"id":"d5ce5cec.92bc8","type":"server","z":"","name":"Home Assistant","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

If you refer to a variable in node-red triggering to start a flow on change that’s not possible. That’s why the homeassistant nodes are for, but something similar can be achieved with status (node.status in function). Check also the example above, if you want to reach another tab then use link-in link-out nodes or same status node.

Thank you very much helping.
I’m new on HA, so I don’t know how to use your advice:
How to read/use : this line?
Is there somewhere a tutorial how to read this line?

[{"id":"423cc4ff.dbf75c","type":"server-state-changed","z":"5db76bc2.b15b94","name":"","server":"d5ce5cec.92bc8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.useless_switch","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":900,"y":420,"wires":[["c5cf4235.6086d","892510e2.52bc1"]]},{"id":"c5cf4235.6086d","type":"change","z":"5db76bc2.b15b94","name":"","rules":[{"t":"set","p":"useless_switch_2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":460,"wires":[[]]},{"id":"892510e2.52bc1","type":"function","z":"5db76bc2.b15b94","name":"","func":"flow.set('useless_switch_1',msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":1180,"y":400,"wires":[["40ba1f59.74ee3"]]},{"id":"e20c5fe2.451ff","type":"status","z":"5db76bc2.b15b94","name":"","scope":["40ba1f59.74ee3"],"x":800,"y":560,"wires":[["f3c0fede.94b3b"]]},{"id":"40ba1f59.74ee3","type":"function","z":"5db76bc2.b15b94","name":"status","func":"node.status({text:\"Just text status\"});\nreturn msg;","outputs":1,"noerr":0,"x":1310,"y":400,"wires":[[]]},{"id":"f3c0fede.94b3b","type":"debug","z":"5db76bc2.b15b94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":970,"y":560,"wires":[]},{"id":"d5ce5cec.92bc8","type":"server","z":"","name":"Home Assistant","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

You need to import it to nodered https://nodered.org/docs/user-guide/editor/workspace/import-export

Thanks.
Wow thats handy :grinning:

I do did get it working.
Thanks for the help