Thanks Jay
I'm running a script to randomly turn lights on if certain variables are true.
My issue is that when other scheduled actions simulate bedtime or leaving home (i.e. all lights turn off) and change the variables, my script often runs for one more loop rather than terminating immediately with the lights turned off. An example of the script...
- Code: Select all
#!/usr/bin/env python2.5
from random import randint
iterCount = 6
dev = indigo.devices[750911005] # "Porch Inside"
indigo.server.log("Random: Porch Script Started")
while iterCount > 0:
alarmMode = indigo.variables[1007026022] # "alarm_state"
xauto = indigo.variables[142739729] # "automated_athome"
xneed = indigo.variables[1931720860] # "need_light"
indigo.server.log("Alarm: " + str(alarmMode.value) + " Auto at Home:" + str(xauto.value) + " NeedLight:" + str(xneed.value) + " Iteration: " + str(iterCount))
if (xauto.value == "true") and (alarmMode.value == "on") and (xneed.value == "true"):
randomDelay = randint(2700, 4500)
indigo.activePlugin.sleep(randomDelay)
indigo.server.log("Random: Turning on Porch - " + str(iterCount))
indigo.device.turnOn(dev)
randomDuration = randint(180, 240)
indigo.activePlugin.sleep(randomDuration)
indigo.device.turnOff(dev)
iterCount -= 1
indigo.server.log("Random: Porch Script Complete")
Does that make sense? thanks for your help on this - much appreciated