In this short article, I'm going to show how to monitor most of your energy consumption without investing in special hardware. This solution is based on the fact, that most devices (prominently all your lights) have unchanging wattage only depending on their current state, which is already controlled by your openHAB system.

By the help of power consumption measuring modules, such as the Homematic HM-ES-PMSw1-Pl, Sonoff Pow or similar, we are able to monitor the consumption of dynamic consumers, be it our washing machine, fridge, TV and more. These modules are great to measure the energy these devices consume over time. The measurements can be used to graph consumption, calculate energy cost or even build higher level state machines from.

However, the mentioned devices are not the only power consumers in our home. You could continue adding these pricey consumption measurement modules to more devices but for many of these, that might not be practicable and is actually not needed. Your home is already controlled by openHAB and the chances are high, that you can derive consumption from that. Devices like light bulbs or LED stripes have a constant wattage when active. We can easily represent this information in openHAB.

Determining Wattage

There are a few ways to determine the wattage of a light/device. The first one is more than obvious: Just check the label or housing:

It's a matter of minutes to determine and write down the wattage of most devices in your house.

Representation in openHAB

Let's continue with an example. I have an LED stripe in my home and after connecting the energy meter in between plug and socket I found out that it is using approximately 17 Watts when turned on (and 0 Watts when turned off). We can now build a simple rule to reflect the consumption of this device in a new Number item:

I've decided to condense this rule to make my rules file with dozens of these easier to read:

rule "myLEDstrip" when Item myLEDstrip received update
then if (myLEDstrip.state == ON) myLEDstrip_Power.postUpdate(17.0) else myLEDstrip_Power.postUpdate(0) end

Adding all further devices in this way is as simple as copy&paste. The shown code lines are working in openHAB 2.0 but should just as well work in openHAB 1.8.

On the Influence of Dimmers

Some devices have a constant usage which is related to a dimmer level or some other openHAB Number item. By taking multiple measurements it's possible to derive the power usage of your device in relation to this item. An example could be (Dimmer percentage on the left, measured power on the right):

Afterwards you need to find the mathematical correlation between these two. You can use a curve fitting tool to do so: https://www.mycurvefit.comDepending on your device try y=a*x, then y=m*x+c and then continue with more complex functions like y=a*x²+b*x+c till you find a good fit. The simplest form will be more than enough! It's no rocket science.

The result for our example from above is pretty obvious:

y = 1.17 * x

Transferred to an openHAB rule:

energy.rules

rule "myDimmer" when Item myDimmer_Level received update
then myDimmer_Power.postUpdate((1.17 * (myDimmer_Level.state as PercentType)).intValue()) end

That's it.

We have successfully added a Number item per device to represent the usage of these at all times. You can now do the next step. An example would be graphing all devices usage with InfluxDB+Grafana. You can also have the overall usage as a Text sitemap item. Lastly you could add logic to accumulate consumption over time and potentially decrease your energy bill Have fun!

The topic of this short tutorial was to create an item that always holds the usage of one device. By the help of the posted rule the item will be set to 0 watt when the myLEDstrip is turned off and 17 watt when it is turned on. I've just broken down the rule to multiple lines to make this better visible.

You could now for example persist these usages with InfluxDB+Grafana, that's what I am doing. You can also see the overall usage as a Text sitemap item. I'll add a summarizing sentence at the end.

halloween:

I´m missing the way, how to get the time how long the lights are on.

That was not my intention. I guess what you are talking about is, that you want to know how much energy was consumed over time and how much this will cost you. Correct?

While editing the article I realized my fault. I'm talking about the consumption of a consumer the whole time but the tutorial is only covering the part, where the wattage of one light bulb or device is made known to openHAB I've updated the article.

Best thing would be a page where i can see all my lights and there i get power consumption for every device on its own.

Then i can add all devices and get the sum of all lights.

If it will be shown after state has changed or every xxx minutes - that doessnt matter and can be changed very easy.

This way i can see, where it would be a good idea to change old bulbs to new led lightings for example. Some rooms which i enter not very often, there it doesn´t make sense to change to leds - too expensive.

Trying to strip off a lot of specific stuff .. Also I'm not using rrd4j, only mapdb I only store the latest value.This can probably be done in some other way with avargeSince-function if you store values in a db. I'm using a timer..

@halloweenIt's not impossible, but it's more difficult for sure. I have something similar for handling my sonos-groups, but I use hashmaps where the label of item is the key. It's also possible to sort a group so you can get the most recent changed item, however, I won't display a solution of that here as it is quite messy.

Didn't express myself very clear, was referring to the generic solution as a whole, it is possible that it can be done in a better way than what I was thinking, but my solution is messy.I'll try to write a small guide but any improvements and or generic suggestions would be good to see.

@rlkoshak it would actually be a very nice gesture of yours, if you could write a hands-on tutorial about how to best go from items-based rules to group-based ones. I believe many users would benefit from your experiences for best practices in that area. I'm not talking about a "Design Pattern" but a step by step guide

Problem Statement
Often one finds a number of rules that are very similar and that all work on similar Items. One way to solve this problem is through the use of lambdas but an even more flexible approach is to use Groups.
This Design Pattern presents a step-by-step tutorial for how to use Groups to consolidate and simplify the these several similar rules into one single rule.
The example used will be based on Contact Items that represent door and window sensors. Whenever any of these Cont…

It ended up being difficult to provide a step by step guide as the steps are just:

add your Items to groups

trigger the rule on all Items (or Group updates if multiple execs of the rule per event isn't a problem)

pull the triggering Item from the Group based on lastUpdate

code as usual

However, I did provide examples for and description of what all of the MyGroup.members.* methods do (at least all the ones I know) including map/reduce.

I've only looked at it briefly but Yes, that looks great!! Thank you I should not forget to add your design patterns tag to this or something similar: https://github.com/openhab/openhab-docs/issues/205I'm waiting for the forum restructure. That will be fun.