FREE Shipping on orders over $49 USA $99 INTERNATIONAL

Control: Blinds Control MQTT OpenHAB ESP8266 Software Windows

Blinds Control MQTT OpenHAB ESP8266

Software Windows: 

Hey guys Matt here from MKSmartHouse.com and in this video I am going to show you how to setup the software for the Blinds Control using Windows.
 
So in the last video we left off with the Blinds Control Device being fully built so all it needs is firmware and to be connected to the home automation server. So let's start off with the firmware. I recommend having my website open up so that way you have all the steps and commands ready, and so you do not have to type in everything you can just copy and paste. I know this is the software video but, there are some hardware things that we need besides a computer. We are going to need an arduino of some kind preferably a UNO or a MEGA equivalent with its usb cable of course and male to male dupont jumper cables. Links to these items will be in the description or on the website.
 
1. The first thing we are going to do is grab the arduino and put a jumper cable from RES to GND.
2. Then grab the Blinds Control and connect all the pins to their corresponding spots so, TX to TX, RX to RX, GND to GND, and 5V to 5V.
 
Before we continue, check to make sure the 2 pin jumper is above PGM. Please note that in this video I will not go over how to setup the arduino IDE and will assume that it is set up and you know how to connect an arduino to it. If you do not know how to set it up or it is not setup then go check out my Door sensor software video where I go in detail of the entire process.  
 
3. Next we are going to head over to my site, the link is in the description to the exact page and press the download Blinds Control Firmware.
4. On the new page press download.
5. Then go to your file explorer and downloads folder and double click on MK-BlindsControl.ino.
6. A pop up will come up asking if you want to put it in a folder, click OK.
It should bring up the code for the Blinds Control, and there are only a few things we have to change.
 
7. The first thing is the wifi settings which are the ssid and password so change those according to your network.
 
Please keep in mind that the esp8266 only works on 2.4ghz so type in your 2.4ghz wifi ssid and password not your 5ghz. Also when adding the information only change what is inside the quotation marks. Next set of parameters are the Web Updater settings. The devices I designed are great because I implemented a web user interface for each individual device so that way if you ever have to flash new firmware you just go to its web address. The web address information is found at that top of the code in the giant comment block.
 
8. The first parameter is the hostname of the device, usually I only change the last digit but since this is the first Blinds Control I will keep it as it is.
9. Next is the update path and personally I don’t change that.
10. After that is the web user interface username and password, these are the credentials you use to access the webpage because each device is protected.
 
The next set of parameters are for mqtt.
11. The first one is the subscribeTopic and this is the topic for which the device listens for commands or messages from the server.
12. The next one is the MQTT Server Ip address and this is simply the IP address of your home automation or openhab server.
13. The last one is the Unique device ID and this simply differentiates each device on the MQTT side, I usually just change the last digit for every single device.
 
That is it the code is ready to be flashed.
 
14. So go to tools and make sure the Board: is Generic ESP8266 Module and the port is COM and a number.
Sometimes the device for some reason does not like to be flashed as a Generic ESP8266 module, if the device does not respond after you flash it, then when you flash it choose the ESP-12E as the board.
15. Once those are good press the upload button, it is the one with an arrow pointing to the right.
When it is uploading you should see dots moving at the bottom and some percents. After it is done uploading you should see it say 100% and Done uploading. Let’s Test it!
16. First unplug the dupont wires in between the arduino and the device.
17. Then take the 2 pin jumper and move it over so it is above RUN.
18. Finally plug the device into the wall.
19. To confirm that it flashed correctly and is working you can fire up MQTT.fx, connect to the server and in the subscribe section type in # and press subscribe.
 
If you do not have MQTT.fx then check out my Home Automation Server Setup Guide.
 
20. Then click on the publish tab.
21. In the topic bar type in the subscribeTopic that we wrote in the blinds control device code that we flashed.
22. Next in the message box type in any number 0 - 100 and press publish.
 
If the servo motor moves then we are all set! Now the device is complete and just needs to be added to OpenHAB.
 
23. So ssh into your pi or whatever your server may be.
The first thing we are going to do is create the Blinds Control item.
 
24. So type in sudo nano /etc/openhab2/items/home.items and press enter, you may need to type in admin password.
25. Then type in the comment //Blinds Controls then underneath that we are going to create the Blinds Control item.
26. So type in Dimmer MKBlindsControl1 "MK Blinds [%s]" <rollershutter> [ "Lighting" ] {mqtt=">[broker:MK-SmartHouse/utilities/MK-BlindsControl1:command:*:default]"}
And press enter.
Now let me go over the item we created. It will allow us to control the Blinds Control. But let me go a little bit more in detail, the first part is Dimmer and since this device is a Blinds Control we need to control the position of the servo motor with numbers. The next part is the item name and I just used its hostname without the dash. After that is the label text and it is what shows up in the interface and how it is formatted with the name. Next to that is the icon name which is what picture shows up in the interface. Then lastly, we have the mqtt path to the device in there is the subscribeTopic that we coded into the device. I have two blinds controls so I will paste it in again and change the item name, label text as well as the mqtt path to match that device’s subscribe topic. Thats it for the items file.
 
27. Now press control x then y and enter.
 
Next up is the sitemap file so we can control the device.
 
28. Type in sudo nano /etc/openhab2/sitemaps/home.sitemap and press enter.
 
It will bring up the sitemap. If you are following along with my series then we have many different frames in our sitemap. I am going to put the device in the frame called MK-Room.
 
29. So go to the frame and type in:
    Switch item=MKBlindsControl1 mappings=[0="Open", 56="Half", 100="Close"]
    Slider item=MKBlindsControl1
and press enter,
 
what we did is import the item into the sitemap so we can control it from the user interface. The controls it has is you can either press one of the three buttons, or use the slider. Again, since I have two I will also put the text in the JK-Room frame and change the numbers.
 
30. Now press control x then y and enter.
31. Before we go any further let's confirm that everything works so go to your web user interface and then Basic UI.
 
You should see the Blinds Control item.
 
32. If you press the buttons and move the slider you should see the servo move.
 
Great! Now that we know the Blinds Control works let's make it automatically open and close at the times we set.
 
33. In ssh type in sudo nano /etc/openhab2/rules/home.rules and press enter.
34. At the bottom of the file type in
//Set Blinds to half At 7 am
rule "Blinds half"
when
Time cron "0 0 7 1/1 * ? *"
then
     sendCommand(MKBlindsControl1, 56)
end
 
//Set Blinds to close At 6 pm
rule "Blinds close"
when
Time cron "0 0 18 1/1 * ? *"
then
     sendCommand(MKBlindsControl1, 100)
end
 
 
Let me explain what this does, the first rule sets the blinds to half everyday at 7 am the second rule closes the blinds everyday at 6 pm. If you want to change the times for the rules go watch my sprinkler system software video where I show you how to change cron expressions. Since I have two blinds I will also add those blinds to each rule.
 
35. Now press control x then y and enter.
 
That is it! The software is complete, now all we have to do is install the device in its final place which will be completed in the next final installation video. 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. Good Bye!