I want to use a sensor and relay as a safety device to allow/deny power to an AC mains-powered electrical unit. If the wall power is disconnected I loose the state of the relay which is stored in a variable on my Pro Mini. My Arduino is powered from an AC-DC voltage regulator that is between the AC mains and the Power On switch of the electrical unit. Apart from powering the Arduino with a battery/supercap, are there any circuit design tricks I'm missing?
I have run into a similar situation on a few occasions. Maybe my scheme will help. What I do is sense power loss early, so I can save a structure full of all my program states to EEPROM when the power is going away. Conversely, the first thing the program does on power up is restore the memory structure from EEPROM. Provided you save your relay state whenever it changes, this scheme should help you recover. You don't need a super cap. I use a circuit like this...
In this circuit, I use a diode to isolate a large (but not super) capacitor from the supply, and that circuit point also feeds my VIN (This is a NANO board). Then, that capacitor voltage is further isolated from a voltage divider, with another diode. The voltage divider brings down the 12V (only 11V after the diodes) to pretty near 5V. there's also a small (100nF) capacitor there to filter any noise.
If power is lost, that 2200uF capacitor will keep my NANO, a bunch of LEDs, an LCD display, and even a transistor driver and relay circuit(not shown) alive for nearly a second. But the voltage at the digital input (D2 in my case) will drop within milliseconds! So if you are polling that pin regularly, you'll have plenty of time to react by saving your states. If you doubt whether you can poll that fast, pin D2 can easily be tied to an interrupt. (that's overkill.. easier to just create you're owe version of millis(), so that whenever you have a timer wait, you can continually test the power detect pin, and react within a millisecond).
Now if for some reason you would like to ensure that the arduino doesn't lose power at all during short power line disturbances, you can add another diode to the 2200uF capacitor, and connect it to a battery pack. It the battery voltage is a little lower than the main supply, no current will flow out of it until its really needed.