Having trouble in GPIO output, 220 V to 5 V signal
Here is using your basic idea, but a circuit that will actually work:



Note the addition of D2.  That's important to keep the LED from frying.  Yes, D1 does block current in the reverse direction, but it will also have some inevitable leakage.  The leakage current should be small (see the datasheet), but that could be enough to build up enough voltage across the LED, also in reverse then, to exceed the LED's reverse voltage spec.  D2 provides a safe shunt path for whatever leakage current there may be thru D1 during the negative half-cycle of V1.

Unlike another answer, I recommend keeping D1.  With D2 across the LED, D1 can actually leak up to being a short without harm to the LED or D2.  You could therefore leave it off.  However, it serves a useful purpose in reducing the power dissipation.  The diode drops are small compared to 220 V, so you basically have 220 V across a 200 k&Omega; resistor.  That comes out to &frac14; W.  With D1 in there, that is reduced by half, since current is only flowing during half the V1 voltage cycle.  Now you can safely use a &frac14; W resistor and still allow for some insulation, packaging, limited air flow, etc, around it.  Or you could lower R1 to get more LED current, and thereby require less current transfer ratio of the opto.

On the digital side, all you need is a pullup resistor.  But, you need to check the current capability all along the way.  The peak voltage of a 220 V sine is 311 V.  Let's say 309 V across R1 due to the voltage drop of the LED.  That results in 1.5 mA.  Of course you don't just want a short blip at the peak of the positive power cycles, so let's say anything over 1.0 mA into the LED should assert the output.

The R2 pullup resistor requires 500 &micro;A for the GPIO line to be held low.  That means this circuit would work with a opto-coupler with a CTR (current transfer ratio) of at least &frac12;.  Optos with a minimum CTR of 1 are easy to find, especially when fast response is not required, like in this case.  You therefore have a fairly comfortable margin of 2x with a 1:1 opto-coupler.  That all sounds good.