One way of doing this: First you need to calculate the Watt hours (or Kilowatt Hours) per time interval. As you say, the variable is updated every 5 seconds. The consumption in the given time interval is $aktuell-bezug.value * 5 / 3600
. The result of this needs to be added to a “register” variable, let’s call it hourlyUse
.
I have drafted a boiler plate you can use which consists of two Rules and a Variable to count hourlyUse
. Moreover, I have added a VariablesDevice, which is only used to display values on the device pages. That’s just the starting point, but it should be relatively simple to add more “register variables”. What might be trickier is to create the logic to reset the registers (daily, monthly, yearlier). I think one needs to use pimatic-cron for this purpose. I’ll have a look at it later.
Variable
{
"name": "hourlyUse",
"value": 0
}
Rules
{
"id": "measure-interval",
"name": "measure-Interval",
"rule": "when $aktuell-bezug.value changes then set $hourlyUse to $hourlyUse + ($aktuell-bezug.value * 5 / 3600)",
"active": true,
"logging": true
},
{
"id": "reset-hourlyuse-counter",
"name": "reset-hourlyUse-counter",
"rule": "when its 0:00 then set $hourlyUse to 0",
"active": true,
"logging": true
}
VariablesDevice
{
"variables": [
{
"name": "hourlyUse",
"expression": "$hourlyUse",
"type": "number",
"unit": "Wh"
}
],
"xAttributeOptions": [],
"id": "energy-meter",
"name": "energy-meter",
"class": "VariablesDevice"
}
EDIT: Here is little of explanation about the calculation and theory behind. The accuracy of the simple set-point accumulation should be accurate enough if the current consumption does not fluctuate a lot faster than the measurement interval (see Nyquist-Shannon Sampling Theorem). Given the short interval you have, it should be fine for typical household appliances. For a PV generator, however, this may be different. As PV generation is fluctuating all the time, you may expect a significant inaccuracy.
https://electronics.stackexchange.com/questions/237025/converting-watt-values-over-time-to-kwh
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law