How to calculate the zero crossing offset in a capacitive transformerless power supply
The calculated angle is accidental, it is not a reliable value. To demonstrate how unreliable is it, imagine that capacitor is 1 pF. The angle will be close to zero, &lt;&lt; much less &lt;&lt; than 270.

I'd suggest to add optocoupler with high voltage diode and resistor, read zero crossing with accurate estimate of current transfer ratio of optocoupler, known part's delays, and known software delays. Though with high voltages (above 300V) the coupler should be super low current kind, say with LED requiring less than 1 mA to be detectable.