Python - introduce script delay

Posted on
Fri Oct 25, 2019 12:07 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Python - introduce script delay

My script first executes condition device on/off, then reports the action with an email. I think the email is not reflecting the change in the device status, so I am trying to add a short delay. The python script syntax I'm finding on the internet is not working:
Code: Select all
import time
time.sleep(5)

I also tried
Code: Select all
indigo.server.getTime()
getTime.sleep(5)
Time.sleep(5)

and, once again, my guess and check has come up with nothing.
Suggestions?

Posted on
Fri Oct 25, 2019 12:09 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python - introduce script delay

Post the whole script, please. Your first code fragment is correct, so if it's not working there's something else going on. Also, be aware that Indigo will kill an embedded script that takes 10 sec (I think) or more to run.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Oct 25, 2019 12:43 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python - introduce script delay

Error message - 'no module named time' at line 3
The delay is at line 95

Code: Select all
season = indigo.variables[325456157].value
hseOcc = indigo.variables[612296111].getValue(bool)
import Time
# now = indigo.server.getTime()

# get the trigger values (trigXXX: abbreviation for FD low point trigger)
trigHsmp = indigo.variables[658575084].getValue(int) #htr sump COLD threshhold
OkHsmp = indigo.variables[1115411517].getValue(int) #htr sump OK
trigHtWtr = indigo.variables[295376955].getValue(int) #htWtrTank COLD threshhold
OkHtWtr = indigo.variables[154728201].getValue(int) #htWtrTank OK
trigLrm = indigo.variables[1086851778].getValue(int) #livingRm COLD threshhold
OkLrm = indigo.variables[711165647].getValue(int) #livingRm OK
trigStWtr = indigo.variables[25559805].getValue(int) #streetWater COLD threshhold
OkStWtr = indigo.variables[483412678].getValue(int) #streetWater OK
trigUpStrs = indigo.variables[840732144].getValue(int) #upstairs COLD threshhold
OkUpStrs = indigo.variables[63463463].getValue(int) #upstairs OK
trigWcab = indigo.variables[415421705].getValue(float) #wineCabinet COLD threshhold
OkWcab = indigo.variables[364969593].getValue(float) #wineCabinet OK
trigOutside = indigo.variables[680985657].getValue(int) #outside COLD threshhold
OkOutside = indigo.variables[78723147].getValue(int) #outside OK
trigCrwlSpc = indigo.variables[427855415].getValue(int) #crawlSpace COLD threshhold
OkCrwlSpc = indigo.variables[1756484536].getValue(int) #crawlSpace OK
statSetPt = indigo.variables[453519410].getValue(int) #stat set point (from var, not stat)

# get the current temperatures (xxxC: abbreviation for space temp)
dev = indigo.devices[647163782] #street water
stWtrC = int(dev.states["temperature"])

dev = indigo.devices[895358553] #wine cabinet
wineCabC = int(dev.states["temperature"])

dev = indigo.devices[883519697] #living room
lrC = int(dev.states["temperature"])

dev = indigo.devices[634066077] #upstairs
upStrsC = int(dev.states["temperature"])
 
dev = indigo.devices[1969337208] #outside
outC = int(dev.states["temperature"])

dev = indigo.devices[892742387] #hot water tank
htWtrC = int(dev.states["temperature"])

dev = indigo.devices[1386749935] #heater sump
sumpC = int(dev.states["temperature"])

dev = indigo.devices[46322275] #crawl space
crwlSpcC = int(dev.states["temperature"])

# verify that the variables have been imported properly
indigo.server.log(" season: {}".format(season))
indigo.server.log(" trigOutside: {}".format(trigOutside))
indigo.server.log(" outC: {}".format(outC))
indigo.server.log(" trigCrwlSpc: {}".format(trigCrwlSpc))
indigo.server.log(" crwlSpcC: {}".format(crwlSpcC))
indigo.server.log(" trigCrwlSpc: {}".format(trigCrwlSpc))
indigo.server.log(" lrC: {}".format(lrC))
indigo.server.log(" trigUpStrs: {}".format(trigUpStrs))
indigo.server.log(" upStrsC: {}".format(upStrsC))
indigo.server.log(" trigHsmp: {}".format(trigHsmp))
indigo.server.log(" sumpC: {}".format(sumpC))
indigo.server.log(" trigHtWtr: {}".format(trigHtWtr))
indigo.server.log(" htWtrC: {}".format(htWtrC))
indigo.server.log(" trigWcab: {}".format(trigWcab))
indigo.server.log(" wineCabC: {}".format(wineCabC))
indigo.server.log(" trigStWtr: {}".format(trigStWtr))
indigo.server.log(" stWtrC: {}".format(stWtrC))

# proceed with the if/then turn off heat for anything that is OK (> FD OK test) w AG
if stWtrC > OkStWtr:
   indigo.actionGroup.execute(358770212) #stWtr tape off
if wineCabC > OkWcab:
   indigo.actionGroup.execute(955423681) #wine can htr off
if sumpC > OkHsmp:
   indigo.actionGroup.execute(172000814) #htr sump tape off
if not hseOcc:
   if lrC > OkLrm or upStrsC > OkUpStrs:
      indigo.actionGroup.execute(431011597) #htr 5C
   if htWtrC > OkHtWtr:
      indigo.actionGroup.execute(460903989) #htWtr off
      
# next, proceed with the if/then turn on heat for anything that is cold (fails FD test) w AG
if season == "winter":
   if lrC < trigLrm or upStrsC < trigUpStrs:
      indigo.actionGroup.execute(1307638528) #htr 7, cntr, main water off
   if sumpC < trigHsmp:
      indigo.actionGroup.execute(1808251937) #htr sump tape on, cntr
   if htWtrC < trigHtWtr:
      indigo.actionGroup.execute(599509902) #htWtr On, cntr
   if stWtrC < trigStWtr:
      indigo.actionGroup.execute(90585841) #stWtr tape on, cntr, water off
   if wineCabC < trigWcab:
      indigo.actionGroup.execute(1406401903) #wine can htr on, cntr

#last, send email notifications f(FD condition)
   time.sleep(5) #allow time for devices to switch on as necessary before reporting their status
   if (lrC < trigLrm or \
      upStrsC < trigUpStrs or \
      crwlSpcC < trigCrwlSpc or \
      outC < trigOutside or \
      sumpC < trigHsmp or \
      htWtrC < trigHtWtr or \
      stWtrC < trigStWtr or \
      wineCabC < trigWcab ):
         indigo.actionGroup.execute(966172245) #if any cond faile, sends FD email

#   if lrC > trigLrm:
#      indigo.actionGroup.execute(1279658637) #elephant light ON autoOFF

   elif (outC > OkOutside):
      indigo.actionGroup.execute(1538967727) #not cold email

   else:
      indigo.actionGroup.execute(963098824) #all temps ok email




Posted on
Fri Oct 25, 2019 12:50 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python - introduce script delay

This:

Code: Select all
 import Time


should be:

Code: Select all
 import time


Python is case sensitive.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 14 guests