How to caluclate grid load over time from modbus sensor?

I have a solaredge sensor (solaredge_modbus_meter_1) that shows production (positive) or grid load (negative) energy over time.

Now I would like to create a function that gives me the read grid load (the values < 0) in kWh over a certain period of time (like from the last 15mins).

Question:
a) how can I get the sensors value(s) in W just based on timestamps (or let’s say: all values between a certain time range)?
b) how could I transform those values from W into kWh?

I mean, the modbus sensor is saving the current power W every other second. So for each measured point on the timeline, I would have to take the spot W, and with the known difference from one point in time to the next, I could then calculate the kWh?

Where could I find some help to this?