Last active
January 14, 2021 22:22
-
-
Save supermitsuba/9afed9f9f91d5adb1a5138ed424f9048 to your computer and use it in GitHub Desktop.
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 threading | |
| import datetime | |
| import time | |
| import os | |
| from gpiozero import MotionSensor | |
| pir = MotionSensor(4) | |
| current_time = datetime.datetime.now() | |
| diff = datetime.datetime.now() - current_time | |
| os.system('./monitor_off.sh') | |
| def when_motion_event(): | |
| global current_time | |
| current_time = datetime.datetime.now() | |
| print(current_time, ": Motion Detected") | |
| os.system('./monitor_on.sh') | |
| def when_no_motion_event(): | |
| global current_time | |
| current_time = datetime.datetime.now() | |
| print(current_time, ": Motion stopped") | |
| def when_no_motion_trigger(): | |
| global diff | |
| global current_time | |
| diff = datetime.datetime.now() - current_time | |
| print("Seconds: ",diff.seconds) | |
| if diff.seconds > 60: | |
| os.system('./monitor_off.sh') | |
| timer = threading.Timer(31.0, when_no_motion_trigger) | |
| timer.start() | |
| def pause(): | |
| while True: | |
| time.sleep(5.5) | |
| print("starting...", current_time) | |
| pir.when_motion = when_motion_event | |
| pir.when_no_motion = when_no_motion_event | |
| timer = threading.Timer(31.0, when_no_motion_trigger) | |
| timer.start() | |
| pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment