Pi-files: Doorbell alert with pushmessage and mail with webcam footage
import time
from time import sleep, localtime, strftime
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) #alternative is GPIO.BCM (Broadcom names)
#set pin 11 as input
GPIO.setup(11, GPIO.IN) #Input: doorbell (relay)
push_user = ‘yyy’
conn = httplib.HTTPSConnection(“api.pushover.net:443”)
conn.request(“POST”, “/1/messages.json”,
urllib.urlencode({“token”: push_token,
“user”: push_user,
“message”: text,}),
conn.getresponse()
The main loop checks for the GPIO input regularly. I added a tiny bit of delay (sleep) to relieve the CPU. When the doorbell is pressed, it takes the current date and time and adds that to the push message.
while 1:
sleep(0.1) #relieves CPU load big time!
#if doorbell is pressed…
if GPIO.input(11):
#determine date/time and add to message
timestr_date = strftime(“%a %d %b %Y”, localtime())
timestr_time = strftime(“%H:%M:%S”, localtime())
mess = “Doorbell pressed on {}, {}.”.format(timestr_date,timestr_time)
print “\n”
print mess
push(mess)
When this all worked it was time to extend the doorbell alert feature. Not only I want to know that there is someone at the door, I also would like to know who was at the door, especially when I am not at home. I added a Logitech C270 webcam to the setup to capture snapshots and a short movie.