-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotion-monitor.py
38 lines (31 loc) · 1.04 KB
/
motion-monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from gpiozero import MotionSensor
from time import sleep
import datetime
from twilio.rest import Client
import subprocess
ACCOUNT_SID = os.environ['TWILIOSID']
AUTH_TOKEN = os.environ['TWILIOTOKEN']
client = Client(ACCOUNT_SID, AUTH_TOKEN)
toNum = os.environ['CELLNUMBER'] #nope!
fromNum = os.environ['TWILIONUMBER']
def send(txtbody):
client.messages.create(
to=toNum,
from_=fromNum,
body=txtbody
)
if __name__ == '__main__':
pir = MotionSensor(4)
while True:
if pir.motion_detected:
theTime = datetime.datetime.now().time()
message = "Motion detected! " + str(theTime)
print(message)
subprocess.call(["python3","/home/neil/raspi-home-monitor/monitor-exec.py", "-v"])
try:
send(message)
except:
print("Error sending message")
# subprocess.call(["ssh","neil@remotehost", "python3 /home/neil/raspi-home-monitor/monitor-exec.py -v"])
sleep(10) #sleep for 30 seconds to avoid repeated alarms