In the previous post [here] , I noted down on building OpenHAB and getting up and running with its distribution.
Here, I will briefly introduce you to the user interface. We will modify the OpenHAB demo setup, we installed earlier, by adding a new device to control. We will be able to toggle this device eventually.
Adding a new device in OpenHAB
This is quite easy. It is just incredible that anyone using OpenHAB doesn’t need to worry too much about it’s user interface. The files of interest here are,
Please note that I use OPENHAB_HOME to refer to any location where you would have installed the OpenHAB distributions that we built here.
If you look at the default demo page of OpenHAB, you will find that devices are segregated into groups. The groups here are given user readable names like “First Floor” or “Ground Floor”. This is hierarchical as you would have seen in the earlier post. We will define a new group as “Second Floor” and add a new Light control for its “Corridor”.
Each of the sections in the home page is a frame which provides a clear distinction between various functionality you might want to provide from your home page. You can define a new frame here just for devices that can be monitored (for example: Outside Temperature device here). This is just a high level logical separation that user might want to work with. No rocket science here.
In the file demo.sitemap, you will find the page layout definition. Here look at the first entry under unnamed frame type which includes groups for all the floors. Go ahead and add another entry for our “Second Floor”. It should now look something like this.
sitemap demo label=”Main Menu”
Group item=gFF label=”First Floor” icon=”firstfloor”
Group item=gGF label=”Ground Floor” icon=”groundfloor”
Group item=gC label=”Cellar” icon=”cellar”
Group item=Outdoor icon=”garden”
Group item=gSF label=”Second Floor” icon=”firstfloor”
The highlighted entry defines a new group type (no devices yet) with user label of “Second Floor” and an user defined icon.
Now, under the demo.items declare that “Second Floor” group gSF will be used. Your entry should look like this,
Group gGF (All)
Group gFF (All)
Group gC (All)
Group gSF (All)
Now under this new group we can add any number of devices or items to control. Since we want to control a light device on the second floor corridor, define a new corridor device like this,
Group SF_Corridor “Corridor” <corridor> (gSF)
Now under section commented as Lights, include the following line,
Switch Light_SF_Corridor_Ceiling “Corridor” (SF_Corridor, Lights)
Now this tells OpenHAB system that SF_Corridor is a switch device type and that it can be controlled in ON or OFF manner like Lights. This is rather an incomplete definition since there is no physical access defined for controlled this device. But OpenHAB is happy to oblige and doesn’t care if there is no physical device present.
Device Control Simulation
Now refresh your browser (preferably by clearing the cache) and you should be able to see the new device additions to OpenHAB GUI.
Everytime you toggle the Corridor Light, you will be able to see INFO logs on the OpenHAB console. These message are helpful when debugging,
11:53:39.388 INFO runtime.busevents[:22] – Light_SF_Corridor_Ceiling received command OFF
11:54:00.186 INFO runtime.busevents[:22] – Light_SF_Corridor_Ceiling received command ON
The OpenHAB console also provides for command line access to the devices. You can quickly test your device access instead of using the GUI. You can list out all the devices under Second Floor using pattern matching,
osgi> openhab items *SF*
gSF (Type=GroupItem, Members=1, State=ON)
SF_Corridor (Type=GroupItem, Members=1, State=ON)
Light_SF_Corridor_Ceiling (Type=SwitchItem, State=ON)
This lists all the SF group devices and their state information.
To specifically check status of an item, you can use the status option,
osgi> openhab status Light_SF_Corridor_Ceiling
Control of the item can be done using the update command,
osgi> openhab update Light_SF_Corridor_Ceiling OFF
Update has been sent successfully.
This has been an easy change. But to physically cause state of a device (LED for now) to change using this GUI, we will use a RaspberryPI with OpenHAB running on it. We will also introduce another OpenHAB concept of bindings in the next post.