Created
February 21, 2015 21:56
-
-
Save achterberg/6658a4dc8108bc1ba012 to your computer and use it in GitHub Desktop.
(Indigodomotics) Turn on a random light for a random duration
This file contains 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
# run as external script | |
import indigoAttachments | |
from random import randint | |
import random | |
import sys | |
import datetime | |
import time | |
indigoAttachments.specialLog("Imported the IOM to run randomlighton.py") | |
housemode = indigo.variables[1563423774] # HouseMode | |
isDaylight = indigo.variables[351661523] # isDaylight | |
iterCount = 6 | |
# Build a device list for all devices that have "#random" in their description | |
dev_list = [dev for dev in indigo.devices.iter() if "#random" in dev.description] | |
random.shuffle(dev_list) | |
while iterCount > 0: | |
for dev in dev_list: | |
if indigo.variables[1563423774].value != "occupied": | |
randomDelay = randint(600, 1800) | |
indigo.activePlugin.sleep(randomDelay) | |
if indigo.variables[351661523].value == "true" or indigo.variables[1563423774].value == "occupied": sys.exit() | |
indigo.device.turnOn(dev) | |
randomDuration = randint(600, 3600) | |
x = str(datetime.timedelta(seconds=randomDuration)) | |
indigo.server.log("Turned on " + str(dev.name) + " for " + str(x), "Random Light On") | |
indigo.activePlugin.sleep(randomDuration) | |
indigo.device.turnOff(dev) | |
if indigo.variables[351661523].value == "true" or indigo.variables[1563423774].value == "occupied": sys.exit() | |
iterCount -= 1 | |
time.sleep(1) | |
if iterCount == 0 : indigo.server.log("Random Light On script completed", "Random Light On") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment