How can I tell if my computer is on?
As you have the iMac on a UPS, you could use the power consumption readout that is usually available on a UPS. I.e. if the power draw is above a few watts, the computer is on - if it's not, the computer is off.

Another option is simply to connect a cabled, USB mouse/keyboard instead of the Bluetooth. As having a malfunctioning UPS at the exact same time your mouse runs out of battery, whilst also being the exact same time your keyboard runs out of battery, is quite rare. Therefore it shouldn't be a problem to spend a little extra time plugging it in USB.

A third option is using a cabled network or WiFi connection to check if the Mac is powered on. You could do that by for example pinging the Mac from another computer, smartphone or tablet. If it responds to pings, it is powered up - otherwise it is powered down. Obviously the computer needs to be connected to the same network in advance for this to work.

A fourth option is to use another computer or specialized hardware to check for Bluetooth/WiFi signals being emitted from the computer. This only happens when the Mac is powered.

A fifth option is to use temperature-sensing equipment (depending on your scenario, it could be your hands) - to sense/feel if the iMac is warmer than room temperature or not. If it is warm, it is powered (or was recently powered).

And finally, if your Bluetooth keyboard is actually an Apple keyboard, then you can press the caps-lock key to detect if the keyboard battery is dead. If the keyboard is not dead, then you can use it to check if the iMac is powered on. If the keyboard battery is dead, you can recharge it.