There is no kWh-reading from your smart meter available? that would be the goto-version. Converting kW/interval is prone for errors like if you miss a beat or similar you won’t get the exact kWh out of it. If you’ve really only got kW-readings, you can go the linked route.
That’s one issue, if you only have kW delivered. You can either assume there’s a strict 5second interval and just use the delta between two item states and hope for the best.
or you can read out the timestamps like this and still hope for the
or this: