How to calculate Soloar Consumption having only kWh data

Hi there
I am using Home Assistant to monitor in- and output of energy.
Currently, I am challenged to calculate the solar benefit. Since I get from my inverter values for current production only every 5min, it is not very accurate. Therefore, I want calculate my solar consumption using the total produced solar energy and subtract the energy out to the grid.
So I build this sensor:

   - name: "solar_energy_consumed"
     unit_of_measurement: kWh
     device_class: energy
     state: "{{ states('sensor.deye_daily_energy')|float(0) - states('sensor.logarex_daily_energy_out')|float(0) }}"

The output is as following and due to the fact that the inverter updates just every 5min and is only able to transmit in 0.1 kWh steps while the sensor to grid reports every few seconds.
image

The challenge starts, when I want to get the savings in EUR and calculate it with the current price per kWH. I have seen lots of examples using the current actual calculation in W multiplied with current price per kW and using Riemann sum integral.
But this does not work with values in kWh.

I tried to use Derivative helper to get from kWh to kW. But I also get negative values in here due to the graph above as it is also decreasing due to the sensor behaviors, reporting with different intervals.

Hope that someone in the community has an idea how to calculate cost savings in EUR when just sensors in and out report in increasing kWh values in different intervals.

Looking forward to your suggestions.
Limerick

Look at your power bill. You are charged for energy (kWh) not power (kW).

Simply multiply the energy consumed by the price per kWh.

Thanks for swift reply.
You’re right, but I don’t know how to calculate billing by using total kWh sensor. Especially, if price is changing over time.

Currently, my sensors are increasing. If I just do a solar_consumed_total_kWh * price_per_kWh and the price changes, the entire result changes.
Let’s say first period is 5 kWh for 0,2 Eur and results in 1 Eur. But if next period again with 5kWh and this time 0,4 Eur/kWh will result in 4 Eur instead of 3 Eur (1 + 2).

Is there a way to get the correct numbers?