How is it possible to use two hubAction commands in same function?

devicetype
communitydevices

(Tom Beech) #1

I have two functions, one called GetValue and one called SetValue. They both use hubAction to perform an HTTP GET and the other a hubAction HTTP SET. If called in isolation, they work perfectly. However, I have a third function which needs to call SetValue followed by GetValue. In this instance only GetValue is ever completed.

From what I can tell, its the asynchronous nature of hubAction and its seemingly absolute reliance on the ‘parse’ callback. log lines from GetValue are present, but only the SetValue hubAction actually gets invoked.

I am unable to find anyway to make two hubActions work in a single call.

Any assistance is appreciated.


Help calling multiple hubactions from single command
(sidjohn1) #2

Nested Hub action:

  	try {
  		hubAction = [new physicalgraph.device.HubAction(
  		method: "GET",
  		path: rooPath,
  		headers: [HOST: "${settings.ip}:${settings.port}", Accept: "application/json"]
  		), delayAction(9800), api('refresh')]
  	}

private delayAction(long time) {
new physicalgraph.device.HubAction(“delay $time”)
}

Full code


(Tom Beech) #3

That worked perfectly. Thank you!! Who knew we have the ability to sleep via the smartthings hub… brilliant!


(nicolasjordankline@gmail.com) #4

Thank you both. I use the now common HubGet method, and just chained them in my X10 command:

def doX10(...) {
   // do setup
   def hubActions = [hubGet("path", true), delayAction(200), hubGet("path2", true)]
   hubActions
}

(Melinda Little) #5

I just have to say a big thank you for having figured this out and sharing. Kudos for your brilliance. Thanks to this I’ve figured out how to put a delay in front of commands to help with timing as well as stack a group of commands together, including delays between. Couldn’t have gotten it done without this. Again job very well done!!!