Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Created May 4, 2017 22:01
Show Gist options
  • Save akhenakh/d96bc6c46df6726cabd4f525eddc1b6f to your computer and use it in GitHub Desktop.
Save akhenakh/d96bc6c46df6726cabd4f525eddc1b6f to your computer and use it in GitHub Desktop.
Motion detection via GPIO film in h264 then upload to google drive in rpi
from gpiozero import MotionSensor
from picamera import PiCamera
from datetime import datetime
from phue import Bridge
import subprocess
b = Bridge('192.168.xxx.xxx')
b.connect()
camera = PiCamera()
camera.rotation = 180
pir = MotionSensor(4)
while True:
pir.wait_for_motion()
b.set_light(['Couch', 'Livingroom'], 'on', True)
b.set_light('Couch', 'bri', 254)
b.set_light('Livingroom', 'bri', 254)
filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
print("RECORDING", filename)
camera.start_recording(filename)
pir.wait_for_no_motion()
camera.stop_recording()
b.set_light(['Couch', 'Livingroom'], 'on', False)
print("END RECORDING")
proc = subprocess.Popen('/usr/local/bin/gdrive upload --no-progress --timeout 30 --delete -p ID_OF_PARENT_DIR ' + filename, shell=True)
mailproc = subprocess.Popen('echo "EVENT occured at home" | mail -s "MOTION DETECTED ' + filename + '" [email protected]', shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment