Instead of use counter for S0 pulses counting, Smart Meter feature is much better…
https://tasmota.github.io/docs/Smart-Meter-Interface/


Here is complete script with pulses calculation examples:
>
D
>B
->sensor53 r
>M 1
+1,4,c,1,-20,S0
1,1-0:1.8.0*255(@1000,Energy,KWh,Energy,3) 1,1-0:1.7.0*255(@0.01667,Power,W,Power,0)
#
1kWh / 1000p/kWh = 1Wh/p => 1/60 = 0.01667
1kWh / 800p/kWh = 1.25Wh/p => 1/75 = 0.01334
1kWh / 250p/kWh = 4Wh/p => 1/240 = 0.00417


No other configuration is necessary…
