FREE Shipping on orders over $49 USA $99 INTERNATIONAL

Setting Up The Home Automation Server

Setting Up The Home Automation Server

Demo:

Hey guys Matt here from MKSmartHouse.com and in this video I am going to give you a demo of the Home Automation Server we will be creating.
So the point of this demo is to show you the home automation server in action as well as how it all works. Also, Please also go ahead and press the like button because if all five videos in the Home Automation Server Series hit 200 likes then I will release the videos on how to actually use OpenHAB 2.0 sooner then it is scheduled.
 
Anyway the first thing I will show you is the device in action so as you can see here it is and it is mounted on the same wall as the network. But, you might be wondering what it is doing right now well, right now it is hosting the OpenHAB 2 service as well as the mqtt service. After completing this series we will be prepared and ready to create the user interfaces as well as connect our smart automation devices.
 
Now let's talk about how it all works. To start off the entire thing is running on a raspberry pi, in this case I am using a raspberry pi 3 but this will work fine on a 2 as well as anymore pi’s in the future. Next up the storage for the pi is a 32gb sandisk micro sd card class 10 of course for the extra data speed. The pi is being housed in a clear acrylic case with a fan built in. But the fan does not do the cooling on its own, I have also installed a heat sink which with the fan is pretty good cooling. The pi is being powered by a 5v 2.5 amp power adapter that is UL certified which is important for power stability. The actual pi is connected to the network via a green cat 6 cable. We will be installing the software onto the pi using either a Mac computer or a windows computer which each have their own video so when you do it make sure you watch the right video. The software we will be installing is OpenHAB 2 as well a Mosquitto Mqtt server. But, this has all been made easy because all we will be doing is flashing a prebuilt image called openHABian which makes everything a lot easier. To actually configure the pi we will be using a combination of the web browser and ssh. But, the entire software process will be explained in its respective video.
 
That’s all I have for the actual demo, now it is time for you to watch the next videos to learn how to setup your own home automation server running OpenHAB 2. 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!

Setting Up The Home Automation Server

Hardware:

 

Installing the heatsinks onto the raspberry pi:
1. Peal the backing off of the smaller heatsink
2. Take the smaller heatsink and place it on the small black square on the raspberry pi
3. Align the heatsink and then press down on it to make sure it attached
4. Peal the backing off of the bigger heatsink
5. Take the bigger heatsink and place it on the big black square on the raspberry pi
6. Align the heatsink and then press down on it to make sure it is attached
 
Setting up the case:​
1. Take off all the protective acrylic packaging paper off of the acrylic pieces of the case (Use a knife to pick at a corner and pull off the plastic)
2. First take bottom piece, the one with the box in the center and the long side with the shorter distance of the side to the box facing you
3. Take out the 4 screws, 4 plastic washers and 4 nuts from the bag
4. Take the 4 screws and put them into the bottom plastics piece from underneath with the long side with the shorter distance of the side to the box facing you and place on flat surface
5. Take the 4 plastic spacers and put them on the screws
6. Take the raspberry pi and put it on the screws by ligning it up
7. Take the 4 nuts and put them on the screws
8. Take out the 4 nuts and 4 screws out of the bag
9. Take the top piece of the case and lay it flat with the gpio cut facing away from you and the big lift tabs to your left
10. Lift up the piece and stick in the 4 screws underneath the piece and through the holes
11. Take the fan and look around its sides to find two arrows
12. Orient the fan so the arrow is pointing up and where the cable exits the fan should be away from you
13. Take the fan and place it on the 4 screws
14. Take the 4 nuts and screw the fan down
15. Use a philips screw driver and a wrench or pliers
16. Take the two long side pieces for the case and put them on 
17. 5v fan so plug the red side into pin 4 and black side into pin 6
18. But sadly the case does not fit with the connector how it is so we are going to shave off the side clip with a razor or knife then plug it in
19. Take the cable and sort off wrap it around the fan, and place the top piece in the two holes of the side pieces
20. Take the piece with two holes in it and align it over the front ethernet and usb ports, when you put on the piece first hook it over the top hooks and then the bottom clips
21. Then take the final piece and put it over the back, by hooking it on the top and cliping it in
22. Now the case is complete
 
Setting it up for use:
1. Plug in the ethernet cable into your network and into the raspberry pi
2. Plug in micro usb side into the raspberry pi but not into the wall socket yet
Setting Up The Home Automation Server
Software Mac:
Setting up the micro sd card (Updated 6/21/17):
1. Grab the micro sd card at least 16 gb recommended 32GB
2. Put the micro sd card into your computer, could be using a micro sd card reader
3. Go to: https://github.com/openhab/openhabian/releases
4. Scroll down to downloads and download the raspberry pi image by clicking on the file called “openhabianpi-raspbian-XXXXX.img.xz”
5. It should download
6. Go to: http://wakaba.c3.cx/s/apps/unarchiver.html and download The Unarchiver
7. Go to your downloads folder
8. Double click on the unarchiver.zip file
9. Drag The unarchiver to applications folder
10. Right click on the openhabianpi-raspbian-XXXXX.img.xz and open with the unarchiver it should unzip it and create a regular .img file without the .xz
12. Scroll down to most recent version (recommended) and click download now
13. Open finder and go to your downloads folder
14. Double click to unzip the ApplePi-Baker.zip
15. Then double click on ApplePi-Baker to open the program
16. You might get a warning saying unidentified developer, if so go to system preferences
17. Security and Privacy then click the button open anyway a box will pop up click open
18. Now we are in apple pi baker and it will ask for admin password for your computer, so type it in and press ok
19. Next in the left side click and select your micro sd card
20. Then in the IMG file field click the 3 dots to browse for the image
21. Head over to your downloads folder and select the openhabianpi-raspbian-XXXXX.img file and click open
22. Then click Restore Backup
23. When the box pops up that says Your ApplePi is ready! Click ok and remove the micro sd card from your computer.
24. Then quit apple pi baker
Putting the micro SD card into the raspberry pi:
1. Take the micro sd card and put it into the raspberry pi, the logo on the SD card should be facing down
2. Then take the other end of the power adapter and plug it in
3. The raspberry pi is now booting
4. Please be patient and set a timer for 45 minutes because that is how long the first boot will take
Setting up the static IP address:
1. Go to you routers web page using a web browser, mine is 192.168.0.1 and login
2. Then go to DHCP and DHCP Client list
3. Look through the list and find openHABianPi
4. Then copy its MAC address
5. Now head over to address reservation
6. Then click add new
7. In the MAC address field paste the pi’s MAC address
8. And then give it a reserved IP address, continuing on from the network videos, I am going to give it 192.168.0.4
9. Then click save and in the pop up box click ok
10. There will be a little warning saying that it needs to reboot so click on the thing that says “click here”
11. And press the reboot button and ok in the pop up box
12. Let the router restart
13. Once the router is fully booted unplug the raspberry pi wait 10 seconds and then plug it back in
14. Wait 1 minute for the raspberry pi to boot back up
Setting Up OpenHAB 2 base components + MQTT Server Mosquito (Updated 6-21-17):
1. Then open up your web browser and go to http://yourpiipadress:8080 replace the yourpiipadress with your pi’s ip address, mine is http://192.168.0.4:8080
2. You should see a webpage asking which setup you would like, we are going to click Expert
3. Now it should be installing our user interfaces, this could take a couple minutes so be patient
4. Open up terminal on mac and type in ssh openhabian@192.168.0.4 replace 192.168.0.4 with your pi's IP and press enter
5. Type in yes and press enter
6. Default password is openhabian
7. type in sudo openhabian-config and press enter
8. Type in the default password openhabian
9. Use the arrow keys and go to update and press enter (it might kick you out of the configurator if so follow step 10 if not go to step 11)
10. Then go back to configuration type in sudo openhabian-config and press enter
11. Use arrow keys and go to Upgrade system and press enter
12. Once that is done use the arrow keys and go to optional components and press enter
13. Then use arrow keys and go down to Mosquitto and press enter
14. Then on the screen press enter while continue is highlighted
15. We will not be using authentication so use arrow keys and go over OK and press enter
16. It should now be installing our mqtt server
17. Once it is done press enter over OK
18. Use arrow keys go to exit and press enter
19. It should give you a warning that we didn't change the password so we are going to change some passwords I recommend using the same new password for the next two things
20. Type passwd and press enter, we are now going to change ssh password, so enter the default password openhabian and press enter then enter a new password and press enter then confirm that password by typing it in again and enter it should say updated successfully
21. We are now going to change the samba password I will explain what this is later, anyway type in sudo smbpasswd openhabian and press enter
22. You might have to Type in the sudo password so the one we just changed previously and press enter if not go to step 22
23. Now type in a new password I recommend using the same password as the sudo password so type it in and press enter then type it in again and press enter
24. Next we are going to change the timezone and locale so the raspberry pi can set its date and time
25. Type in timedatectl list-timezones and press enter Then use the arrow keys to scroll down through the list to find your time zone, once you find it highlight it and then copy or remember it then press control z to exit
26. Type in sudo timedatectl set-timezone Europe/Berlin but replace the Europe/Berlin part with your timezone then press enter
27. Then type timedatectl and press enter to check the timezone
28. We have now finished the initial configuration the home automation server
29. So now type in sudo reboot and press enter, you might have to type in the sudo password and press enter
Testing The MQTT Server Mosquito:
1. Once it is done rebooting go to http://mqttfx.org/
2. Press Download MQTT.fx then click on the one below Latest version
3. It will take you to a new page click on the file that has the ending macos.dmg
4. It will start downloading
5. Once it downloads open up finder and go to your downloads folder
6. Double click on mqttfx……...macos.dmg
7. Box should pop up double click on MQTT.fx installer
8. Should give a warning of unidentified developer so go system preferences > security and privacy and the click open anyway
9. Another box will pop up click open
10. Then go through the setup by click next two times and then finish
11. It is now installed so go to launchpad and click on MQTT.fx
12. This is now a good time to explain what this is, this is a program that tests mqtt stuff so you can debug it and see if it is working
13. Click on the gear at the top
14. Change broker address to the ip address of the raspberry pi mine is 192.168.0.4 and make sure the port is 1883
15. Then at the bottom click apply then click cancel
16. Now click connect
17. If it connects successfully and there is a green circle in the top right then you are good
18. Go over to the subscribe tab and type in the # symbol and press subscribe
19. Then in the publish tab type in hi in the field and then in the big box type in hello world! Then hit publish
20. Then go back to the subscribe tab and if you see hello world that we are very good
21. We successfully set up the mqtt server
Connecting The MQTT Mosquito server to OpenHAB 2:
1. Now lets connect the mqtt server to openhab, so go to open up your web browser and go to http://yourpiipadress:8080 replace the yourpiipadress with your pi’s ip address, mine is http://192.168.0.4:8080
2. Then click paper ui, paper ui is the web administration pannel for the automation server
3. Add ons
4. In the search box type in MQTT
5. Next to where it says MQTT Binding click install wait for it to install
6. Go back to terminal and ssh into raspberry pi, type in ssh openhabian@192.168.0.4 replace 192.168.0.4 with your pi's IP and press enter, then type in your sudo password and press enter
7. Type in sudo nano /etc/openhab2/services/mqtt.cfg and press enter
8. Might ask for sudo password so enter that
9. The only thing we are going to change is the server or url to our broker so delete the line #<broker>.url=tcp://<host>:1883 and replace it with broker.url=tcp://192.168.0.4:1883 but change the IP address to match your raspberry pi
10. Press Control x and then press y then press enter to save
Software Part Complete For The Setting Up The Home Automation Server

Setting Up The Home Automation Server

Software Windows:

 

Setting up the micro sd card (Updated 8/21/17):
1. Grab the micro sd card at least 16 gb recommended 32GB
2. Put the micro sd card into your computer, could be using a micro sd card reader
4. Scroll down to downloads and download the raspberry pi file by clicking on the file called “openhabianpi……..xyz”
5. It should download
6. Go to: http://www.7-zip.org/ and download and install 7-Zip
7. Once it is installed right click on openhabianpi....xyz then hover over to 7-Zip and click extract here
8. The file is now a .img file
10. Click the download button and it should automatically download
11. Once it is done downloading open file explorer and go to your downloads folder
12. Double click on Win32DiskImager to install it
13. Click run and then yes in the pop up boxes
14. Click next, agree to the terms, click next, next, next, next and then click install
15. Once it is done click finish
16. You should get an error that says “Unable to execute file” click ok
17. Go into the search bar or wherever your applications are and find Win32 Disk Imager
18. But we have to run as administrator so right click on it and press run as administrator then click yes in the pop up
19. First we have to load the image so click on the folder icon next to the Image File Field
20. Go to the downloads folder and double click on the file that starts with openhabianpi
21. Next in the device drop down select the letter drive of your micro sd card if you are unsure you can go to the file explorer and check the letter of the drive
22. Click write
Putting the micro SD card into the raspberry pi:
1. Take the micro sd card and put it into the raspberry pi, the logo on the SD card should be facing down
2. Then take the other end of the power adapter and plug it in
3. The raspberry pi is now booting
4. Please be patient and set a timer for 45 minutes because that is how long the first boot will take
Setting up the static IP address:
1. Go to you routers web page using a web browser, mine is 192.168.0.1 and login
2. Then go to DHCP and DHCP Client list
3. Look through the list and find openHABianPi
4. Then copy its MAC address
5. Now head over to address reservation
6. Then click add new
7. In the MAC address field paste the pi’s MAC address
8. And then give it a reserved IP address, continuing on from the network videos, I am going to give it 192.168.0.4
9. Then click save and in the pop up box click ok
10. There will be a little warning saying that it needs to reboot so click on the thing that says “click here”
11. And press the reboot button and ok in the pop up box
12. Let the router restart
13. Once the router is fully booted unplug the raspberry pi wait 10 seconds and then plug it back in
14. Wait 1 minute for the raspberry pi to boot back up
Setting Up OpenHAB 2.0 web config
1. Then open up your web browser and go to http://yourpiipadress:8080 replace the yourpiipadress with your pi’s ip address, mine is http://192.168.0.4:8080
2. You should see a webpage asking which setup you would like, we are going to click Expert
3. Now it should be installing our user interfaces, this could take a couple minutes so be patient
Setting up SSH:
2. Find where it says “MSI(‘Windows Installer’)” and click on the .msi file that corresponds with you system architecture either 32 or 64 bit personally I choose 64 bit
3. Open File Explorer then go to your downloads folder
4. Double click on the .msi file that starts with putty-
5. When the box comes up hit run
6. Click the next button 2 times and then click install when the box comes up click yes
7. Once done hit finish
8. Now we are going to open putty, so either search for it in the search bar or go to wherever your applications are and run it
9. Right click on it and press pin to taskbar so you always have access to it
10. In the Host Name field type in the IP address of the raspberry pi
11. In the Saved Sessions field type in Home Automation Server and press the save button
12. Click Open
13. Box should pop up saying not cached in the registry, just press yes
14. In the prompt box it will say login as: type in openhabian
15. Now it will ask for the password type in the default which is openhabian and press enter
16. Congratulations we are now SSH into the raspberry pi
17. Type in sudo openhabian-config and press enter
18. Type in the default password openhabian
19. Use the arrow keys and go to update and press enter (it might kick you out of the configurator if so follow step 20 if not go to step 21)
20. Then go back to configuration type in sudo openhabian-config and press enter
21. Use arrow keys and go to Upgrade system and press enter
22. Once that is done use arrow keys and go down to Mosquitto and press enter
23. Then on the screen press enter while continue is highlighted
24. We will not be using authentication so use arrow keys and go over OK and press enter
25. It should now be installing our mqtt server
26. Once it is done press enter over OK
27. Use arrow keys go to exit and press enter
28. It should give you a warning that we didn't change the password so we are going to change some passwords I recommend using the same new password for the next two things
29. Type passwd and press enter, we are now going to change ssh password, so enter the default password openhabian and press enter then enter a new password and press enter then confirm that password by typing it in again and enter it should say updated successfully
30. We are now going to change the samba password I will explain what this is later, anyway type in sudo smbpasswd openhabian and press enter
31. You might have to Type in the sudo password so the one we just changed previously and press enter if not go to step 33
32. Now type in a new password I recommend using the same password as the sudo password so type it in and press enter then type it in again and press enter
33. Next we are going to change the timezone and locale so the raspberry pi can set its date and time
34. Type in timedatectl list-timezones and press enter, then use the arrow keys to scroll down through the list to find your time zone, once you find it highlight it and then copy or remember it then press control z to exit
35. Type in sudo timedatectl set-timezone Europe/Berlin but replace the Europe/Berlin part with your timezone then press enter
36. Then type timedatectl and press enter to check the timezone
37. We have now finished configuring the initial setup home automation server
38. So now type in sudo reboot and press enter, you might have to type in the sudo password and press enter
 
Testing The MQTT Server Mosquito:
1. Once it is done rebooting go to http://mqttfx.org/
2. Press Download MQTT.fx then click on the one below Latest version
3. It will take you to a new page click on the file that suits your windows the first windows one is 64 bit and the second one is 32 bit
4. It will start downloading
5. Once it downloads open up file explorer and go to your downloads folder
6. Double click on mqttfx……...windows
7. Click run and then when the other box comes up click yes
8. Click next 3 times and then click finish
9. Go to your search bar or wherever your applications are and look for mqttfx and the double click on it to open the program
10. This is now a good time to explain what this is, this is a program that tests mqtt stuff so you can debug it and see if it is working
11. Click on the gear at the top
12. Change broker address to the ip address of the raspberry pi mine is 192.168.0.4 and make sure the port is 1883
13. Then at the bottom click apply then click cancel
14. Now click connect
15. If it connects successfully and there is a green circle in the top right then you are good
16. Go over to the subscribe tab and type in the # symbol and press subscribe
17. Then in the publish tab type in hi in the field and then in the big box type in hello world! Then hit publish
18. Then go back to the subscribe tab and if you see hello world that we are very good
19. We successfully set up the mqtt server
Connecting The MQTT Mosquito server to OpenHAB 2:
1. Now lets connect the mqtt server to openhab, so go to open up your web browser and go to http://yourpiipadress:8080 replace the yourpiipadress with your pi’s ip address, mine is http://192.168.0.4:8080
2. Then click paper ui, paper ui is the web administration pannel for the automation server
3. Add ons
4. In the search box type in MQTT
5. Next to where it says MQTT Binding click install wait for it to install
6. Go back to terminal and ssh into raspberry pi, type in ssh openhabian@192.168.0.4 replace 192.168.0.4 with your pi's IP and press enter, then type in your sudo password and press enter
7. Type in sudo nano /etc/openhab2/services/mqtt.cfg and press enter
8. Might ask for sudo password so enter that
9. The only thing we are going to change is the server or url to our broker so delete the line #<broker>.url=tcp://<host>:1883 and replace it with broker.url=tcp://192.168.0.4:1883 but change the IP address to match your raspberry pi
10. Press Control x and then press y then press enter to save
Software Part Complete For The Setting Up The Home Automation Server 

Setting Up The Home Automation Server

Final Install:

 

Preparation:
1. Unplug the raspberry pi from the micro usb cable as well as unplug the ethernet cable
2. Then bring over to a table and take the whole case apart because we need to make some small modifications
3. Next unscrew the raspberry pi from the bottom piece of the case and put it somewhere safe
4. Make sure you do not loose the small screws so move them somewhere safe
 
Modifying the case
1. Grab a small piece of wood, I am using a short piece of a 2 x 4 this is to prevent the desk being damaged
2. Then take the bottom piece of the acrylic case with the straight side to the left and the shorter side to the middle box facing you
3. Choose a drill bit that is bigger than the screws you are going to use to mount the pi, The screws I have are M3.5 so I chose a 4mm drill bit
4. Next grab your drill and put in the drill bit
5. I am going to drill two holes for mounting, one is going to be in between the micro sd card hole and the square cut out, the other hole is going to be in between the left edge and the square
6. Once the holes are drilled, we are going to countersink them so they are flush with the case
7. Find a counter sink bit that will make the screw flush, I chose a size 8 and found that it worked really well
8. Once you chose a size put it in the drill and go to the hole and just start drilling, while you are drilling though take breaks to test and see how flush the screw is
9. When the screw is perfectly flush then we are done and then repeat the procces for the other hole
10. Great now that both screws are counter sunk, put the case back together but, without the pi inside
11. Bring it over to where you are going to mount and play around with its positioning, keep in mind the locations of the ports and clearance
12. Once you chose its position bring the case back over to the table and take it apart.
13. After it is apart find a drill bit that is smaller than the screw we are going to use to mount the case
14. Take the bottom piece of the case back over to where we are going to mount it and drill holes use the bottom piece as a template
15. When the holes are drilled bring the bottom piece back to the table and put the two mounting screws through the holes
16. Then take 8 - 10 of the plastic washers and put them over the screws, the reason we do this is to provide a space between the bottom piece and the mounting surface so we can assemble the case on the wall
17. This is the tricky part grab the 4 screws that we use to mount the pi to the case and stick the through (Refer to the video if confused)
18. Now with all the screws in bring it over to the mounting place and screw in the mounting screws into the predrilled holes
19. To prevent the raspberry pi from ever shorting just in case I put pieces of electrical tape over the metal mounting screws
20. Next take the 4 small plastic spacers used for attaching the pi to the case and put them over the 4 screws we put in before screwing it to the wall
21. Then take the pi in addition to the 4 nuts and mount the pi to the case, since we can't reach the screws we will just finger tighten the nuts
22. All we have to do is assemble the case, so grab the microsd card side piece as well as the two long pieces and put them on
23. After take the piece with the fan, and connect the fan as well as put the piece on
24. Finally take the piece with the port cutouts and put it on
25. Before we plug in the cables I like to label them
26. I used my dymo label maker and made a label for the two sides of the ethernet cable as well as the power brick
27. I also labeled the actual pi with what type of server it is and its IP address
28. Then I took the micro usb cable and the ethernet cable and plugged them in
29. The automation server is now done in terms of hardware

Setting Up The Home Automation Server Resources:

Product Links:

Raspberry Pi Stuff
Raspberry Pi 3: http://amzn.to/2m62Kg6
Power Adapter: http://amzn.to/2lIyh5E
Micro SD Card: http://amzn.to/2mQZGo7
Ethernet Cables: http://amzn.to/2mQVsws
Wall Mount Hardware
Tools
Micro SD Card Reader: http://amzn.to/2lqsvL1
Impact Gun + Drill: http://amzn.to/2lqke9L
Screw Bit Set: http://amzn.to/2mQSpoh