Smartmeter - daily kWh - any existing solution

Hi, i’ve got a MODBUS based Smartmeter that provides the current power values and a counter of the overall kWh like any other electric meter.

What I would love to do is a graph that shows the daily kWh per day (0:00 til 24:00). My only idea without any smartness would be to run an e.g. python script that remembers the counter at midnight and does the math 24hrs later…and this on a daily basis…plus sends the delta to openhab.

Is there any smarter approach or an existing solution that could help me in my doing?
Regards , and thanks a lto Norbert

Shove the value in influxdb. And you can do it as many times as you like during the day.

From there you can graph on power by day, month whatever.

1 Like

hm - you mean to setup influxdb as my primary persistence source? right now i’m rather simple in using rrd4j…is there anything similar to do with rrd4j to not have both or even need to transit from rrd4j…

You can do this fine with rrd4j. Persist the cumulative reading.

Run a rule at 23:58 each day that fetches the persisted value from 24 hours ago, subtracts it from current reading, and generates your daily total. You’ll probably want to store that too for charting etc.

ah, that sounds very nice! means that there is a function to fetch 24hrs ago…will check in the doc.

by store too you mean that again i put this in another persisted item…so the delta is again stored…?

Well, if you want to chart it, that makes it easy to do from a collection of daily totals. Else you will have to do maths at the time of charting to work it out from the ever-increasing cumulative total.

Something like this (in German, but if you understand the rules sniplets you can make it working)?

1 Like

hm, i now was successful in taking the delta from “EnergyImp” since dayStart and save it all the time in EnergyImpToday.
So i’ve seen only the consumption of the day. 1min before midnight i want to move this count to another item “EnergyImpDaily” but now my problem starts…

I expected that after midnight EnergyImpToday should again start at 0,0kWh…but it stays forever at the count it was before midnight…and strangely it does not even continue from where it was before…
So perfect would have been if the count goes back to zero…but even if this is not happening, i would at least have expected the count to continue and go upward…but this does not happen even after half a day now…any idea what i’m doing wrong here…

// ***************************************************************************************************
rule “kWh consumption today”
when
Item EnergyImp received update
then
EnergyImpToday.postUpdate(EnergyImp.deltaSince(now.withTimeAtStartOfDay))
end

// ***************************************************************************************************
rule “LogDaily kWh”
when
Time cron “0 59 23 * * ?”
then

if (EnergyImpToday.state instanceof DecimalType) {
EnergyImpDaily.postUpdate(EnergyImpToday.state instanceof DecimalType)
}
end

// ***************************************************************************************************

If you’re seeing mysterious numbers, you may wish to tell us what they are. It might be a clue.

This all relies on EnergyImp being persisted properly, so see if that is working and check your strategies.

I have feeling that as you have chosen to use deltaSince that may not work very well with rrd4j, because if its compression.

Hi,
that was yesterday…since that …the value did not change even another day started and new energy consumption happened…

2019-06-23 08:45:54.137 [vent.ItemStateChangedEvent] - EnergyImpToday changed from NULL to 0.5
2019-06-23 10:46:10.677 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.5 to 0.6
2019-06-23 14:48:00.363 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.6 to 0.7
2019-06-23 19:10:35.460 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.7 to 0.8
2019-06-23 20:43:11.547 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.8 to 0.9
2019-06-23 22:09:02.971 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.9 to 1.0

EnergyImpDaily…seems to not update at all even after the first time the cron time happened last night…
and its value is set to NULL

Is there anything else / better to use for my scenario? (instead of deltaSince)

I had some issues with persistence functions when I tried to do something similar with a Dutch smartmeter. So I resorted to simply trigger a rule just before midnight and moving the value to a 'last state’item, and reset the value just after midnight.

I’ll lookup my rules tomorrow if you like. Time to sleep now…

There is an error in your second rule’s postUpdate, you can’t send a Number a conditional true/false test like instanceof.
Are you looking in openhab.log for errors?
Are all three Items of type Number?
Are you persisting any of them?
Is your default persistence service set? (you are relying on that)

You could always add some logging to aid analysis, you know

rule “kWh consumption today”
when
   Item EnergyImp received update
then
   logInfo("increment", "raw data " + EnergyImp.state.toString)
   var delta = EnergyImp.deltaSince(now.withTimeAtStartOfDay)
   logInfo("increment", "delta " + delta.toString)
   EnergyImpToday.postUpdate(delta)
end

rule “LogDaily kWh”
when
   Time cron “0 59 23 * * ?”
then
   logInfo("daily", "old daily " + EnergyImpDaily.state.toString)
   logInfo("daily", "today " + EnergyImpToday.state.toString)
   if (EnergyImpToday.state instanceof DecimalType) {
      EnergyImpDaily.postUpdate(EnergyImpToday.state)
   } else {
      logInfo("daily", "Unexpected Today state")
   }
end

Thanks @rossko57 for the details.

You mean it should look like (so no boolean condition inside)? I once have seen this in a different rule here in the community and just thought it would help a little…

So there is no If and a simple postUpdate (?)
EnergyImpDaily.postUpdate(EnergyImpToday.state)

In terms of errors, i have not seen any in the openhab.log but will check today what comes up at midnight.
All items are number-Type. EnergyImp, EnergyImpDaily are persisted by rrd4j…its used for other items as well so rrd4j at least works as it should.