- Code: Select all
for i in range(6): # will loop 6 times with values of i set from 0 to 5
# do something
if someTerminatingConditional:
break
for i in range(6): # will loop 6 times with values of i set from 0 to 5
# do something
if someTerminatingConditional:
break
# turn off all valves and repeats up to 30 times until they are really off
for i in range(30):
indigo.iodevice.setBinaryOutput(134979129, 0, False) # "EZi08T" output 1 OFF
indigo.iodevice.setBinaryOutput(134979129, 1, False) # "EZi08T" output 2 OFF
indigo.iodevice.setBinaryOutput(134979129, 2, False) # "EZi08T" output 3 OFF
indigo.iodevice.setBinaryOutput(134979129, 3, False) # "EZi08T" output 4 OFF
indigo.iodevice.setBinaryOutput(134979129, 4, False) # "EZi08T" output 5 OFF
indigo.iodevice.setBinaryOutput(134979129, 5, False) # "EZi08T" output 6 OFF
indigo.device.statusRequest(134979129) # "EZi08T"
time.sleep(1)
ezio8t.refreshFromServer(waitUntilServerIdle=True)
binaryOutput1 = ezio8t.states["binaryOutput1"]
binaryOutput2 = ezio8t.states["binaryOutput2"]
binaryOutput3 = ezio8t.states["binaryOutput3"]
binaryOutput4 = ezio8t.states["binaryOutput4"]
binaryOutput5 = ezio8t.states["binaryOutput5"]
binaryOutput6 = ezio8t.states["binaryOutput6"]
if (not binaryOutput1) and (not binaryOutput2) and (not binaryOutput3) and (not binaryOutput4) and (not binaryOutput5) and (not binaryOutput6):
break
# turn off all valves and repeats up to 30 times until they are really off
for i in range(30):
for j in range(6):
indigo.iodevice.setBinaryOutput(134979129, j, False) # "EZi08T" output X OFF
indigo.device.statusRequest(134979129) # "EZi08T"
time.sleep(1)
ezio8t.refreshFromServer(waitUntilServerIdle=True)
binaryOutput1 = ezio8t.states["binaryOutput1"]
binaryOutput2 = ezio8t.states["binaryOutput2"]
binaryOutput3 = ezio8t.states["binaryOutput3"]
binaryOutput4 = ezio8t.states["binaryOutput4"]
binaryOutput5 = ezio8t.states["binaryOutput5"]
binaryOutput6 = ezio8t.states["binaryOutput6"]
if not (binaryOutput1 or binaryOutput2 or binaryOutput3 or binaryOutput4 or binaryOutput5 or binaryOutput6):
break
# turn off all valves and repeats up to 30 times until they are really off
for i in range(30):
for j in range(6):
indigo.iodevice.setBinaryOutput(134979129, j, False) # "EZi08T" output X OFF
indigo.device.statusRequest(134979129) # "EZi08T"
time.sleep(1)
ezio8t.refreshFromServer(waitUntilServerIdle=True)
stillOn = False
for state in ["binaryOutput1", "binaryOutput2", "binaryOutput3", "binaryOutput4", "binaryOutput5", "binaryOutput6"]:
stillOn = stillOn or ezio8t.states[state]
if not stillOn:
break
# calls indigo_irrigation.valveOn('1')
import indigo_irrigation
indigo_irrigation.valveOn('1')
"""
indigo_irrigation.py
controls EZIO8T outputs, with redundancy to accommodate its unreliability
tests each output (for on or off) and logs any errors, including number of repeat attempts
In this file you can insert any methods and classes that you define.
They will be shared by all Python scripts - you can even import the
IOM (as shown below) but if you do then you'll only be able to import
this script in Python processes started by Indigo. If you don't need
the IOM then skip the import and it'll work in any Python script
no matter where it's run from.
"""
try:
import indigo
except ImportError:
print "Attachments can only be used from within Indigo"
raise ImportError
import time
def valveOn(mWhichValve):
# turns off EZi08T outputs 1-6 and repeats until they are all off
indigo.server.log("indigo_irrigation.valveOn('"+mWhichValve+"') executing...", type="External Script")
maxAttempts = 5 # number of times repeat loops will attempt to turn on or off an exio8t output
repeatCounterOn = 0
ezio8t = indigo.devices[134979129] # "EZi08T"
for repeatCounterOff in range(maxAttempts):
indigo.iodevice.setBinaryOutput(134979129, 0, False) # "EZi08T" output 1 OFF
indigo.iodevice.setBinaryOutput(134979129, 1, False) # "EZi08T" output 2 OFF
indigo.iodevice.setBinaryOutput(134979129, 2, False) # "EZi08T" output 3 OFF
indigo.iodevice.setBinaryOutput(134979129, 3, False) # "EZi08T" output 4 OFF
indigo.iodevice.setBinaryOutput(134979129, 4, False) # "EZi08T" output 5 OFF
indigo.iodevice.setBinaryOutput(134979129, 5, False) # "EZi08T" output 6 OFF
indigo.device.statusRequest(134979129) # "EZi08T"
time.sleep(1)
ezio8t.refreshFromServer(waitUntilServerIdle=True)
binaryOutput1 = ezio8t.states["binaryOutput1"]
binaryOutput2 = ezio8t.states["binaryOutput2"]
binaryOutput3 = ezio8t.states["binaryOutput3"]
binaryOutput4 = ezio8t.states["binaryOutput4"]
binaryOutput5 = ezio8t.states["binaryOutput5"]
binaryOutput6 = ezio8t.states["binaryOutput6"]
if (not binaryOutput1) and (not binaryOutput2) and (not binaryOutput3) and (not binaryOutput4) and (not binaryOutput5) and (not binaryOutput6):
break
if mWhichValve in "123456":
# turn on valve and repeat until it is really on
if mWhichValve == "1":
stateName = ("binaryOutput1")
tTimerDuration = unicode(indigo.variables[128363799].value) # "irrigation_duration_1" value as unicode
elif mWhichValve == "2":
stateName = ("binaryOutput2")
tTimerDuration = unicode(indigo.variables[1092635302].value) # "irrigation_duration_2" value as unicode
elif mWhichValve == "3":
stateName = ("binaryOutput3")
tTimerDuration = unicode(indigo.variables[8186003].value) # "irrigation_duration_2" value as unicode
elif mWhichValve == "4":
stateName = ("binaryOutput4")
tTimerDuration = unicode(indigo.variables[780129921].value) # "irrigation_duration_2" value as unicode
elif mWhichValve == "5":
stateName = ("binaryOutput5")
tTimerDuration = unicode(indigo.variables[50403568].value) # "irrigation_duration_2" value as unicode
elif mWhichValve == "6":
stateName = ("binaryOutput6")
tTimerDuration = unicode(indigo.variables[1214967738].value) # "irrigation_duration_2" value as unicode
for repeatCounterOn in range(maxAttempts):
indigo.iodevice.setBinaryOutput(134979129, (int(mWhichValve)-1), True) # "EZi08T" output x ON
indigo.device.statusRequest(134979129) # "EZi08T"
time.sleep(1)
ezio8t.refreshFromServer(waitUntilServerIdle=True)
binaryOutput = ezio8t.states[stateName]
if binaryOutput:
indigo.variable.updateValue(126668483, value=tTimerDuration) # "irrigation_timer"
break
if (repeatCounterOff >= (maxAttempts - 1)) or (repeatCounterOn >= (maxAttempts - 1)):
indigo.server.log("indigo_irrigation.valveOn('"+mWhichValve+"') executed but exceeded maximum attempts limit! Off repeats: "+unicode(repeatCounterOff)+". On repeats: "+unicode(repeatCounterOn), type="External Script", isError=True)
indigo.actionGroup.execute(848159626) # "Irrigation Valve Error Warning"
elif (repeatCounterOff > 0) or (repeatCounterOn > 0):
indigo.server.log("indigo_irrigation.valveOn('"+mWhichValve+"') executed with some repeats. Off repeats: "+unicode(repeatCounterOff)+". On repeats: "+unicode(repeatCounterOn), type="External Script", isError=True)
else:
indigo.server.log("indigo_irrigation.valveOn('"+mWhichValve+"') executed. Off repeats: "+unicode(repeatCounterOff)+". On repeats: "+unicode(repeatCounterOn), type="External Script")
"""
mWhichValve (parameter 1) can be:
"0" (turns off all valves)
"1" (turns off all valves and turns on valve 1)
"2" (turns off all valves and turns on valve 2)
"3" (turns off all valves and turns on valve 3)
"4" (turns off all valves and turns on valve 4)
"5" (turns off all valves and turns on valve 5)
"6" (turns off all valves and turns on valve 6)
"""
Users browsing this forum: No registered users and 3 guests