I created this kWh sensor with the TCRT5000 IR Barrier Line Track Sensor.
My powermeter is a ferarrismeter with 375 rotations per kWh.
I also had the problem with spikes in the power usage. But after long...too long investigation I solved the problem.
At my config it was a double issue.
The problem is the pulse width of the rotation.
The pulse are at night ( low power) much wider that during the day when more power is consumed. At night the spikes in power usage where huge.
Switching on/off the halogen light causes spikes and related to also strange power measurement.
I added a second arduino mini pro as a pulse regulator between the TCRT5000 and the power meter arduino.
this arduino triggers on Rising and will always give a 100ms puls. Als debounce is handled (spikes).
I don't upload the sketch here, I'm a beginning programmer on arduino. It's made on " trail and error" but it functions as it supposed to do.
If someone wants a copy feel free to contact mee