Please, proceed carefully following the tips published in this blog, specially when Main Power is involved. I'm not responsible for any damages caused by what is written in this blog.
Thank you

Wednesday, 18 October 2017

Home Automation System - Using groups in OpenHAB v.2

Another step forward with OpenHAB v.2...let's speak about "groups"; reading the official documentation (http://docs.openhab.org/configuration/items.html#groups) and studying them I discovered that they aren't simple labels to categorize items but they can be used also as particular objects to be added in the sitemaps, they can be used inside "rules" and may get a real value, derived from the linked items. They may also receive commands which will be forwarded to the items inside them.

A "group" is a special item with some differences. It is defined in a .items file in the folder /etc/openhab/items. So I create a new file called groups.items with some groups which I will use later, going forward with the openhab configuration.

Groups may be nested and so it is possible to create a real hierarchical design.

The syntax is very simple and you can find it in the official documentation.

The first groups I created are related to the floor and the room (main floor, first floor, kitchen, garden...), the item type (sensor, switch, network, etc etc...), the purpose (lights, temperature etc etc...) and so on...

Some of these groups will have a real value, depending on the value of the items / groups inside them. Examples:

- the gTemperatureFirstFloor group will be used for temperature sensors on the first floor and its value will be the average of all values of these sensors;

- the gEnergyConsumer group will be used for the energy consumer sensors and its value will be the sum of all values of the sensors;

- the gLightSwitchGarden group will be used for all the light switches in the garden and its value will be ON if at least one switch will be ON, otherwise OFF;

These groups can be put into the sitempas, so their values will be shown (if applicable...) and, click on them, you can see all the items / groups inside them, making a real hierarchical presentation.

For example, referring to the gLightSwitchGarden, we could add other groups for all the light switches in the house: gLightSwitchFirstFloor, gLightSwitchMainFloor, gLightSwitchGroundFloor (inside them we will put the light switch item...). Then, we create a new group called gLightSwitch linked to all of them.

Adding the gLightSwitch group in a sitemap we could browse all the light switches with a couple of click; sending command to gLightSwitch we will drive all the light switchs together.

Here is a video about groups and light switches: