Getting started with Groups

I have 2 Openhab 1.8 Instances working very well together, but as Openhab 1.8 is at the end of its life development wise, and can’t be trusted to come up cleanly after every reboot I’m looking to the future, and migration to Openhab 2.
So far my items file has evolved without the assistance of groups, so my startup rule file has many instances of

postUpdate(Item1, OFF)
postUpdate(Item2, OFF)
postUpdate(Item3, OFF) // and so on, to avoid leaving items uninitialized

Which works, although it seems inefficient
My sitemap also defines each item separately

Text item=BedroomTemperature label="Bedroom Temperature [%.1f C]" icon="temperature"
Text item=BedroomCoolingTime label="Minutes needed to cool Bedroom [%.0f Minutes]" icon="clock"
Text item=TodayBedTime label="Todays Bed Time [%s]" icon="moon"

Will adding groups allow me to simplify things?
Is there any information about best practice for membership for OH2?
Is not having items in Groups a problem moving into OH2?

As each edit of default.items reset everything to uninitialized, and reboots can’t be always relied upon due to the occasional file not found error when restarting, I’ve tried to limit the editing of my items file until now.

Rules “yes”, Sitemap “maybe”.

In your Rules you can replace all those lines with:


However, while it is more efficient in lines of code, it runs just the same.

Using Groups can help in a lot of other situations as well. See this post for some details.

In Sitemaps Groups can make things easier but be aware that when you use a Group, you have no ability to customize how the Item appears on your sitemap.

Yes. By using Groups I was able to reduce my total lines of code by more than 50%.

I find them less useful on the Sitemap.

Not really but if you search the forum for Design Pattern you will find lots of uses of Groups in Rules. But there is nothing OH 2 specific about it. The concepts work the same in both.

No. Groups or lack of Groups is no different between the two.

You should use persistence with restoreOnStartup. This will initialize your Items to what ever they where when you saved the .items file or restarted openHAB. See the following for how I set up persistence.

Thanks very much for the detailed reply, I’ll experiment and see what I can simplify.
I’m guessing splitting the items file up into different files is way more trouble than its worth, as rules will start before all items files have finished loading, its up to 447 lines, although I can’t see it growing much larger?

I recommend splitting both items and rules into separate files. It is much easier to understand and maintain when they are separate files.

In OH 1 you can prevent the rules from running before items have loaded by setting the polling period for the Rules to be longer than items. This is not a problem at all in OH 2 as far as I can tell.

1 Like