-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphue_connected_commute_planner.py
71 lines (57 loc) · 2.02 KB
/
phue_connected_commute_planner.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# This is an example of how to use the upcoming events callback
from geopy.distance import distance
from phue import Bridge
from datetime import datetime, timezone
from commute_planner.main import *
from commute_planner.settings import HOME_POS, MIN_ROUTE_DISTANCE
def update_lamps(route):
global b
# check if start is at home (if not, triggering the lamps would be kinda dumb)
start_coordinates = route["description"].split("\n")[0].split(" | ")[0].split(", ")
start_coordinates = (float(start_coordinates[0]), float(start_coordinates[1]))
if distance(start_coordinates, HOME_POS).kilometers > MIN_ROUTE_DISTANCE:
return
# decide which color to set
departure_delta = datetime.fromisoformat(route["start"]["dateTime"]) - datetime.now(timezone.utc)
# cyan -> purple -> magenta -> color changing -> off
if departure_delta > timedelta(minutes=10):
# Set to cyan
b.set_light([1, 2, 3], {
"on": True,
'bri': 254, 'hue': 39675, 'sat': 240
})
elif departure_delta < timedelta(minutes=1.5):
b.set_light([1, 2, 3], "on", False)
elif departure_delta < timedelta(minutes=3):
# Set to color changing
b.set_light([1, 2, 3], {
"on": True,
"effect": "colorloop"
})
elif departure_delta < timedelta(minutes=5):
# set to magenta
b.set_light([1, 2, 3], {
"on": True,
'bri': 254,
'hue': 55844,
'sat': 254
})
elif departure_delta < timedelta(minutes=10):
# set to purple
b.set_light([1, 2, 3], {
"on": True,
'bri': 254, 'hue': 49962, 'sat': 254
})
b: Bridge
BRIDGE_IP = "192.168.0.186" # Enter the ip of your Bridge here
async def main():
global b
b = Bridge(BRIDGE_IP)
b.connect()
await asyncio.gather(
update_today_loop(update_lamps),
update_week_except_today_loop(),
update_following_weeks()
)
if __name__ == "__main__":
asyncio.run(main())