I am learning the ins & outs of groovy and have a couple device types of my own running and successfully muddled together some other peoples apps. I’m trying to write a SmartApp that calls an outside REST API ( http://thisfancyapi.com/query?key=MYKEY¶m1=yes¶m2=no ) which gives me a JSON response.
I have poured through the forums and the documentation. Being new to REST and groovy I’m hitting a big hurdle on how to call my httpPost handler (based on time of day) and how to parse the JSON elements from the response.
I just need to know how to parse out elements like realTime value to use in the app. "realTime":943 represents trip time in seconds that I need to do a calculation based on.
I dunno as I don’t know all the classes Groovy/SmartThings may support. So is 943 supposed to evaluate to 9:43 AM? If so you might try the timeToday() function… but I think it wants to see a colon between hours and minutes.
no 943 is an integer in seconds, but i have another time value that is formatted as 00:16:30 that I would like to be recognized as time.
Also when requesting an input type of time in ST it appears to pass it as a string…its becoming problematic. I want to check that a time is between time A and time B given by the user.
this:
section("Expected Arrival Time:"){
input "arrivalTime", "time", title: "When?"
section("Begin Checking At:"){
input "checkTime", "time", title: "When?"
}
def now = new Date().format("HH:mm:ssZ")
log.debug "Now is = ${now}"
log.debug "Arrival Time is = ${arrivalTime}"
log.debug "Check Time = ${checkTime}"
gives me this:
debug Check Time = 2014-06-02T13:00:00.000-0700
debug Arrival Time is = 2014-06-02T14:00:00.000-0700
debug Now is = 20:33:42+0000
hard to compute this
if(now > arrivalTime && now < checkTime){
checkTrafficHandler()
}
I know groovy has some awesome time conditionals, I just havent gotten there yet.
groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: () values: []
Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), take(int), any(groovy.lang.Closure) @ line 124