Optimal persistence strategy for a gas meter

hi,

what would be the best persistence service for a gas meter, so that i can see my daily gas usage, monthly or in a year?

my setup:
gas meter w. reed contact --> 1 tick every 0,01m³ --> arduino --> mqtt message --> openhab Number item counting the ticks.

thx,
stefan

1 Like

If you want to keep your actual data for a year you will want to use something other than rrd4j. That persistence has the advantage of keeping your database at a fixed size but it does so by “compressing” data as it gets older. I put “compressing” in quotes because what it actually does is throw out data. For example, month old data may go from one value a minute to one value an hour, year old data may go from one value an hour to one value a day, etc.

Do you want to access this data from outside of openHAB? That can also impact your selection as servers like MySQL are more universally supported than db4o, for example.

So, if you don’t care if you keep all of the data as it gets older I would probably go with rrd4j as you will never have to worry about your database getting too large (this is what I use). If you don’t care about accessing the data from outside of openHAB I would probably go with db4o as it is light-weight and doesn’t require setting up and configuring a separate service. If you do want access to it outside of openHAB I would go with either MySQL or InfluxDB.

thx @rlkoshak,

well, one value per day is absolutely fine. i am planning on doing the following:

i will count the ticks in a Number item “usage_now”.
a rule that triggers every day at 23:59 will then write that value to a second persisted number item “usage_day”.

so i guess 365 values for “usage_day” should fit inside a rrd4j database?

i already have rrd4j set up (for temperatures) so i just have to add “usage_now” and “usage_day” to it.
still i need to persist every minute, even if the value for “usage_day” is written only once a day?

Unfortunately yes. rrd4j does strange things if you don’t use an everyMinute strategy including failure to generate charts (they come up blank) and providing nulls when trying to use past values in your rules.

But since the DB is a fixed size I think it is a fair tradeoff to never have to worry about doing a purge sometime in the future because my DB ate my hard disk.

perfect, thanks for your help!

Figured out how to make this work.

rrd4j:today_propane.def=GAUGE,172800,0,500,86400
rrd4j:today_propane.items=Today_Propane_Used
rrd4j:today_propane.archives=MAX,0.5,1,730

Then store the vaule at 23:59.

so you can save the value shifted “one day back in time”?
how would I apply these rrd4j: commands?

Well its not shifted, it just where it should be. So if you put the following in openhab.cfg:

rrd4j:today_propane.def=GAUGE,172800,0,500,86400 
rrd4j:today_propane.items=Today_Propane_Used
rrd4j:today_propane.archives=MAX,0.5,1,730

And then make sure you have that item or group (for me its group Totals that has Today_Propane_Used item) in rrd4j.persist:

Strategies {
	everyMinute : "0 * * * * ?"
	everyNight : "0 59 23 * * ?"
}

Items {
	Temperature*,Humidity*,Weather*,Water*,Buy*,Inverter*,Charge_Controller*
,Shunt*,HVAC*,CT_Sensor*,Creek_Level,Battery_Charge,Battery_Voltage,TankUtility_
Tank : strategy = everyMinute, restoreOnStartup
	Totals* : strategy = everyNight, restoreOnStartup
}