Calculate Energy Consumtion & Costs

Hi All, I am trying something very simple and already fail on the simple :frowning:

Basically, I’ve got a device consuming energy - no surprise… However, I would like to calculate the amount of energy it is consuming over time and I am searching a good approach for it leveraging a Rule.

To make it more difficult, the amount of consumption changes continuously:
14:00 - 14:30 0,50kW -> It burns from now on 0,5
14:30 - 14:45 0,10kW -> now it changed, instead of 0,5 it now burns only 0,1
14:45 - 14:50 0,30kW -> now it changed again, it burns going forward 0,3
14:50 - 15:00 0,10Kw -> to not make it boring, it changed again, it burns now 0,1
etc

How would you count this together, if item BurnedEnergy sends the updates as of the above (e.g. at 14:00 you receive 0,50, at 14:30 you receive 0,10, at 14:45 you receive 0,3 at 14:50 you receive 0,1)?

There’s nothing really, you can do, if you only get the actual consumption in that long intervals - as you don’t know what happens exactly in between - could be, that it burnes constantly 0,5kW (I’ll doubt that) - So you need the overall consumption.
What kind of power meter do you have here? and how is it connected to openHAB?

(I just moved the thread to the right Topic)

Not directly related but you might be interested to also read:

I agree with @binderth. In order to get the consumption of the device you need to calculate the integral product of power over time. With these sparse readings you are only able to get a rough number. If that’s okay with you you can simply define an item to store this number and a rule to add to it.

The better solution is often to get the consumption directly from the device. Most energy monitoring devices offer the additional data point.

Well, I am using KNX smart-meter. This tells me exactly the moment it changes. So if the device is burning 0,5 kW for 30 minutes, it would tell me the first moment it burns 0,5kW up until the 30th minute its buring 0,5kW.

After the 30 minutes it would tell me immediately that the device now burns 0,1kW and not 0,5kW anymore. Lets assume the device burns for another 15 minutes now 0.3kW (as in the above example) it would tell me immediately if it changes and the device does not burn 0.3 anymore. Therefore, I exactly know when the device burns how much. I only have not a good idea how i can calculate this together in a good rule.

The challenge basically is, if I would like to calculate this, than I could say:
kWh = what the devices burns (kw) * h => kwh = kw * h

I could measure 60 time in a minute the current used kw and count this together to get the Kwh. However, how do I do this in a clever way with rules?

I’m confident, the knx also counts the overall consumption. I can’t imagine it won’t?
But if it won’t, and if it tells you every change, it’s simple math? You know the consumption per hour, so just calculate the consumption on the reported length.

Write a rule when Item xy changes and, be sure you have persistence, so you can adress xy.lastupdated and xy.previousState().state so you can calculate the exact time the state was live. Calculate the kWh and add it to you overall consumption item.

But I would be very surprised, if your knx didn’t come up with that one itself…