Theoretically trivial: Derivative Sensor.
But HA has a bug that derivative sensor only takes new values when new value is available. This is problematic when energy stays constant because then power is clearly supposed to be 0.
But since the value is not repeated until the energy entity provides a new value, the derivative sensor shows a large power value even is it’s zero.
Create a template sensor that adds a small random value to your energy sensor (+/-0.1Wh). This should average to zero in the long term. Make sure this sensor has a state_class of total not total_increasing, as it will go up and down. Take the derivative of that.