I need to detect the zero cross of AC main (220V - 50Hz) with an ESP32 to make a phase shift control of a resistive load. Searching the web I found this circuit but I have some doubts on how to dimensions the resistor values properly.
Can you please tell me if my reasoning is right or wrong?

In order to calculate the values of R1 and R2 I made this calculations:
\[ V_{peak}=220*\sqrt{2} \simeq 312V \\ I_f=\frac{312V}{220 k\Omega} = 1,41 mA \\ P_{R} = V_{peak}*I_f = 312V * 1,41 mA \simeq 440 mW \]
I want to limit the forward current to the diode in the bridge rectifier and also the power dissipation through the input resistors (R1 and R2).
With the same approach R3 should limit the current into the anode of the photodiode inside the H11L1:
\[ I_F^{max} = 30mA \\ R_3 = \frac{V_{peak}}{10mA} = \frac{312V}{10mA} = 31,2\Omega \simeq 33\Omega \\ P_{R_3} = 312 * 10mA = 3,120 W \]
This is the first doubt that I have: Shouldn't the current be limited to 1.41mA because of R1 and R2?
I'm asking this because 3W of power is huge for a single resistor.
If you wondering why I'm using H11L1 instead a common optocoupler (e.g 4N35), thats because I need a "clean" square wave output to use ESP32 interrupt on raising edge. ESP32 is too fast for the AC frequency and if you use a 4N35 you'll get a lot of false positive triggering. Arduino, that is much slower than ESP32, doesn't have that issue.
Lets move to the phase control circuit to dim a 220V heater:

R5 is 1K because the \[ I_{TSM}^{max} \] of the Triac in the MOC3021 is 1A, with \[ R_5=1K\Omega \to I_{TSM} = \frac{312V}{1K\Omega} = 312 mA \]
Do I also have to limit the current that flows into the BT139's gate? If not why?
Can you please tell me if my reasoning is right or wrong?

In order to calculate the values of R1 and R2 I made this calculations:
\[ V_{peak}=220*\sqrt{2} \simeq 312V \\ I_f=\frac{312V}{220 k\Omega} = 1,41 mA \\ P_{R} = V_{peak}*I_f = 312V * 1,41 mA \simeq 440 mW \]
I want to limit the forward current to the diode in the bridge rectifier and also the power dissipation through the input resistors (R1 and R2).
With the same approach R3 should limit the current into the anode of the photodiode inside the H11L1:
\[ I_F^{max} = 30mA \\ R_3 = \frac{V_{peak}}{10mA} = \frac{312V}{10mA} = 31,2\Omega \simeq 33\Omega \\ P_{R_3} = 312 * 10mA = 3,120 W \]
This is the first doubt that I have: Shouldn't the current be limited to 1.41mA because of R1 and R2?
I'm asking this because 3W of power is huge for a single resistor.
If you wondering why I'm using H11L1 instead a common optocoupler (e.g 4N35), thats because I need a "clean" square wave output to use ESP32 interrupt on raising edge. ESP32 is too fast for the AC frequency and if you use a 4N35 you'll get a lot of false positive triggering. Arduino, that is much slower than ESP32, doesn't have that issue.
Lets move to the phase control circuit to dim a 220V heater:

R5 is 1K because the \[ I_{TSM}^{max} \] of the Triac in the MOC3021 is 1A, with \[ R_5=1K\Omega \to I_{TSM} = \frac{312V}{1K\Omega} = 312 mA \]
Do I also have to limit the current that flows into the BT139's gate? If not why?