[SOLVED] How to calculate average per day value for series of last year?

Hello,

sorry, but I’m a bit stuck in getting the following implemented in a rule: I have a smart meter in my house of which I every day get the state at midnight and store it in a number item (so if I use 20kWh per day, then it’s for 5 days 20, 40, 60, 80, 100). With lastState and state I manage to calculate the daily delta of my energy consumption.

Yet, I would like to calculate the per day average over the last year but there I am stuck. Is there a way, to get the last 365 values of my daily delta item? These I would sum up then and divide by 365. But I have no idea, how to get those 365 values and sum them up in a variable.

If anybody could help, that would be very nice and thanks for any hint in advance.

ERROR MISSING INFORMATION DETECTED

Sorry for fooling around :sweat_smile:

But for real, how do you store your data? MySQL, InfluxDB yada yada.
Do you want to make this calculation multiple times a Day/Week/Year?

I would simply create a small Python3 script which gets the data calculates what I want, send it via. REST API to openHAB to a new “Yearly Energy Average item” which would be persisted again.

Or when using InfluxDB and Grafana just create a graph with what you want :slight_smile:

1 Like

You for got the “You must be lost” tag. :smiley:

This is a help forum for OpenHAB & smart Home, not general programming tips & tricks

I can see he is doing at least something with openHAB since he wrote he is stuck on a “rule” :smiley: (I hope)

Haha! Great joke! :rofl::joy::rofl:

But I figured something myself

Item.averageSince(now.minusDays(365))

which does the trick itself.

Thanks for the help!

2 Likes

EDIT:
Wait? Item.averageSince(now.minusDays(365))
Doesn’t that give you the value from 365 days ago?

What do you think the “averageSince” is trying to say?

Yep, misinterpreted that one :slight_smile:

That gives the average over the last year.
The title requested the average for EACH DAY over the past year which should yield 365 values. not 1.

1 Like

Sorry for my noobish questions.

In the context, I found this useful: https://www.element14.com/community/community/design-challenges/forget-me-not/blog/2014/08/29/ip-post-10-my-story-of-persistance-with-persistance-on-openhab