Skip to content

Instantly share code, notes, and snippets.

@JGaudette
Last active July 27, 2019 01:58
Show Gist options
  • Save JGaudette/8ad0bd26acdb3c0d289eef4326abcc15 to your computer and use it in GitHub Desktop.
Save JGaudette/8ad0bd26acdb3c0d289eef4326abcc15 to your computer and use it in GitHub Desktop.
Automatically dim the motion-sensor lights between 8pm and 6am
import datetime
import time
import flux_led
import sys
def scanAndSet():
lightlevel = 100
dt = datetime.datetime.now()
if dt.hour < 6 or dt.hour >= 19:
#if dt.hour > 6 and dt.hour < 20:
lightlevel = 9
scanner = flux_led.BulbScanner()
scanner.scan(timeout=10)
bulb_info_list = scanner.getBulbInfo()
sys.stdout.write(str(len(bulb_info_list)))
sys.stdout.flush()
for info in bulb_info_list:
print "id: ", info["id"]
# Skip the non-hallway lights. Should switch this around and whitelist the hallway instead
if info["id"] in ["C44F338FE93C", "840D8E6AE41B", "840D8E69C6E9"]:
print "Skipping ..."
continue
try:
bulb = flux_led.WifiLedBulb(info['ipaddr'])
bulb.setWarmWhite(lightlevel)
print(str(info))
print datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), "set bulb", info['ipaddr'], "to level", lightlevel
except Exception as e:
print("Unable to connect to bulb at [{}]: {}".format(info['ipaddr'],e))
continue
starttime = time.time()
while True:
scanAndSet()
time.sleep(30.0 - ((time.time() - starttime) % 30.0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment