-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsctshift.py
More file actions
executable file
·51 lines (37 loc) · 1.18 KB
/
sctshift.py
File metadata and controls
executable file
·51 lines (37 loc) · 1.18 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
#!/usr/bin/env python3
import subprocess
import os
from time import localtime
"""
A simple wrapper around xsct to compute the desired light temperature and set it.
From morning to mid afternoon: high
mid afternoon to early evening: decrease linearly
early evening til morning: low
"""
LOW_TEMP = 2500
HIGH_TEMP = 7500
def set_temperature(t):
command = ["xsct", t]
display = os.environ.get("DISPLAY", ":1")
subprocess.run(command, env={"DISPLAY": display})
def compute_temperature(morningh, midafterh, eveningh):
tm = localtime()
hour = tm.tm_hour
minutes = tm.tm_min
if morningh <= hour < midafterh:
temp = HIGH_TEMP
elif midafterh <= hour < eveningh:
temp = HIGH_TEMP - (hour + minutes / 60 - midafterh) / (
eveningh - midafterh
) * (HIGH_TEMP - LOW_TEMP)
else:
temp = LOW_TEMP
return temp
def main():
morningh = int(os.environ.get("REDSHIFT_MORNING", 8))
midafterh = int(os.environ.get("REDSHIFT_MIDAFTER", 15))
eveningh = int(os.environ.get("REDSHIFT_EVENING", 20))
temp = compute_temperature(morningh, midafterh, eveningh)
set_temperature(str(temp))
if __name__ == "__main__":
main()