This should be a standard feature of BIOS, and handled easily by apcupsd.
You are looking in BIOS for power-auto-return, power-return, OR after-power-loss. This can be enabled, disabled, or (for more recent BIOS) last-state. The 'last-state' option means: did you manually leave the machine on OR off, using the power switch.
I have used an APC UPS, with apcupsd and USB connection, to do precisely what you are trying to do.
The UPS givith and the UPS taketh away. (but in reverse):
When the UPS is low on battery, it halts power to the machine. When it again has mains-power, it returns power to the machine. From the machines viewpoint, the power was removed and restored, BUT outside its control. It should just follow the BIOS setting for: 'after power loss".