bathroom-timer/door.py

43 lines
826 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
from gpiozero import Button, Buzzer
from time import sleep
from datetime import datetime
# https://docs.python.org/3/library/datetime.html#datetime.datetime.now
# DHT22 with an rpi
# https://web.archive.org/web/20200819162120/http://www.home-automation-community.com/temperature-and-humidity-from-am2302-dht22-sensor-displayed-as-chart/
# the door sensor
door = Button(23)
btn = Button(19)
bz = Buzzer(26)
#bz.on()
#bz.off()
def alarm():
bz.beep(0.5,0.25,8)
def doorClosed():
t = datetime.now()
print(f"{t} - door closed. LED on")
def doorOpen():
t = datetime.now()
print(f"{t} - door open. LED off")
def whenPressed():
bz.toggle()
btn.when_pressed = whenPressed
door.when_pressed = doorClosed
door.when_released = doorOpen
print("ready")
while True:
sleep(0.2)