FREE Shipping on orders over $49 USA $99 INTERNATIONAL

MQTT Door / Window Sensor

MQTT Door / Window Sensor

Demo: 

Hey guys Matt here from MKSmartHouse.com and I am going to give you a demo of the door sensor we will be creating.
So what is this door sensor exactly well, it is a sensor that connects to our openhab server through MQTT and tells it the state of the door. If I pull out a mobile device and open up the openHAB app you can see that I now have two things in the security. The first thing is a switch that says “Security System” and what it does is control whether the server sends out notifications if a device is tripped. The next item is the door sensor and this one is labeled as “Side Door”. This item shows me the current status of the door. Right now I have the Security System switch on and the door is closed. I locked my mobile device and as you can see if I open the door I get a notification. Now, if I go back to the openhab app and turn off the security system, you can now see that if I open and close the door I am not getting notifications but the device status is still changing. Next, I am going to show you around the device starting with it already mounted. Starting from the top we have the magnetic switch sensor, and this is the part the determines if the door is open. Next we have the control box and then if we keep going down is its power wire connected to an outlet. But, let's take a closer look at the control box. It is all housed in a nice plastic enclosure with two holes for screws, in the final installation video I explain that I am going to mount it differently. Anyway if we open it up we can see the Custom PCB and its components. First up at the top right is the communication port and this is how we are going to program the device. Next to that is the 5 volt input that will come from the power adapter. To the right of that is the mode switch and we use this to either put the device into program mode or in run mode. In the top left there is the input for the magnetic switch sensor. Underneath that is a resistor and a 5 volt to 3.3 volt regulator because the ESP8266 uses 3.3V speaking of if we flip the board over we will see the esp right in the middle. The esp8266 is the whole brains of the device and it is what connects to the openhab server through mqtt That’s it that is the entire device! In the next video I will show you all the hardware we will need and how to put it together. 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!

MQTT Door / Window Sensor

Hardware: 

So, in this video we are going to go over all the parts required for the door sensor and then we are going to make it. To start off with the parts we are going to need 2 2 pin pcb terminals, 1 4 pin female header, male header strips that we can cut to length, 2 pin jumper, 10k resistor, 5v to 3.3v regulator, ESP8266, Custom Printed circuit board more on that later, plastic enclosure, magnetic switch sensor, 2 conductor 22 Gauge Cable, Male usb connector and a 5v USB Wall adapter. The wall adapter can be any usb 5v adapter like a phone charger. For tools we are going to need a soldering iron with ST7 tip, flux, steel wire, solder, wall tac, PCB holder, helping hands, wire strippers, small wire cutters, small flat screwdriver and a hot glue gun. That is everything that we will need. The links to all the parts and tools will be in the description. In the beginning I did say custom circuit board because to make this easier I designed a custom circuit board so that way not only will it be very stable and have strong connections with no guess work in assembling it but, also so I can make many of them really easily for my house. I have provided the gerber file in the description as well as where to get it made. Also, I have made a video on my website showing how to order the custom circuit board from iTead so that way there is nothing to be scared of and you know exactly how to order it.
 
Since all the connections are already made on the circuit board all we have to do is solder the components on to the board.
1. First let's take the circuit board and put it into the circuit board holder. If you look closely at the circuit board you will see that there are labels next to the component slots, when I say where to put the component that is what I will be referring to.
2. I like to solder from the less sensitive components to to most sensitive so, let's start off with the 2 pin terminals, take the terminals and put them in J1 and J4.
3. Then take the wall tac and temporarily secure the component.
4. After flip the pcb so we can start soldering. When soldering I recommend taking the flux and putting some on the on the soldering area, so it makes a better solder connection.
5. Then take your soldering Iron and put it on the component and put the solder behind the component. Clean the soldering iron with the steel wire often.
6. Once the solder is cooled remove the wall tac from the component. Great we soldered our first components!
 
To make this guide simple I won't repeat myself with the wall tac, flux and how to solder instead I will just refer to the whole process as soldering.
 
7. Next take the 4 pin female header and put it into J2 and solder it in.
 
If the leads get long and stick out gut them with wire cutters.
 
8. Then take a strip of the male header and using the wire cutters make a header that is 3 pins long.
9. Take that 3 pin male header and solder it into J3.
10. Now take the 10K resistor and bend one side so the two leads are parallel to each other and solder it into slot R1.
11. Next take the 5v to 3.3v regulator and match up its leads to the board and solder it in.
 
Great now we have one component left to solder and that is the esp8266.
 
12. I recommend putting flux on every single pad of the esp8266 and of the circuit board and then solder it in.
13. Now that everything is soldered take the 2 pin jumper and put it on the pins above PGM.
14. Next take the Magnetic Switch Sensor and strip its leads and fold them over so they are touching the wire insulation.
15. Then loosen the terminal screws where it says Sensor Input using the small flat screw driver.
16. Now take the leads of the Switch Sensor and put it in the holes of the terminal, it does not matter which lead goes into which hole.
17. Then take the screwdriver and tighten the screws.
18. Now we are going to make the power cable for the device so go over to where you are going to have the device and cut how much 22 gauge wire you think you are going to need for the device to the nearest outlet.
19. Then take one end of the wire and strip it to expose the 2 conductors.
14. Strip a little of the each conductor and then take wire boot and plastic boot of the usb connector and slide it over the 2 conductors.
15. Next take the helping hands and put the 22 gauge wire in one of them and the usb connector in the other.
16. Then solder the black wire to the far left pin and the red wire to the far right pin.
17. Now put some hot glue on the connector and slide over the plastic boot and the wire boot.
18. If you want you can connect the USB to the 5v wall adapter but do not plug it into the wall.
19. Almost done, strip the other end of the 22 gauge cable and then loosen the two screws on the 2 pin terminal above the 5v.
20. Then take the red wire and put it into the hole parallel to where it says + and the black into the hole above the - symbol and tighten the screws.
21. Finally take the PCB and put it into the plastic enclosure, but don’t put on the lid yet because we still need to install its software which is what we will cover in the next video.

MQTT Door / Window Sensor

Software: 

sudo nano /etc/openhab2/items/home.items 
 
 
 
//Security items
 
Switch SecuritySystem "Security System" 
 
Contact MKDoorSensor1 "Side Door [%s]" <door> { mqtt="<[broker:MK-SmartHouse/security/MK-DoorSensor1:state:default]" }
 
 
 
sudo nano /etc/openhab2/sitemaps/home.sitemap
 
 
 
Switch item=SecuritySystem
 
Text item=MKDoorSensor1
 
 
 
sudo nano /etc/openhab2/rules/home.rules
 
 
//Side Door Sensor Is Open
 
rule "Side Door Sensor"
 
when
 
   Item MKDoorSensor1 received update OPEN
 
then
 
       if(SecuritySystem.state == ON)
 
       {
 
           sendBroadcastNotification("SECURITY SYSTEM: SIDE DOOR OPEN")
 
       }
 
end

MQTT Door / Window Sensor

Final Install: 

First up let's go over the materials we need to install this door sensor. For this device there are two ways to install it so what you need depends on how you install. The first way and the way I am going to do it, is to take wall tac and put it on the back of the device and stick it to the wall. In this case all you need is wall tac. The second way to install it is to take screws and screw it to the wall. In this case you need screws and a drill and a screw driver. The link to all the materials and parts are in the description below or over on the website. Alright let’s get to installing, I am doing the wall tac method because this door is not finished so I do not know the final position of this device and do not want to make holes right now. The great thing about wall tac is that it does not damage walls.
 
Anyway the first thing we are going to do is play with the positioning of the device and determine where we want it to go. I was thinking about either putting it down at the bottom or at the top. But, I decided to put it at the top. The next thing I did is open the case and take the sensor cable and sort of rolled it into the enclosure to make the cable shorter, then I closed the case back up. As you can see now the wire is shorter and there is not an excess amount sticking out. After that take off the protective paper off of the adhesive on the magnetic door sensor and stick it in your desired location. Now take two pieces of wall tac and stick it on the back of the door sensor control box. Then stick the control box to the wall. Next peel off the protective backing off of the magnet or the other piece of the sensor and line it up, then stick it to the door. Great the sensor is mounted, so plug it in and test it out, see if you get a notification on your mobile device. Now that we confirmed it works in this location let’s clean up the wire. If your door is finished with trim then you can either lift up the trim and tuck it in or you can just it alongside the trim. Lucky for me the door is not finished so I lifted up the tape that was there and laid the cable in the hole, then I put the tape back. Great the cable is mostly hidden. That is it, the sensor is now complete and fully installed! 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!

MQTT Door / Window Sensor

Links: 

PyFlasher:
If you are on mac click the latest dmg file and on windows click the latest exe file