[ANSWERED]: timeout for script needed

Posted on
Wed Oct 22, 2014 7:12 pm
esprits300 offline
Posts: 49
Joined: Apr 29, 2012

[ANSWERED]: timeout for script needed

hello, i have a fairly simple question. i am using the api for pinging insteon devices and i have the below script I've written. all it does is "ping" instead devices and sets 2 variables, one with true/false, the other with a numeric value. the script actually works except when the device is down. it just hangs. i wanted to put a hard break after 3 seconds and just return false/0 to the variables Im using. i looked into MANY ways to do this but none worked. I'm NOT a coder so this is probably pretty basic for someone! i hope :) thank you in advance! I've been working on getting something like this working for a long time and I'm soooo close now....



hvacPing = indigo.variables[7055203]
hvacResponse = indigo.variables[808718]
dev = indigo.devices[240906]
result = indigo.device.ping(dev, suppressLogging=True)
if result["Success"]:
indigo.variable.updateValue(hvacPing,"true"), indigo.variable.updateValue(hvacResponse,"%.3f" % (result["TimeDelta"]/1000.0))
else:
indigo.variable.updateValue(hvacPing, "false"), indigo.variable.updateValue(hvacResponse,"0")

Posted on
Thu Oct 23, 2014 9:01 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: timeout for script needed

Unfortunately, there is no way to specify a timeout value for that method. It should timeout on its own eventually (I think 60 seconds) at which point an exception will probably be thrown you can catch. But it won't be possible to, via python, specify a custom timeout value.

Image

Posted on
Fri Oct 24, 2014 8:44 am
esprits300 offline
Posts: 49
Joined: Apr 29, 2012

Re: [ANSWERED]: timeout for script needed

Thanks for the reply! i was able to fix it by using the below code BUT it acts erratic. it works 80% of the time. i have no idea why but sometimes it reports them down even though they are up. its like the except: is being ignored... either way, ill take it. i have 5 devices i poll every 3 minutes and its mostly accurate.... i was thinking about putting a setting in that only shows down if reported down 2 times in a row, maybe that will make it 95% reliable instead of 70 or 80%
Code: Select all
# HVAC
hvacPing = indigo.variables[4903]
hvacResponse = indigo.variables[80718]
hvacdev = indigo.devices[2906]
from threading import Timer
import thread, time, sys
def timeout():
    thread.interrupt_main()
def main1():
      hvacresult = indigo.device.ping(hvacdev, suppressLogging=True)
      indigo.variable.updateValue(hvacPing,"true"), indigo.variable.updateValue(hvacResponse,"%.3f" % (hvacresult["TimeDelta"]/1000.0))
      return 
      time.sleep(1)
try:
    Timer(4, timeout).start()
    main1()
except:
   indigo.variable.updateValue(hvacPing, "false"), indigo.variable.updateValue(hvacResponse,"0")

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests