Is there a way to trigger a macro based on the Mac being on UPS power in case of a power outage?
This might be of interest:
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.
This may seem like a longshot, but if you have a HomePod or HomePod Mini you may be able to use its built in feature to detect sirens and smoke alarm sounds to recognize the alarm from your UPS as an alarm. In that case, you will be notified on your iPhone remotely even if you are far away from home. You won't need KM to alert you.
It all depends on the sound of your UPS device and how close your HomePod is to it. You won't need to deal with USB cables this way.
Problem is my network cabinet has its own UPS system that will run the network equipment longer than the Mac will run on backup power, so the WiFi will never die before Mac does. My APC Back-UPS Pro 1500 S has USB connection, but I intend to use KM to command all Mac's on network to shutdown before power fails altogether.
In my opinion, you shouldn't be using the UPS to detect if the power is out. You should simply use a HomeKit device like a $20 power switch. If the switch goes offline, your Mac can detect that (with the right software.) To me, this is simpler.
The UPS is feeding the Mac data like time remaining, UPS battery percentage. The UPS shutdown parameters are adjustable by System Preferences, built into macOS.
I've used EventScripts to trigger a number of different KM macros. It also supports the Mac switching to UPS. Have a look here: EventScripts Events
Is it also networked and able to send alerts or run scripts when mains power fails? You could use either of those to trigger a KM macro if you don't want to use EventScripts (although that's the better option, IMO).