Using global variables in node

I'm new to Node-RED so sorry if this is a stupid question but I really can't find an answer.

I need a flow to control light parameters based on time of day and I'd like to be able to easily change the time parameters if I need. At the moment they are like 07:00-18:00 Day, 18:00-21:00 Evening, 21:00-07:00 Night, but I'd like to be able to globally change those if I need.

So, instead of putting 07:00 everywhere where I need something to happen at the start of the day, I'd like to have a global variable for that time (e.g. DayStartTime = 07:00). I can do that by using change node and set function but I have no idea about how to use that value in time nodes or if that's even possible.

Here's an example from time switch node where I'd like to replace times with global values:

Soi the question is: is it possible to use a global variable like this and if yes, how do I do that? Or is it maybe node-dependent?

It depends on if the node author permits it in the drop down.

There are often technical reasons for not including context (e.g. if the value flow/global changed externally, the node wont be notified so cant recalculate its schedule)

It depends on if the node author permits it in the drop down.

So you need to have a "global." selection in the dropdown to be able to use context in a node?

Yes unless the node permits you sending values in.

For example, the cron+ node permits you to send a control msg to the node to add / remove / adjust your schedules times. The reason global/flow are not permitted are as I said before - the user could change the global var externally - but the node has no idea you have done that so cannot reschedule the event time.

So, probably the best way to deal with this is to set a global variable for time of day using inject nodes as triggers and then use that variable in switch nodes like this?


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