I don’t think my subject explains what I am trying to accomplish well.
Essentially, I need to send two packets to my device, separately. For instance, in the “fade” command of the device, I want to send packet #1, then packet #2. Unfortunately, only the second hubaction command gets actually run (because that is what I am returning).
So, how do I send two hubactions from a single command? I tried this in the fade handler, but nothing happens.
Arg. I knew I needed to explain this better. Thanks for your interest in my issue. sendCommand is used to send raw TCP packets to a device on my network. It is executed when a user interacts with the device in the SmartThings UI (hits a button, or moves a slider).
Ok, I get it. I’m not sure about this… I’ve only ever sent one. If returning a list of them doesn’t work like it does for events then my guess is that they don’t have a way to do it. The documentation doesn’t mention anything about this either. Maybe @Jim could help?
If no proper response is given, the hub can wait for up to 20 seconds to timeout before listening for another response.
It is not a proper web socket, it is a web browser, essentially.
Best way to accomplish what you are trying to do is create a command queue and a scheduler to run until the queue is empty. Wait for a parse / response before sending the next item in the queue, etc.
I’m not so sure about this timeout topic. I have some buttons on my custom lighting device (on/off/white/red/blue, for example). I can hit these buttons and send the raw TCP commands without any issues one after the other, without waiting for a response.
The challenge here is sending two commands from within the same “button click”. SmartThings seems to only want to send one.
I’m trying to do exactly the same thing, to control X10 through an Insteon hub. This takes two messages to the hub, one to set the unit address and one to set the command.
Your sendCommand code doesn’t actually send anything. It just creates a hubAction object and returns it. When you return from the command method that is called in your deviceType (i.e. the on or off method for a switch) whatever is returned is sent to the hub. I think that if you return an array of hubCommands it will send each in turn. You can also try calling sendHubAction(hubAction) but I’m not sure this is working the way I expect
My problem is that the insteon hub needs about 500ms between calls otherwise it just ignores them. I’m trying to work out a way of getting this to happen, think it involves scheduling (as one of the other respondents suggested).
I have the same issue. I need to perform a HTTP GET to determine the state of something, then a HTTP POST in the same function. This seems impossible. I have attempted putting a wait in, but it simply will not execute the hubAction if you already called it within the same session
You can call httpGet() directly from the deviceType code, so theoretically you could make several calls before returning the hubaction (or null if you don’t need any further calls). Having said this I’m calling httpGet() within a method called by runIn() and it throws an error every time. I get: “error something went wrong: org.apache.http.conn.ConnectTimeoutException: Connect to [/] failed: connect timed out”.
That’s it, no further debug info, which isn’t terribly helpful!
It’s a shame we can’t run this code in a debugger. Even more of a shame that we can’t download the smartthings libraries into our own IDE to get name completion, compile-time checking etc.
Yes, gave up on httpGet(). It’d documented in the device driver code but doesn’t say anything about how it works - as usual Finally got it all working by returning a list of hubActions from the command call, see https://github.com/pshotton/insteon-x10-smartthings/