Hey guys Matt here from MKSmartHouse.com and in this video I am going to show you the OpenHAB
2 Configuration files as well as how to set them up.
[Intro]
The configuration files make up the whole smart home and without them it would not work
because with these files we create the things, which connect to the items that we can use
in the sitemaps to then create rules for automation.
The statement that I just made is exactly how it works because there are 4 main configuration
files, things, items, sitemaps and rules.
To access all these files we have to ssh into the device so on windows open up putty and
on mac open up terminal, if you don’t know how to ssh then you can refer to my setting
up the home automation server series that will be linked below or in a card at the top
right.
Speaking of links I recommend having the written guide on my website open so all you have to
do is copy and paste commands.
Anyway the folders for where we are going to create these files are located in the OpenHAB
2 folder so type in cd /etc/openhab2 and press enter.
To see all the folders in this folder type in ls and press enter.
As you can see there are many folders and they all do different things but the first
folder we are going to access is the things folder so type in cd things and press enter.
Then we are going to create the things file so type in sudo nano home.things and press
enter.
It should open an empty text document so make a comment type in //This is the Things file
then press control x then y and then enter.
Great we created our first configuration file.
Eventually we will populate this file with devices that require a thing declaration,
keep in mind that not all devices need it.
The next file we are going to create is the items file.
So type in cd..
And press enter to go back to the main folder.
Then type in cd items and press enter.
Then type in sudo nano home.items.
It should open up a text document.
The items file is where we are going to create or add all of our devices so they can be accessed
such as a light switch.
Type in //This is the Items File and press enter 2 times.
But, we are not done yet, I think this is a good time to show you one of the most important
types of items and that is the switch, it is not the only type of item, for a complete
list check out the documentation at docs.openhab.org.
Anyway the first item is a switch so first type in a comment explaining the next item
we will create for reference purposes I wrote //Demo items and pressed enter.
Then type in Switch DEMOSW "Demo Switch" and press enter, let me explain what we wrote,
the first part is the type of item, the second part is its name and the third part is its
label text, there are many more parts to an item such as its binding config but we will
get to that when we add an actual device.
Now press control x then y and enter.
Then type in cd..
And press enter To go back to the main folder.
Next type in cd sitemaps and press enter.
Then type in sudo nano home.sitemap and press enter.
It should open up a blank text document.
The sitemap file is how you interact with the devices or the user interface.
Then type in the following code segment:
sitemap home label="MK-SmartHouse" {
Frame label="Demo" {
Switch item=DEMOSW }
}
Then press control x then y and enter.
Now comes the fun part we are going to see what we created.
Keep your ssh window up because we will access it later.
Open up your web browser and go to the openhab web user interface.
If you don’t know how to do that then look at my video on OpenHAB 2 web interfaces explanation
link in the card or in the description.
Then go to paper ui, in the left column go to configuration and then the services sub
tab.
Now we can configure the user interfaces, the first one is basic ui so click its configure
button, in the Default Sitemap field change whatever is there to home and press save.
Do the same thing to classic ui, click configure, change the sitemap to home and press save.
Great, now go back to the main web interface screen by typing in the ip address of the
pi again with :8080 and click on basic UI.
You should see a switch and the text demo switch.
It does not do anything but now you understand the process of creating it.
We can now also access classic ui and it will have the same information as basic ui it just
looks a little different.
Now let's go back to the ssh window and let me explain what each piece of code does.
Type in sudo nano home.sitemap and press enter.
The line sitemap home label="MK-SmartHouse" creates a label in the top.
Frame label="Demo" creates a new section or box in the interface with the name demo.
Switch item=DEMOSW Brings the switch item to user interface so we can control it.
Essentially you can keep creating more frames to organize your system, that is what I like
to do, I create a new frame for every room in the house that I will have smart devices.
Here is My Sitemap file I will be using if you do use it then delete everything you have
in your sitemap file and then paste it in it will be on my website.
sitemap home label="MK-SmartHouse" {
Frame label="Demo" {
Switch item=DEMOSW }
Frame label="Information" {
Switch item=DEMOSW }
Frame label="Security" {
Switch item=DEMOSW }
Frame label="MK-Room" {
Switch item=DEMOSW }
Frame label="JK-Room" {
Switch item=DEMOSW }
Frame label="Master Bedroom" {
Switch item=DEMOSW }
Frame label="Living Room" {
Switch item=DEMOSW }
Frame label="Garage" {
} Frame label="Outside"
{ Switch item=DEMOSW
} }
Then press control x then y and enter.
I put the demo switch in every frame because a frame can not be empty and they are just
placeholders till we put in actual devices.
If you go back to the basic UI You can see how it all looks.
Now let's talk a little about the rules file.
This is the file that does all the automation and since it has so many different things
I will show you how to utilize in its own video once we add some devices but in this
video I will show you how to create the file.
So type in cd..
And press enter to go back to the main folder, then type in cd rules and press enter.
Then we are going to create the file by typing in sudo nano home.rules and press enter, it
should create a text document then type in //This is the rules file then press control
x then y and enter.
Type in sudo reboot and press enter to reboot the device, I always recommend rebooting after
making major changes like these.
That is it!
The configuration files are all setup.
Now we have the Automation server ready for devices to be added but, before we do that
the next two videos will cover how to setup remote access so you can access your smart
home from anywhere and control devices from anywhere.
Which perfectly leads into the video after that, setting up mobile devices to access
the home automation server from IOS and Android.
Alright thank you for watching and If you have any questions leave them in the comments
section below or head over to mksmarthouse.com/forum where you have a better chance of it getting
answered.
Good Bye!