Count how much kwh my dishwasher uses for 1 cycle

I have a sensor.energy_socket_actueel_vermogen where I can see the actual w used. the program I use for my dishwasher is always the same. so I know how long a cycle is.
Now I want to know how much energy (kWh) I use for 1 cycle. How do I do that ?

I was thinking : trigger when socket is above 4 w and then start counting for 3,5 hours. and save it . So next time it resets the value… How do I count ?