Help with motion trigger and reset

I have a light which turns on at dusk using a smart plug and turns off at a specific time of night, this flow works as expected.

I am trying to add an additional flow for the same smart plug / light to act as a night light:

  • If the light is off, and there is motion, and the ambient light in the room is less than 5 lux - turn the light on
  • After 3 minutes, if there are no more motion events - turn the light off

I am having issues with the new flow, because of the existing timer flow - the light is turning off at unintended times due to no motion in the Living area. I tried including a time range node before the trigger, but I would rather not use it as it also introduces edge cases.

Is there some way to set a global value when the light is turned on from the new flow and only turn it off if that is the case and there is no motion?

What is the correct node-red way to execute this additional flow without interfering with the existing flow?

There are many ways to accomplish this. What is the specific problem with what you have?