Imitating the Power Consumption of Lights (and others)

Great! Thanks a lot! I will try to edit it to my needs.

Is there a way to do this with groups or do i have to write a rule for each light?

I agree, I can write something in the coming days.

It’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.

Not really:


If you have Items that may not have been stored in persistence:

myGroup.members.filter[i|i.lastUpdate != null].sortBy[lastUpdate].last

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.

Regards, S

@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 :wink:

I think it still qualifies as a Design Pattern, but I’ll write it more like a tutorial than just an example.

I’ve already written most of it up in my own notes. I’ve transcribed it and beefed it up a bit here:

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

  1. add your Items to groups
  2. trigger the rule on all Items (or Group updates if multiple execs of the rule per event isn’t a problem)
  3. pull the triggering Item from the Group based on lastUpdate
  4. 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 :tada: :wink:
I should not forget to add your design patterns tag to this or something similar:
I’m waiting for the forum restructure. That will be fun.

It can’t be as painful as the eviction from Google Groups was… :slight_smile:

1 Like

Now I have no excuse anymore, to not build a group-based rule for the above :wink:

Another way to throw a different & larger lasso around the entire problem of energy monitoring is to go with a whole-house approach based on a multi-circuit-capable special-purpose hardware such as the Brultech GEM. I bought one of these units a few months ago & can now see per-circuit usage for the entire house. At around $500-$600 or so, not cheap, but perhaps a fair cost when compared to the time & coding investment required to try to piece together comprehehsive usage based on measurements of individual devices.

Hardware-level physical current monitoring also accounts for normal line-voltage variations in real time. (As much as +/- 7% from nominal 120V AC on heavily-loaded circuits.) A well-designed hardware solution also automatically measures & accounts for AC power factor, a very significant issue when dealing w/ inductive loads & switching power supplies.

IMO the GEM is a good piece of hardware, built-in web GUI is rudimentary but functional. Documentation is adequate but not super well-organized.

At some point I will work on getting the GEM hardware integrated w/ OpenHAB.

+1, they are great, I have 3 of them in my new house. Would be nice to have a binding some day.


Would be great, if you could explain your rule/item/… file from above a little bit more.

I wanted to test the file and changed the item names to my installation, but it didn´t work and as i don´t know what this rule exactly does, i can´t see, where i made a mistake or what went wrong…

A small tutorial would be great! Including a few words, which groups i have to persist for this and which persistence i need.

@globramma @sipvoip I do not own a house myself but would just out of curiosity be interested to know how difficult that binding would be? Is only the web GUI available? Could it be parsed easily?

In the web GUI you can setup how you want the data exported. Today most of us are using the script and mqtt to get the data into openHAB. I am not a programmer, but I don’t think it would be that complex to write a binding. If anyone is interested I can put one or more of my GEM units on the public internet for testing.

1 Like

Take a look at OpenEnergyMonitor - lots of ideas. And it integrates with Openhab…

hey guys. can you please show me, where i am able to find the complete tutorial as @Seaside ‘promised’?
i cannot find it.

This thread is really old. I don’t think I managed to post a tutorial. However I made a binding which can monitor power consumption, feel free to try it out.

This thread is really old.

yes, i know, but this was exactly that, what I was looking for.

Thank you for you Info, I’ll try it.

one more question…(or two)
can i use this binding to measure the power consumption of light bulbs based on the on-time?

in addition, i would like to preset the consumption of the respective light bulb as a variable.
and enter the multiplication value to calculate dimmed bulbs.

The binding will work if you supply “simulated” power inputs at given intervals.
I can probably add functionality for just supplying ON/OFF and the binding should work.
Do you use Openhab2 or Openhab3?

Regards, S