Automated Bedroom Light Control with Node-RED

I would like to build a Node-RED flow that does the following: At exactly 10:00 PM, it should turn off the bedroom light if it's on. If I turn on the light, a timer will check how much time has passed since I turned on the light, and once 15 minutes have passed, it should turn off the light again. However, if I turn on the light again within that timeframe, the timer should be set to 30 minutes. If I turn on the light for a third time and it's still before midnight, the timer should be extended until midnight. Once midnight passes, the timer should go back to 15 minutes. This setting should be active from 10:00 PM until 7:30 AM the next day. How can I achieve this?

You need to provide a bit more information as to how the bedroom light is controlled and what platform you are using.

Are we talking about a Raspberry Pi or some other platform?
Is the bedroom light controlled from a relay (via an output pin on the Pi)?
Are we talking about switches on the wall to control the light?
Is the bedroom light controlled by Alexa?

There are so many variations to consider before we can offer a suggestion to you.

I am using the Home Assistant Supervisor system on a mini PC with an Intel Celeron processor to control the bedroom lights using various devices.
These devices include push button switches with Tasmota firmware interfaced to Node-RED using an MQTT broker, a Philips Hue dimmer with Zigbee2MQTT protocol, and a Google device. Typically, when the automated flow begins to turn off the lights, I use voice control to turn them back on.
However, I have encountered an issue with the state node not accepting arguments and only accepting values in the for statement. I'm not sure if I've made an error, so I'm seeking help.
I'm considering creating a custom function to track how long the lights are on, but I'm unsure if this is the best solution.