Perhaps you have a misconception on what node-red does and how to use it.
Yes you can use programming (JS) in functions for more customized control, this should not be needed for your example (unless we are missing some information).
Node-red in a nutshell to me: a message has a lifecycle, comes in at point A and goes to point B or any other direction (to the right), no loops.
You connect nodes together to make this work. Need input from other nodes accross flows ? Use link nodes. Personally, I consider variables a last resort, function nodes as well.
Your PIR example is simple if you use the principle above.
My house is full with PIR's and triggers together with all kinds of conditions in between them. No function nodes needed.