DANGER - HIGH VOLTAGE UNTESTED
This is a simple circuit which allows a micro controller or Raspberry Pi to monitor a 230V AC signal. The 230V power from the mains is applied to the upper terminal. On the lower terminal one has to provide the supply voltage and ground reference. The circuit will output a clock-like signal, which is high by default, but goes low every time the 230V AC goes high. So when your Raspberry Pi or micro-controller sees a low signal, you know the 230V AC line is powered. On the other hand, when the signal remains high for a period of say 100ms, you can safely assume the 230V AC line is switched off.
The circuit will most likely not work for 120V AC by default, because the resistors R1-R5 will be too big and thus the current through the optocoupler too low. But you could use 4.7k resistors (also at least 0.25W). Keep R6 as 10k Ohms, as it is mostly unrelated to the AC input voltage.
The diode should be a 1N4004 or better (that is for example a 1N4007). I exclusively used 0.25W-rated 10k resistors, because they are commonly available, cheap, and in case you need to buy them, you only have to buy one kind of resistor and not several different.
The terminals are 2-pole RM 5mm and 3-pole RM 3.5mm. I use these ones: http://www.pollin.de/shop/dt/MzQxOTQ1OTk-/Bauelemente_Bauteile/Mechanische_Bauelemente/Steckverbinder_Klemmen/Leiterplatten_Anschlussklemme_XY301V.html http://www.pollin.de/shop/dt/NDQ4ODQ1OTk-/Bauelemente_Bauteile/Mechanische_Bauelemente/Steckverbinder_Klemmen/Leiterplatten_Anschlussklemme_XY350.html But it should be easy to fit the PCB to any connector/terminal, also you could just solder some wires directly to the PCB without terminal.
I marked the project as "IN PROGRESS" as I hadn't had a chance to test this version. The previous version -which is quite similar to this one- works like a charm though. So I guess that this one also works.