There isn't a "native" way (as far as I know) to have the client itself know to trigger at "exactly 1 second before the end of my service window, run "this", whatever "this" is". Where in your situation, that just so happens to be a reboot.
I can think of dreaming up some custom methods, but I don't know if they would be any more or less complex than what you already have.
One fevered dream (keeping in mind I have zero code on how to do this, just thinking as I type that 'maybe this is possible')...
- A powershell script to LOCALLY check the known service windows on the client. (ccm_servicewindow in root\ccm\policy\machine\actualconfig I think? )
- Compare the end date/time of the known service windows against "current date and time" (that could be cough fun to code), and if within say... 30 minutes of the end of the service window, calculate the seconds between 'now' and end of service window, and do a shutdown.exe -t <seconds as calculated> /c "some message".
The trick would be scheduling that to run, and run frequently enough to trigger... and... do you want it to only run if there is a pending reboot? or just reboot every single time the end of the service window is approaching? So who knows how much additional logic you'll need to add into that script.
In my twisted brain, I would think that once you have that logic solid (that alone would be a long testing process I would think), then you'd use whatever method you want to have it re-run frequently. Like a Baseline/CI, or a packag/program/advertisement, where it reruns every 30 min ? The problem(s) might be that if, for example, CM is currently installing something, the advert might not trigger, because CM is already busy.
Or, if there is a pending reboot... the advert might not trigger because it's waiting for the reboot to finish before the advert will run (catch-22).
Lots of potential failure points here, in logic especially, and in trying to second guess what CM the client will be doing depending upon what other tasks have just been done.