Smart Overhead Door Opener (4)

This is part 4 of the Smart Garage Door Opener

Step 4.1. 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 4.2. 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 4.3. 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 4.4. 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 4.5. 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

Step 4.7. Try it out

The project is done. Try it out and ensure it works.

References:

Raspberry Pi Garage Door Opener by quartarian

My original garage door instructable

Troubleshooting:

directories or paths

The github repository shows the directories where the files should be stored

email and text message issues

If you are having issues, then try this:

$ echo "test" | sendmail -v ♣your-gmail-account♣@gmail.com

If email is setup correctly, then you should get an email in your gmail account.

If you get an authentication failure:

You may need to lower security on your account. However, lowering security is NOT recommended. Google will send an email with a link to lower security setting.

You can switch from your current email reader to use www.gmail.com to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecu... so that your account is no longer protected by modern security standards.

I do not recommend lowering your security standards.

If you get an Authorization failure:

The most probable cause of this is that you have specified a wrong username or password for your gmail account in the /etc/ssmtp/ssmtp.conf file. Double check the values of the AuthUser and AuthPass fields.

If you get connection lost in the middle of processing:

Chances are you specified the wrong port for the Google smtp somewhere in /etc/ssmtp/ssmtp.conf or in /etc/ssmtp/revaliases.

Check the last lines of your logs. There should be some relevant error messages in there:

$ tail /var/log/mail.log

$ tail /var/log/syslog

Garage Door won’t open

If everything was working and it just stops, then try restarting. If that doesn't work, try

$ sudo shutdown -h 0

Then pull the power cord from Raspberry Pi, and then restore power. The Raspberry Pi should reboot in less than 2 minutes and everything should work fine. This is generally caused by a loss of power to a home Gateway or Wi-Fi Access Point.

GPIO

If anything goes wrong, then the best way to see what is happening is with the gpio commands:

$ gpio readall

Logs

If something goes wrong, check these logs for errors, warnings or other issues.

$ cat /var/log/messages

$ cat /var/log/syslog

$ cat /var/log/dmesg

Raspberry Pi home directory

$ pwd

/home/pi

Raspberry Pi hostname

$hostname

hostname = ♣hostname♣

Raspberry Pi IP

♣raspberry-pi-ip♣ = 192.168.1.93

SECO-LARM stops working

In the old implementation, after two years of use, the SECO-LARM stopped working. To say this correctly, the sensor pin on the Raspberry Pi stopped detecting the 3.3v input. I tried 3.3v physical pins 1 and 17, and both were still outputting 3.3v. I switched from the original sebsor pin to another pin and it started working again. So, there is nothing wrong with the SECO-LARM. The problem seems to be with the Raspberry Pi GPIO.

The is a very good post on how to test GPIO pins.

I was not sure why the GPIO pin stopped working. Here are possible reasons:

  • I have the Seco-larm sensor mounted so when the door is closed it outputs 3.3v. The garage door is closed more often then it is open. Perhaps, the GPIO pin cannot take a more-or-less constant input of 3.3v.

  • The failure coincided with a power loss, perhaps there was a power spike.

  • I did not use the Raspberry Pi's built-in resistors (the issue has not repeated since I did this)

Potential Future Changes:

  • Create iPhone app

  • Add sqlite3 database and python to store and read private data (email, address, password, etc.)

  • Use the python template for all the scripts

  • Update API

  • Add curl support

Go to the previous or next part of the smart garage door opener project