Sorry to open up a "solved" thread, but have a few questions for the experts. Using this thread I successfully wrote a eight separate Python scripts that execute turning strategically selected random lights in the house in what I call "Vacation Mode."
I wrote a schedule in Indigo for Vacation Mode: I have a variable "vacationMode" which if set to true, then at sunset (randomized by plus or minus 10 minutes, eight scripts are executed in the actions list, and each script controls a light in my home will be turned on after a random time period, for a random amount of time, three times each. Here is an example of one of the eight scripts and this one is called "randomFitnessRoomLight.py":
- Code: Select all
from random import randint
iterCount = 3
dev = indigo.devices[109173275] # "Fitness Room - KPL"
while iterCount > 0:
randomDelay = randint(120, 7200)
randomDuration = randint(60, 600)
indigo.activePlugin.sleep(randomDelay)
indigo.device.turnOn(dev)
indigo.activePlugin.sleep(randomDuration)
indigo.device.turnOff(dev)
iterCount -= 1
Here are my questions:
1) I'm assuming the units are in "seconds" and that numbers like 7200 seconds are perfectly fine (this corresponds to a delay period of up to 2 hours). Is this correct?
2) If these scripts are executed every night for several days, how do they terminate or do they keep running forever even if the iteration count reaches 0 in it's countdown? Won't they fill up memory on my indigo server eventually? I guess I'm asking about garbage cleanup. When these scripts are finished doing their thing, I would like them to report to the log they are finished and quit peacefully.
3) Is there an easy way to externally kill a script once it is executing, in case I change my mind? Lets say I get home after sunset once the scripts already executed and don't want my lights turning on and off.
Thanks, I'm still very new to python. The scripts seem to be working although they are hard to test. Any thoughts?
TIA, -Al