Energy monitoring / Openhab 1.8 Chart

Hi,

I’m monitoring my electricity and gas meters with ESP01 hardware and they give me every minute (through MQTT) the delta value of the previous measurement.
In case of power every minute (example) : 12, 13, 14, 15,12 etc etc.
I tried to configure the RRD4J function in openhab.cfg to customize the chart function but cannot find the proper settings.
Is there someone who successfully made energy monitoring graphs in openhab and is willing to share them ?

-ben

I’m not sure about the question. Is your problem to get/generate the correct values or ist the problem to define a chart.

Thomas

Hi,

Maybe I was not clear:

I use the ‘standard’ charts to make nice diagrams but I want to use historical data ( using persistence ) to calculate power consumption over time:
rule "Power"
when
Item powerCounter received update
then
var Number tmp
tmp = powerCounter.sumSince(now().minusHours(1), “rrd4j”)
power1Hr.postUpdate(tmp.toString)
tmp = powerCounter.sumSince(now().minusHours(4), “rrd4j”)
power4Hrs.postUpdate(tmp.toString)
tmp = powerCounter.sumSince(now().minusDays(1), “rrd4j”)
power24Hrs.postUpdate(tmp.toString)
tmp = powerCounter.sumSince(now().minusDays(7), “rrd4j”)
power1Wk.postUpdate(tmp.toString)
end
Every minute a delta value is stored and fed into rrd4j (var powerCounter) and from there I do some math.
All works fine except that the day and week calculation are wrong, this has to do with the fact that not all data is stored with high resolution (hence the round robin database) but how is it stored ?
Therefore I tried to change the resolution in the archives section og the rrd4j part of openhab.cfg:
########################### RRD4J Persistence Service #################################
#
# please note that currently the first archive in each RRD defines the consolidation
# function (e.g. AVERAGE) used by OpenHAB, thus only one consolidation function is
# fully supported
#
# default_numeric and default_other are internally defined defnames and are used as
# defaults when no other defname applies

#rrd4j:<defname>.def=[ABSOLUTE|COUNTER|DERIVE|GAUGE],<heartbeat>,[<min>|U],[<max>|U],<step>
#rrd4j:<defname>.archives=[AVERAGE|MIN|MAX|LAST|FIRST|TOTAL],<xff>,<steps>,<rows>
#rrd4j:<defname>.items=<list of items for this defname> 

rrd4j:energy.def=GAUGE,120,0,U,60        
rrd4j:energy.archives=AVERAGE,0.5,60,525600
#rrd4j:energy.archives=AVERAGE,0.5,3600,8760
rrd4j:energy.items=powerCounter 

Above setting should store with high resolution for 1 year (525600 minutes) but cannot get this to work, also I can not get the charts to work when using the ‘new’ settings.

Hope this clarifies my problem.

-ben

I’m not expert on rrd4j but by design as the data gets older rrd4j throws out some values and replaces them with their average. I’m not sure that just changing the archives to what you changed them to will change that behavior. My recommendation would be to spend a good deal of time studying on rrd4j and how it works to figure out the best way to force it to not throw out any data until it is a year old or switch to using a database that will preserve your exact values as saved forever without throwing out data points as they age.

Also, I do know that warning to save data every minute for rrd4j charts has to do with the default settings. When you change the settings like this I’m not sure how often you have to save the data for charts to work.

1 Like

In my opinion you should not use rrd4j, but mysql or a similar db. rrd4j throws out older values to keep the db size stable and as far as i remember the time intervalls to store values are not flexible.

Thomas

1 Like

There was an update in 1.7.1 that lets you configure the time intervals. But I completely agree with the rest. If you want accurate data for anything older than a week or so rrd4j is not a good choice.

1 Like

Point taken, I’ll switch to something different, what would you recommend ?

-ben

I use the MySQL persistence service and I can recommend it. But beware if you are using a server that stores to an SD card (like a Raspberry Pi, for example), because running a database on it will surely burn it out quickly.

It depends on what your full use case is. I actually use a combination of persistence engines. I use Mapdb for restoreOnStartup and for a things that I want the historic data from in my rules I use rrd4j. My rules pretty much only care about the last change or the last few minutes so rrd4j’s habbit of throwing out older data isn’t a problem. That is all I have right now as I don’t really do any deep data analysis or charting where I care about accurate data from long ago.

But when/if I do I will probably either use MySQL because it is a pretty standard DB with tons of third party tools and lots of people on this forum (including myself) have experience with it. However, I’m also intrigued by InfluxDB which seems to be a DB designed to handle the sort of data OH produces (i.e. time series data).

I am doing this sort of thing and would agree that RRD is not the tool of choice if you are looking for accurate, long duration time-series interval storage and retreival. I would second the suggestion to use MySql. It is very well supported and will give you the possibility to do queries with functions that will easily tell you the consumption for a particular period.

Just something for you to consider however. When you use power measurements to come up with “total” energy measurements, you REALLY need to be sure that you have all the data points, otherwise your energy calculations can quickly become inaccurate. So, you may consider storing the energy as well as the demand (each has a particular use)- when I say energy, I am thinking of cumulative energy consumption, like an electric meter index.

If you are storing indexes/consumptions, it is quite easy to calculate totals like weekly and monthly as you just need to subtract the ending value from the starting value. Even if you had a database outage in the middle of the month, you’d still get the correct consumption (as long as OpenHAB kept track of the energy value).

On to openHAB… have an item for power and one for energy (Wh) and have a rule which increments the energy consumption when an update is triggered on your power Item. Now, this Item would be very important to persist and use the restoreOnStartup however, so that OpenHab would pickup from where it left off when it restarts (you could also read the last value from the MySql database for nice consistency).

Thanks to everyone who replied!

For longtime measurements I moved to MySQL, works like a charm !
My energy data is fed into this by OPENHAB every minute, from here I do the magic math to calculate power consumption by hour/day/etc . I do NOT rely on totalize functions by OPENHAB (restore issues) but totalize the data from MySQL database since it has all the information in it.

    tmp = powerCounter.sumSince(now().minusHours(1), "mysql")
    power1Hr.postUpdate(tmp.toString)
    tmp = powerCounter.sumSince(now().minusHours(4), "mysql")
    power4Hrs.postUpdate(tmp.toString)
    tmp = powerCounter.sumSince(now().minusDays(1), "mysql")
    power24Hrs.postUpdate(tmp.toString)
    tmp = powerCounter.sumSince(now().minusDays(7), "mysql")
    power1Wk.postUpdate(tmp.toString)

Now I need to add all other enerdy sensors like gas and water.
Thanks for all your help/suggestions.

-ben