I have had a need for a similar circuit for quite some time, but priorities are such that I don't even have time to do it. What I can do, is tell you how I interfaced a piece of audio equipment many years ago. I used a VTL5C1 FET opto isolator which is a leaded version of some DIP varieties. The FET contacts go across the button and I used an LM334 current source set to 10 mA. I also used a diode. Now my control signal can be anything from 3 to 32 volts.
I also had to detect whether the unit was on. I just paralleled the LED portion of an optoisolator with a resistor. I lost some brightness, but it worked. Nor I had an open collector signal to detect ON.
I used timer chips that are obsolete now to generate what I needed.
What I would like now could be massaged into what you want, but I don't have the time to do a microcontroller based solution.
It would also be best to know the state of power to the computer. e.g. is the computer on. Some amount of time of stable power should exist before you attempt to turn on the laptop.
It may be possible to use modules such as these, about $50 USD **broken link removed** to help accomplish what you need to do. e.g. Once power has returned, start a timer for say 30 sec. If that timer times out and the computer is OFF, then pulse opto.
Detecting if the computer is on can be done by detecting voltage present on the floppy connector. A simple 12V relay with supression diodes would be all that's needed.
The computer shutdown I would still do via a UPS that is interfaceable to the computer.
This company
**broken link removed** looks promising for a processor based solution that might be easy.
It would not be my choice for what I want to do though. You have a UPS, I don't.
This (IDEC smart relay)
https://www.idec.com/language/english/manual/FL1AManual.pdf may also be a possible starting point.
There are always the questions of time, money, reliability, availability, # of units and whether a development system is required.
You can play with the CPUSTIC BASIC for free on your computer and you can play with the IDEC program and simulator free as well.
What makes it tough is dealing with power on/power off events, but with a few signals, you should be good to go.
1. Is computer on? Relay on 12V disk drive connector with supression diode.
2. Interface to power button - I showed how to do that.
3. Is AC power available. You can use a mains powered relay to do this.
You have a UPS to keep the controller on.
You need one other piece of info and that is, you need to have some idea as to when the UPS will quit delivering power. A comparitor on the battery voltage may work powered by the UPS battery itself. This is where the USB based shutdown would be advantageous.
The IDEC programming language (ICON based) looks easy.