Created
January 27, 2018 22:21
-
-
Save tremby/5bd0e06e346cdcf5e04742e61d8787dc to your computer and use it in GitHub Desktop.
Sync Philips Hue light temperature with redshift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import phue | |
import re | |
import subprocess | |
import sys | |
import logging | |
logging.basicConfig() | |
redshift_output = subprocess.check_output(['redshift', '-p']) | |
for line in redshift_output.splitlines(): | |
if not line.startswith('Color temperature:'): | |
continue | |
result = re.search(r'([0-9]+)K', line) | |
if result is None: | |
print("Couldn't get colour temperature", file=sys.stderr) | |
sys.exit(1) | |
temperature = int(result.group(1)) | |
break | |
miren = float(1e6) / temperature | |
bridge = phue.Bridge('hue') | |
print("Setting lights to colour temperature %dK (%g miren)" % (temperature, miren)) | |
for light in bridge.lights: | |
if not light.on or light.colormode != 'ct': | |
print('skipping %s' % light.name) | |
continue | |
light.colortemp_k = temperature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment