-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.py
More file actions
51 lines (43 loc) · 1.43 KB
/
light.py
File metadata and controls
51 lines (43 loc) · 1.43 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from lifxlan import LifxLAN
from suntime import Sun
from datetime import datetime
import pytz
import sys
LATITUDE=41.263923
LONGITUDE=13.632816
def light_on():
lifx = LifxLAN(1)
lights = lifx.get_lights()
print("\nFound {} light(s)\n".format(len(lights)))
lights[0].set_power("on")
def light_off():
lifx = LifxLAN(1)
lights = lifx.get_lights()
print("\nFound {} light(s)\n".format(len(lights)))
lights[0].set_power("off")
def schedule_light_on(cron,time):
job = cron.new(
command='/home/pi/Desktop/PycharmProjects/catDetector/venv/bin/python3.7 /home/pi/Desktop/PycharmProjects/catDetector/light.py on > /home/pi/Desktop/light_on_backup.log 2>&1')
job.minute.on(50)
job.hour.on(12)
cron.write()
def schedule_light_off(cron,time):
job = cron.new(
command='/home/pi/Desktop/PycharmProjects/catDetector/venv/bin/python3.7 /home/pi/Desktop/PycharmProjects/catDetector/light.py off > /home/pi/Desktop/light_off_backup.log 2>&1')
job.minute.on(time.minute)
job.hour.on(time.hour)
cron.write()
def get_light_status():
lifx = LifxLAN(1)
lights = lifx.get_lights()
return lights[0].get_power()
def get_times():
utc = pytz.UTC
now = utc.localize(datetime.now())
sun=Sun(LATITUDE,LONGITUDE)
return now,sun.get_local_sunset_time(),sun.get_local_sunrise_time()
if __name__== "__main__":
if sys.argv[1]=='on':
light_on()
else:
light_off()