Automate your garage using a Raspberry Pi 3 B+
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.env-sample
.gitignore
LICENSE
README.md
__init__.py
garageautomation.py
requirements.txt

README.md

Overview

Automate your garage using a Raspberry Pi 3 B+

I got tired of leaving my garage opened by mistake overnight a few times. Not only that is not safe, but also it's an open invitation for someone driving by to come in and break into the house. To solve this problem, I used the new Raspberry Pi 3 B+, an IR Beam Break Sensor, a 2 Channel Relay Module, the Twilio API for SMS messaging and some Python codes. Now the garage communicates with me via SMS and I can reply back with a text to Open, Close or to check Status. If the garage stays open past 11:00 pm it will notify me via text, if I don't reply back within 5 minutes, it will automatically close it for me.

Here are the codes to make that happen. Enjoy it!

Garage Automation

Parts Needed

Requirement

  • Twilio Account for sending & receiving SMS messages.

Setup

Clone this repository in your home directory of the Raspberry Pi

git clone https://github.com/eddieespinal/GarageAutomation.git

You need to setup a virtual enviroment to install the dependancies that are required for this project.

Make sure you are inside the GarageAutomation directory

cd GarageAutomation

Install the virtualenv library

pip install virtualenv

Now create a virtual environment called venv

virtualenv venv

Now you need to activate this new virtual environment

source venv/bin/activate

Install Dependancies

There is a file called requirements.txt inside the GarageAutomation folder. Run the following command to install the dependancies listed there.

pip install -r requirements.txt

Go inside the GarageAutomation directory and create a copy of the .env-sample and name it .env

cd GarageAutomation

Make a copy of .env-sample and name it .env

mv .env-sample .env

Configurations

Edit the .env file with your own settings from Twilio. Replace YOUR_AUTH_TOKEN and YOUR_ACCOUNT_SID with your own. Also enter your own TWILIO_NUMBER, this will be used as the From number when sending messages from the Raspberry Pi.

sudo nano .env
TWILIO_ACCOUNT_SID="YOUR_ACCOUNT_SID"
TWILIO_AUTH_TOKEN="YOUR_AUTH_TOKEN"
TWILIO_NUMBER="+18009997777"
TO_NUMBER="+18006663333"

Save your changes by pressing Control+x, then Y then Enter

Edit the garageautomation.py file and configure the time you want the garage to automatically notify you and the duration before automatically closing itself.

sudo nano garageautomation.py
alarmTriggerTime = "11:00 PM"
notificationDelayInSeconds = 300 # five minutes in seconds

Save your changes by pressing Control+x, then Y then Enter

This means that the garage will notify you at 11:00 PM if the door is opened via SMS. If you don't reply back with the Close comand it will automatically close itself 5 minutes from the time you got notified.

Setup GPIO

You can change these values only if you don't want to use the same pins for the relay and the IR sensor. You can use the following image for reference.

IRSENSORPIN = 17
RELAYPIN = 18

Raspberry Pi Pinout

Automatically run this script when the Raspberry Pi boot

In order to fully automate this project, we need to make sure that when the Raspberry start it runs the garageautomation.py script. Edit the following file to do that.

sudo nano /etc/rc.local 

Copy and paste the following command at the end of this file but before exit 0.

(sleep 10; . /home/pi/GarageAutomationRaspberryPi/venv/bin/activate; python /home/pi/GarageAutomationRaspberryPi/garageautomation.py)&

Project Photos

Garage Automation

Garage Automation

Garage Automation

Garage Automation