You should be able to do this in a single automation using Trigger IDs. Trigger IDs let you do things based on what trigger activated the automation.
(3 dots on trigger item)
For triggers, you could have something like:
Trigger on sunset with -10 offset
Time trigger at 10:30pm
Trigger on motion
Trigger on no motion
Just give each trigger a unique ID.
For conditions, you could have an ‘AND’ statement that if triggered by motion AND time is between 10:30pm & 5:00am, do action. Same for no motion.
A trigger for motion should have a duration value. You can set this to 5min for the “motion ended” trigger. It will automatically reset if there is motion.
It can sometimes be helpful to do a separate automation for each action. Then you can temporarily disable the ones you don’t want, those times when your schedule changes a little.
I have some automations I wrote for “away” lighting patterns, but I leave some of them active even when I’m home. Turning a few lights on before sunset is handy, but I’ll turn them off manually. So I leave those “on” automations active and disable the associated “off” automations when I’m home.
For this part specifically, I would recommend an actual Timer helper, with Restore enabled, rather than trying to trigger on “not motion detection for 5 minutes”. You can then have motion detection events (in your desired time window) just start the timer (which will also reset the duration if it’s already running). The “turn off again” would be a timer.finished event trigger, rather than triggering on a lack of motion state specifically. One benefit there is that, even if HA goes offline for any reason, it’ll turn off the light after the timer runs out (once HA’s running again). It will also simplify the case of motion detection firing at 04:59. It’ll kick the light on, start the timer. At 5:04 the timer will run out, motion after 5am won’t have renewed the timer, and it’ll turn off. If you want motion to keep it going past 5am, you could adjust your conditional on “motion detected, is it in my time window?” to add “or is the timer already running?” … and then it’ll go until there’s no motion well into the morning.