Last active
February 19, 2020 19:00
-
-
Save amanelis/9efa85d1feed1bd546a8c1ee8f3f4bbe to your computer and use it in GitHub Desktop.
My raspberryPI python Twilio code to trigger a command / garage door
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import datetime | |
from datetime import date | |
from twilio.rest import Client | |
from subprocess import call | |
print("Garage loop, starting...") | |
client = Client('account_sid', 'account_token') | |
valid_command = ['o', 'c', 't',] | |
valid_numbers = [ | |
'+12813308004', # Give Mike Jones access | |
] | |
processed_messages = { | |
str(date.today()): [m.sid for m in client.messages.list(date_sent=date.today())] | |
} | |
print("Garage loop, listening...") | |
while(True): | |
today = date.today() | |
if str(today) not in processed_messages: | |
processed_messages[str(today)] = [] | |
messages = client.messages.list(date_sent=date.today()) | |
for message in messages: | |
b, f = message.body, message.from_ | |
if message.sid not in processed_messages[str(today)]: | |
processed_messages[str(today)].append(message.sid) | |
print("Message [{0}] received from [{1}], processing...".format(b, f)) | |
if message.body is not None and message.body.lower() in valid_command and message.from_ in valid_numbers: | |
print(" [+] authorized [{0}]".format(message.sid)) | |
call("{your garage wiringPI script to toggle the relay switch}") | |
else: | |
print(" [-] unauthorized [{0}]".format(message.sid)) | |
else: | |
continue | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment