Measure the area under a line graph in grafana - same in openhab rule

Im having Power consumption data form my HeatPump given in Watts.
In grafana I can calculate How many kWh it takes in timeseries.

SELECT integral("value") /3600000 FROM "pompa_dane_suma_energii" WHERE $timeFilter
where time is now/d. (since start of the day)

This thing calculates field under a line graph.

How to do this in openhab rule?? So that I will have this kWh since start of the day in openhab?

How are you persisting your data? You can probably exploit that.

Im using influxdb.

I don’t know how to write rule with integral?

Well, let’s say you are persisting data every hour. You can sum the records since last midnight.

But I need to calculate integral, not sum.

The integral basically is a sum, at least in approximation. But given that the x-axis is time and it does not have the same meaning as the y-axis I’m not entirely certain what the integral will tell you. You’ll get fairly different different results depending on how you interpret the x-axis and convert it to a number that you can then use to calculate the area between two points using the trapeziodal rule or Simpson’s rule or what ever approach you choose.

I do notice that InfluxDB has an integral function built in which you could call out to using executeCommandLine. It might be worth a look to see how it interprets the time axis to do it’s calculation.

You said you wanted the kWh, not some particular method.

A simple approximation is to persist kW everyMinute and then sum / 60 = kWh