You can accomplish this by using one of the ATO inputs.
Simply use a regular wall wart power supply, with output of less than 5VDC connected to the wall and bypassing the UPS.
When blackout occurs, you have this power supply going down and RA still running on the UPS.
Then all you have to do is keep monitoring that input. In case you see 0VDC on that input, you know there was a power outage and then react within the code to disable the ports you want.
Was this explanation clear enough?
Roberto.