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
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.
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.
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
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
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.
Hi there,
I have the same problem here.
I am using a KNX smartmeter which gives me the current load in Watt and the total power consumption.
Like 500W and 5250 kWh total.
Now I would like to get the daily power consumption and also the daily costs.
But my rule for the daily consumption is aleady not working.
My Items:
Number EZD_Wirken_A_plus "Stom Bezug Gesamt [%.0f kWh]" (gStrom) { channel="knx:device:bridge:Elektroz_EZD_1_1_20:EZD_Wirken_A_plus" }
Number EZD_Wirkleist_P_plus "Strom Verbrauch Aktuell [%.0f W]" (gStrom) { channel="knx:device:bridge:Elektroz_EZD_1_1_20:EZD_Wirkleist_P_plus" }
Number EZD_Bezug_Heute "Stom Bezug Heute [%.2f kWh]" (gStrom)
My things:
Type number : EZD_Wirken_A_plus "Stom Bezug Gesamt kWh" [ ga="13.013:8/1/4" ]
Type number : EZD_Wirkleist_P_plus "Strom Verbrauch Aktuell" [ ga="14.056:8/1/36" ]
I tried the following rule to get the daily value for power consumption but Visual studio marks this as an error:
There is no error in the openhab.log, but the events.log shows stange values:
2020-02-02 18:48:07.965 [vent.ItemStateChangedEvent] - EZD_Wirken_A_plus changed from 5599.0 to 5600.0
2020-02-02 18:48:07.990 [vent.ItemStateChangedEvent] - EZD_Bezug_Heute changed from -5584501.0 to -5584500.0
I am using influxdb and grafana for my graphs. So I added also a persistance for the items EZD_Wirken_A_plus, EZD_Wirkleist_P_plus and EZD_Bezug_Heute
rule "Stromzaehler EZD Bezug Heute"
when
Item EZD_Wirken_A_plus received update
then
EZD_Bezug_Heute.postUpdate ((EZD_Wirken_A_plus.deltaSince(now.withTimeAtStartOfDay, "influxdb")).floatValue)
end
hm, sorry to reopen this threat but i realized that something in my solution seems to not work properly…any idea what goes wrong…
As you can see, the Energy should change to zero at midnight, but it changes 8hours later to the correct one, so it seems that it does everything in background but the item presents itself wrong with the data from the last day…it simply looks like its time shifted presenting…
Below you also see the rules…EnergyImp receives the current meter value every minute.
Thanks for checking!!!
2020-03-24 23:37:54.200 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.2025 to 1.2125
2020-03-24 23:57:44.438 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.2125 to 1.2225
2020-03-25 08:01:13.301 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.2225 to 0.37
2020-03-25 08:03:02.629 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.37 to 0.38
2020-03-25 08:06:41.699 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.38 to 0.39
2020-03-25 08:06:57.356 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.39 to 0.40
// ***************************************************************************************************
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
EnergyImpDaily.postUpdate(EnergyImpToday.state)
end
hm, why should i do a ZERO’ing? can you please explain why this should help.
…i believe/hope that if at 0:01 there comes a value and at 0:02 comes the next one, it should take that difference and any zero value is not necessary?
Hm, i was unsure if my step going forward could work, but it seems it did. rrd4j i knew is just a simple way to store your data persistently…but it seems to be a problematic choice. Switched completely to influxDB…and without changing anything…have a look/guess its solved.
2020-03-25 23:09:56.692 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.24 to 1.25
2020-03-25 23:27:10.414 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.25 to 1.26
2020-03-25 23:34:30.049 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.26 to 1.27
2020-03-25 23:41:33.085 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.27 to 1.28
2020-03-25 23:49:07.563 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.28 to 1.29
2020-03-25 23:57:44.773 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.29 to 1.30
2020-03-26 00:00:05.785 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 1.30 to 0.00
2020-03-26 00:04:47.679 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.00 to 0.01
2020-03-26 00:13:24.695 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.01 to 0.02
2020-03-26 00:29:20.236 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.02 to 0.03
2020-03-26 00:46:49.975 [vent.ItemStateChangedEvent] - EnergyImpToday changed from 0.03 to 0.04