Some guidance

Hi All,

I currently tally up my energy usage and report it to an item. I’d like to somehow have my daily culumative energy usage so that I can graph this for the week and determine which days Im using more or less energy.

Im a little confused on how to do this.

What I do right now is create a group called gPowerUsage that is tied to the Kw_hr channel of each item. I then reset that value by resetting the individual meters each day at mid night.

Does anyone have a suggestion on how to do this or graph gPowerUsage at midnight before the reset ?


Before you reset the states at midnight, call gPowerUsage.persist. This will add one came per day to the db, presuming you are not already saving it with a policy.

Thanks Rich. Not sure I understand what you mean


logInfo("Power Usage Recorded", "Daily Usage Written to DB + gPowerUsage.persist")

Every Item, including Group Items, have a number of persstence methods available. Most of them are to get access to historical data like previous state or sumSince. But there is also a persist meeting that will save the current state too the database. This let’s you save states to persistence based on rules instead of policy.

Hi Rich understand, What I cant find is how to do that in a rule.

is it sendCommand(gPowerUsage.persist) ?

Just gPowerUsage.persist()


Perfecto, I couldnt find this :frowning:

What do you use for graphing?
An other alternative would be to use a group-by(day) and then show the max.

I use grafana. Ill configure this tonight and see what it does.

Hi Rich, if i use this in the rule, do I still need to have gPowerUsage in my influx.persistance file?

Essentially, i just want to graph the total amnount of power usage for the day, at mid night. i will do this in my rule like so:

rule "Reset Power Usage to 0 at Midnight"
        Time cron "0 0 0 ? * * *"
        logInfo("Power Usage", "Power Usage being Reset for the next Day")

I have the command as you’ve suggested. then I will create a weekly graph, which graphs all the daily persisted gPowerUsage’s. Not sure how Ill do the this component yet.

No. The Rule will handle all the persistence for the Group so you do not need to define a policy for this Group.

Keep an eye on the values you get persisted. I don’t think there will be any problem but you have stuff going on in parallel here (persisting the value and resetting the state). I could see situations where these two commands might get processed out of order. If you start seeing zeros in the database then you might need to add a small sleep between the persist and the reset.

If you have more than one persistence and/or InfluxDB is not your default, you may need to tell OH which persistence to use.


Beyond that the Rule looks good and like it should work.

Depending on what you use for your display you can use the built in charting or Grafana to actually generate the charts.

I use Grafana but I don’t reset the total until the end of my billing month (in green) and I also track the day’s Kw usage (in orange). It’s probably not the best idea to mix x axis scales like this but it works for me.

Thanks Rich

I too use grafana. I didnt realise you could do this with the graph, what you have displayed is exactly what I’m looking for.
Do you do this with two Usage items?

Yes. The real work is actually handled by the sensor itself. It has a a Channel for instantaneous (well usage over a short period of time) usage in watts (orange line) and a channel that accumulates the usage in KwH until you issue a command to the device to reset the meter (green line). I have a Rule that triggers at the end of my power billing period to send that reset command.

1 Like