Sum energy values stored in influxdb

Hi Guys,
i need your help please.
I have this nice little setup so far:

Via OH i write my actual used Watt of my dryer and washingmachine into an influxdb and produce a little nice graph with grafana.

So far, so good.

But what i want to have as final result is:

  1. the summarized energy of each machine per month
  2. the summarized energy of the actual year and last year

I tried to display this in grafana in a table diagram but have failed so far. So i thought about if OH can help me and select the data directly from my influxdb, but i have no idea so far how.

So i need a good idea if grafana or OH would do the job and how.


InfluxDB offers a function for that:

I did something similar once but am having problems now. Maybe you have more luck :wink:

Hi Thom,
thanks for the quick reply.
Ok let me get this correct. influxdb can sum it up and i can then query this value in OH in a widget or so?
I not getting the complete picture yet.
Can you give me a bit more details if possible? Maybe your broken code and how i would then display the calculated value in OH.


Please be aware, that summing up is not what you are actually looking for, you want to calculate the Integral. :cloud_with_lightning:
Anyhow. Yes, InfluxDB can integrate over a measurement series. The query can be called from Grafana, from command line or via REST Api call. So you can either generate a graph in Grafana or retrieve values through the REST API from within an openHAB rule (or via the HTTP binding).

I did never implement the latter but would be interested in a solution and would happily add it to the InfluxDB+Grafana tutorial. Kepp us posted! @rlkoshak might have additional experience in this area.

Edit: Just found the issue on my side: INTEGRAL was introduced in InfluxDB 1.3

A long time ago I remember helping @sipvoip with some rules to calculate running totals of power usage (i.e. last day, last week, last month) but in that case, I’m pretty certain that he was getting kWh so didn’t need to do the integral himself.

Maybe he remembers and can find the thread and/or can post his code.

That being said, I would look into Grafana and InfluxDB as a way to do this. InfluxDB has a REST API so it isn’t too hard to implement queries in rules.

Thank you all for your Feedback. I will see how far i can figure it out and will post my results for sure.


Guys, i did a few tries in Grafana for Month 08 and 09, both contain a lot of values. But i still have it not right :-/
See below:

Without the group by the Time is getting weird :frowning:

@ThomDietrich does a query like this calculate the Power?

InfluxDB has Integral but grafana somehow only let us use the default value 1s.
So i just integrate the value for 1s and cumulative_sum them after that devide it by 3600 to get hours.
The time interval has also to be set to 1s.

In the math field also the price calculation could be added.
Unfortunatly the starting point of the sumation is always the left border.

Or maybe an implementation with continues queries?


Anyone been able to get this to work on the singlestat widget? I’ve got it working on a graph like you demonstrated Josar, but I’d like a singlestat widget just to show the totals for the day so far. For a 24 hour period, yes, but if you wan’t ‘Today so far’, it’s not working it out correctly.