-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightsensor.py
33 lines (27 loc) · 746 Bytes
/
lightsensor.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
#!/usr/bin/python3
# standard
import datetime
# custom
import gardentools
import light
# raspberry pi specific
import RPi.GPIO as GPIO
def main():
config = gardentools.get_config()
pin = config['light_sensor']['pin']
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.IN, GPIO.PUD_DOWN)
dark = GPIO.input(pin)
if dark:
dark = True
if config['light']['enabled'] and config['light']['frequency'] == 'when dark':
light_enabled = light.main()
else:
light_enabled = None
else:
dark = False
light_enabled = None
with gardentools.Logs('opengardener.db') as db:
db.write(dark=dark, light_enabled=light_enabled)
if __name__ == '__main__':
main()