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.

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