Skip to content

Commit

Permalink
added text disarm functionality - text to twillio number
Browse files Browse the repository at this point in the history
  • Loading branch information
amaurer committed Oct 22, 2016
1 parent e2db271 commit 9b09006
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
53 changes: 49 additions & 4 deletions alarm.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
#!/usr/bin/python

import time
import yaml
import yaml, time, os, sys, subprocess
from alarmdecoder import AlarmDecoder
from alarmdecoder.devices import SerialDevice
from me.maurer.alarmdecoder.zonemapper import ZoneMapper
from twilio.rest import TwilioRestClient

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

def main():
global deactivate

# Number map of different Zones
zm = ZoneMapper('./zone-map.yml')

# used to toggle disarm message send
deactivate = False

# Load Account settings
with open("./settings.yml") as filestream:
try:
settings = yaml.load(filestream)
except yaml.YAMLError as exc:
print(exc)



class DisarmEventHandler(FileSystemEventHandler):
def on_modified(self, event):
global deactivate
# Only deactivate when file matches
if self.find_file(event.src_path) == settings["dir_watch_file"]:
#Find last line in file
line = subprocess.check_output(['tail', '-1', event.src_path])
# if you find the passcode in the line
if "Body="+settings["alarm_pass"] in line:
print("Disarming")
deactivate = True

def find_file(self, file_path):
pathArr = file_path.split("/")
return pathArr[len(pathArr)-1]





def handle_on_arm(device):
send_sms_message("Alarm Armed")

Expand Down Expand Up @@ -69,9 +95,17 @@ def send_sms_message(msg):



event_handler = DisarmEventHandler()
observer = Observer()
observer.schedule(event_handler, settings["dir_watch_path"], recursive=False)
observer.start()



try:
# Retrieve the first USB device /dev/tty.usbserial-DJ009GBR
device = AlarmDecoder(SerialDevice(interface=settings["device"]))
serialDevice = SerialDevice(interface=settings["device"])
device = AlarmDecoder(serialDevice)

device.on_zone_fault += handle_on_zone_fault
device.on_zone_restore += handle_zone_restore
Expand All @@ -84,11 +118,22 @@ def send_sms_message(msg):

with device.open(baudrate=115200):
while True:
if deactivate:
deactivate = False
print "Deactivated!"
device.send(settings["alarm_pass"] + "1")

time.sleep(1)


except Exception, ex:
print 'Exception:', ex







if __name__ == '__main__':
main()
9 changes: 9 additions & 0 deletions example_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
device: "/dev/ttyUSB0"
# device: "/dev/tty.usbserial-DJ009GBR"
twilio_account_sid: ""
twilio_auth_token: ""
twilio_numbers_to_text: ["+15553334444"]
twilio_number_from: "+15553334444"
alarm_pass: "1111"
dir_watch_path: "/var/log/"
dir_watch_file: "writefile.log"

0 comments on commit 9b09006

Please sign in to comment.