Converting a rate sensor into a total value

I have a power sensor that gives me kW and I want to have a running total for the day. I can’t seem to find a nice simple way to do this in hass. Any ideas?

Eseentially I think I want something that everytime the sensor reports a new value it takes the last value, multiplies it by the time since the last value and adds that to a running total for the day.