Smart Garage Door Opener (4)
Step 14. Check if garage door is open when it shouldn't be
Get a script to check if the garage door is open when it shouldn't be, and then send a text message. Run the following commands, which change to home directory; get the script; make the script executable and move the script to the correct directory for user scripts:
$ cd ~/.
$ wget https://raw.githubusercontent.com/dumbo25/garage-door/main/usr/local/bin/garage.py
$ chmod ug+x garage.py
$ sudo mv garage.py /usr/local/bin/garage.py
Run the command to create a cron job to run the script above every five minutes:
$ sudo crontab -e
And add the line:
*/5 * * * * sudo python /usr/local/bin/garage.py
Step 15. Add a Battery [optional]
The battery doesn't prevent brownout conditions, or act as a UPS. The microSD Card can still become corrupted.
If the house loses power, then the garage door isn't going to open.
If someone unplugs the garage door opener, then the battery allows the garage door opener to start back up.
Step 16. Add simple Raspberry Pi Fan [optional]
You may have to edit the script to make it work:
Raspberry Pi 0 physical pin 17 (3.3v) goes to Red on Fan
Raspberry Pi 0 physical pin 7 (GPIO 4) goes to black on Fan
Step 17. Create restful API [optional]
A second Raspberry Pi is required to do this Step.
Follow the link in Step 17 and return here when done. The server part of the API goes on the Smart Garage Door Opener.
On the other Raspberry Pi, edit rest_client.py
$ nano /home/pi/api/rest_client.py
and change the line starting with Server to your Smart Garager Door hostname
On the Smart Garage Door Raspberry Pi, add Garage Door APIs by running the following commands:
$ ~/.
$ wget https://raw.githubusercontent.com/dumbo25/garage-door/main/home/pi/getAPI.sh
Check that it works
On the API server, run the command:
$ python3 rest_server.py -d
On the client server, assuming the door is closed, run one of the following commands:
$ curl -X GET http://♣api-hostname♣:♣port♣/api/open
$ python3 /home/pi/api/rest_client.py -a/api/open
Step 18. Add Control via Amazon Echo
In the link above, don't tell Alexa/Echo to discover new devices
Add firewall rules to ufw to allow discovery and control by running the commands:
$ sudo ufw allow 1900/udp
$ sudo ufw allow 5070
$ sudo ufw allow 5071
In this step's link, in Step 4. Edit rpi-echo.py to do what you want, add open.py and close.py to the actions
$ edit rpi-echo.py
and change the actions line as follows:
actions = ['python /usr/local/bin/open.py', 'python /usr/local/bin/close.py']
Open corresponds to On and Close is Off.
Get the scripts, put them in the right directory and set permissions accordingly:
$ cd ~/.
$ wget https://raw.githubusercontent.com/dumbo25/garage-door/main/home/pi/getScripts2.sh
$ sudo bash getScripts2.sh
When the above is complete, run these commands to restart the service:
$ sudo systemctl stop rpi-echo.service
$ sudo systemctl start rpi-echo.service
$ sudo systemctl daemon-reload
$ systemctl | grep running | grep rpi-echo
If there are any issues with starting the script using systemd, examine the following outputs:
$ sudo journalctl -u rpi-echo.service
$ cat rpi-echo.log
$ ps aux | grep rpi-echo
There should be two items for rpi-echo
$ sudo reboot
Wait until you can ssh back in to the Raspberry Pi
If everything is working, then tell echo/alexa to discover new devices
Try it by saying:
Alexa, turn on garage door
Step 19. Add support for Alexa App
Open the Amazon app on a smart phone
Click hamburger icon or More
Click Routines
Click + to add a new routine
Click + on Enter name (close garage door) and click Next
Click + on When you say, click voice and enter: Alexa, close garage door and click Next
Click + on Add Action, select All Devices, scroll down and select Smart Home, scroll down to garage door and select on
Click save
Repeat the above for: open garage door
Wait 5 minutes or so before trying