Of course, your macro could do other things besides shutting down your Mac.
As you may know, if your UPS has a USB output, you can connect it to your Mac and use the “UPS Options…” section of “Energy Saver” in System Settings to set when the Mac should shut down.