Get Information Technology Conjecture…

Main menu

Post navigation

Garage Door Automation w/ Rev 1 Analytics

My family and I use our garage as the primary method of ingress and egress from our home. Almost daily I open the garage door using the standard wall mount garage door button, I also drive away and 30 seconds later I think to myself “did I close the garage door”. The thought of “did I close the garage door” results in one of two outcomes.

I am close enough that I can strain my neck and look back over my left shoulder to see if I closed the door.

I went in a direction that does not allow me to look back over my left shoulder to see the state of the door or I am too far to see the state of the door, this results in me turning around and heading home to appease my curiosity.

My Goal(s)

Initial goal: To implement a device that allowed me to remotely check the state of my garage door and change the state of the door remotely (over the internet). Pretty simple.

Implemented analytics add-on: Given the intelligence of the device I was building and deploying to gather door state and facilitate state changes (open | closed) I thought wouldn’t it be cool if I captured this data and did some analytics. E.g. – When is the door opened and closed, how long is it kept in this state and started to infer some behavioral patters. I implemented Rev 1 of this which I will talk about below.

Planned add-ons:

Camera with motion capture and real-time streaming.
Note: Parts for this project on order and I will detail my implementation as an update to this post once I have it completed.

My First ApproachNote: This only addressed my initial design goal above. Another reason I am glad I bagged the off-the-shelf approach and went with the maker approach.

I have automated most of my home with an ISY99i (https://goo.gl/YOklKH) and my thought was I could easily leverage the INSTEON 74551 Garage Door Control and Status Kit (http://goo.gl/Soo31V). To make a long story short this device is a PoS so it became an AMZN return. After doing more research on what was available off-the-shelf and aligning it with my goals I decided that I should build rather than buy.

The Build

Parts list:Note: Many of these parts can be changed out for similar versions.

Cardboard – You will notice my fancy mounting system in the post installation photos below.Note: From Amazon box so technically Amazon provided this as well. I may 3D print a mount at some point in the the future, if I do I will update post with CAD file.

Fork Terminal Sta-Kons (http://goo.gl/A0tdMJ)– Always make connections a little nicer (used these on the wires connected to the back of the garage door opener, you will see in the post implementation photos below).

Although below you will see my breadboard design I actually soldered and protected all final connections with heat shrink (you will see this in my post installation photos below).

Required SoftwareNote: This is not a Raspberry Pi tutorial so I am going to try to keep the installation and configuration of Raspbian and other software dependencies limited to the essentials but with enough details and reference material to make getting up and running possible.

Download Win32 Disk Imager (http://goo.gl/hz9BD)Note: This is how you will write the Raspbian Image to your 8 GB microSDHC Class 4 Flash Memory Card.Note: If you are not using Windows then Win32 Disk Imager is not an option.

Check that networking looks good by executing “ifconfig”
Note: It’s going to look good otherwise you would not have been able to ssh to the host but if you need to check from console issuing a “ifconfig” would be a good starting place. If you are having issues consult Google on Raspberry Pi wireless networking.

Follow promptsNote: Setting up a Weaved account not required. I suggest doing it just to play with Weaved (https://www.weaved.com/) but I just use dynamic DNS and port forwarding for remote access to the device. I will explain this more later in the post.

sudo update-rc.d webiopi defaults

sudo reboot

Once the system reports WebIOPi should be successfully installed and running. To test WebIOPi open your browser and open the following URL: http://YOURIPADDRESS:8000

You should get a HTTP login prompt.

Login with the default username / password: webiopi / raspberry

If everything is working you should see the following:

We now have all the software installed that will enable us to get status and control our garage door. We are not going to prep for the system for the analytics aspect of the project.

Once your account is created, login in and navigate to “my account” by clicking your account name in the upper right hand corner of the screen and selecting “my account”

Scroll to the bottom of the page and make note of or create a “Streaming Access Key”

As “pi” user from Raspberry Pi ssh session run the following command: \curl -sSL https://get.initialstate.com/python -o – | sudo bashNote: Be sure to include the leading “\”

Follow the prompts – if you say “Y” to the “Create an example script?” prompt, then you can designate where you’d like the script and what you’d like to name it. Your Initial State username and password will also be requested so that it can autofill your Access Key. If you say “n” then a script won’t be created, but the streamer will be ready for use.

OK all of of software prerequisites are done, let’s get our hardware built!

Shutdown and unplug the Raspberry Pi

The Hardware BuildNote: I used fritzing (http://fritzing.org/home/) to prototype my wiring and design. This is not required but as you can see below it does a nice job with documenting your project and also allowing you to visualize circuits prior to doing the physical soldering. I did not physically breadboard the design, I used fritzing instead.

Click on the “IN” button next to Pin 26 (GPIO 7) (big red box around it below)

You should hear the relay click and the LED on the relay should illuminate.

If this works you are in GREAT shape, if not you need to troubleshoot before proceeding.

Connect the relay to proper terminal on your garage door opener.Note: Garage door openers can be a little different so my connection may not exactly match your connections. The relay is just closing the circuit just like your traditional garage door opener button.

As I mentioned above I soldered all my connections and protected them with heat shrink but there are lots of other ways to accomplish this which I talked about earlier.

Finished Product (post installation photos)

Above you can see the wires coming from the relay (gold colored speaker wire on the right, good gauge for this application and what I had laying around)

Below you can see the connections to the two leftmost terminals on the garage door opener (I’m a fan of sta-kons to keep things neat)

OK, now that our hardware device is ready to go and connected to our garage door opener let’s power it up.

Once the system is powered up let’s login as pi and download the source code to make everything work.

Next we need to put the files in their appropriate locations. There are no rules here but you may need to modify the source a bit if you make changes to the locations.

mkdir /usr/share/webiopi/htdocs/garage

cp ./garage.html /usr/share/webiopi/htdocs/garageNote: garage.hrtml can also be places in /usr/share/webiopi/htdocs and you will not need to include /garage/ in the URL. I use directories because I am serving multiple apps for this Raspberry Pi.

mkdir ~pi/daemon

cp garagedoor_analytics.py ~/pi/daemon
Note: You will need to edit this file to enter your Initial State Access Key which we made note of earlier.

cp garagedoor_analytics.sh ~/pi/daemon

cp garagedoor_analytics_keepalive.sh ~/pi/daemon

Make required crontab entries:

sudo crontab –eNote: This edits the root crontab

You should see a line that looks like the following:#@reboot /usr/bin/startweaved.shThis is required to use Weaved. If you remember earlier I said I just use port forwarding so I don’t need Weaved so I commented this out in my final crontab file.

When you login you should see something similar to the following:Note: “Garage Door” on the left represents the bucket where all of our raw data is being streamed to.

Click on “Garage Door”

There are number of views we can explore here.

First lest check the raw data stream:
Here we see the raw data being streamed from the Raspberry Pi to our Initial State Bucket.

Next lets look at some stats from the last 24 hours.
Here I can see the state of the door my time of day, the % of the day the door was opened or closed, the number of times the doo was opened, etc…

I haven’t really started mining the data yet but I am gong to place an AMP meter on the garage door and start to use this data to determine the cost associated with use of the garage door, etc… I am thinking maybe I can do some facial recognition using the Raspberry Pi camera and OpenCV to see who is opening the door and get more precise with my analytics.

Two more item before I close out this post.

The first one being how to access the your Raspberry Pi over the internet so you can remotely check the status of your garage door and change it’s state from your mobile device. There is really nothing special about this it’s just using dynamic DNS and port forwarding.

Find a good (possibly free but free usually comes with limitations and/or aggravation) dynamic DNS service. I use a paid noip (http://www.noip.com/) account because it integrates nicely with my router, it’s reliable and I got tired of the free version expiration every 30 days.

This will allow you to setup a DNS name (e.g. – myhouse.ddnds.net) to reference your public IP address which assuming you have residential internet service is typically a dynamic address (meaning it can change).

Next setup port forwarding on your internet router to forward an External Port to an Internal IP and Port

This procedure will vary based on your router.

Remember that WebIOPi is running on port 8000 (unless you changed it) so your forwarding rule would look something like this:

The last thing is a video walk-through of the system (as it exists today):

I really enjoyed this project. Everything from the research, building and documentation was really fun. There were two great things for me. The first being the ability to engage my kids in something I love, they like the hands on aspect and thought it was really cool that daddy could take a bunch of parts and make something so useful. The second was actually having a device deployed which is extensible at a price point lower that what I have purchased an off-the-shelf solution for (understood that I didn’t calculate my personal time but the I would have paid to do the project).

My apologies if I left anything out, this was a long post an I am sure I missed something.

Looking forward to getting the camera implemented, it just arrived today so this will be a holiday project.

Great project. I am using this as my first Pi project, and its really easy to follow. As this is my first project bear with me but what GPIO’s are used if I wanted to do 2 garage doors? As it works out in my head power and ground are set but I cannot figure out which other pin will send the signal to the other channel on the relay, it looks like 17 will power the door sensor, what would be the other pin that would require the 10k resistor? Thanks for any help.