Get energy consumption over 120s from pulse meter

Hi,
I want to estimate the actual CoP of my heatpump. With ESPHome (Arduino) I measure the average difference between in/out temperature over 120 seconds and count the pulses from my kWh meter. But how do I get the sum of these pulses over the same period of 120 seconds?
Is there anyone out there how can provide me some yaml coding or hints for this?
Regards,
Harry