-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhue_lights.py
49 lines (37 loc) · 1.04 KB
/
hue_lights.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime, timedelta
from apscheduler.schedulers.background import BackgroundScheduler
import time, logging, os, signal
from phue import Bridge
from astral import Astral
#logging.basicConfig(level=logging.DEBUG)
#Scheduler
scheduler = BackgroundScheduler()
#Hue Stuff
b = Bridge('10.0.1.3')
b.connect()
#Sunset stuff
city_name = 'Los Angeles'
a = Astral()
a.solar_depression = 'civil'
city = a[city_name]
timezone = city.timezone
sun = city.sun(date=datetime.now(), local=True)
def turn_on():
try:
b.set_light(3,'on', True)
print('Lights On')
except:
print('Exception raised')
pass
def turn_off():
try:
b.set_light(3,'on', False)
except:
print('Exeception raised')
pass
scheduler.start()
while True:
scheduler.add_job(func=turn_on, trigger='date', next_run_time=(str(sun['sunset'] - timedelta(minutes=45))))
scheduler.add_job(func=turn_off, trigger='date',
next_run_time=(str(sun['sunrise'] + timedelta(hours=25))))
time.sleep(60)