user37469: 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?

user37622: When you change the state of the relay, save it to the EEPROM. In setup() read the value from EEPROM and apply it.

user43127: 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. 

user7201: You power your device and your controller from same AC source. 
You loose that AC source and they both will go off line. 
You get your AC source back - restart controller and check the current state of your device /relay. 
What did I missed ?

37469: <p>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?</p>
 37622: <p>When you change the state of the relay, save it to the EEPROM. In setup() read the value from EEPROM and apply it.</p>
 43127: <p>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...<a href="https://i.stack.imgur.com/x5FW8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x5FW8.jpg" alt="enter image description here"></a></p>

<p>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. </p>

<p>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).</p>

<p>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. </p>
 7201: <p>You power your device and your controller from same AC source. 
You loose that AC source and they both will go off line. 
You get your AC source back - restart controller and check the current state of your device /relay. </p>

<p>What did I missed ?</p>
