I struggle with some specific topic and do not know if there is a “best practice solution” for this.
Let’s explain:
I have a heatpump that delivers various values via the Luxtronik/Novelan heatpump binding. Reading the delivered values and persisting them works great.
The used energy of the heatpump (KWH) is only delivered via a sinlge cummulative value that steadily grows. This value is never reset or broken down to hours or days or months, …
What I want o achieve:
Somehow get values from this cummulative energy value broken down to hours or days or months
Persist these broken down values (does this make sense? Or calculate them somehow in realtime when needed?)
Chart the values (preferrably Bar Charts, via Grafana). Can this be achieved with the big cummmulative value?
Does somebody else have this constellation with single values that need to be broken down and visualized?
What your item gives you is the energy E used by the device in kWh. What you would like to have is the power P currently drawn by your device. Since energy is the time integral of power, you need to calculate the time derivative of that value: P = dE/dt.
However, because the value for E that you get from your device is updated in intervals (probably seconds to minutes?), you can not calculate an exact value for P, but an estimate for the average value between an update and the update before that: P = (E(now) - E(previous update)) / (t(now) - t(previous update)).
It should be possible to perform this calculation in a rule on every update of E and set the value of P accordingly.
Assuming the item that receives the energy usage value from your device is called EnergyUsageItem and it is persisted in a database (e.g. InfluxDB, important!), and the item for the current power draw is called PowerItem, you could try the following:
rule "calculatePower"
when
Item EnergyUsageItem received update
then
val deltaE = EnergyUsage.state - EnergyUsage.previousState
val deltat = now - EnergyUsage.lastUpdate
PowerItem.postUpdate(deltaE/deltat)
end
You can then also persist PowerItem values and do any analysis you like using InfluxDB and Grafana.
Please be warned that I did not test the rule and I’m not sure if the calculation of deltat will work like this because I don’t have experience with timestamp values in openhab.
@armin80, let me know if this is still relevant for you. I have a very similar setting (though with a heat meter) and am currently testing what I build (so far it looks good). Probably, once I can confirm that it works without any errors, I’ll post a separate piece in the “Tutorial & Examples” / “Solutions” section.