Response from HubAction

Hi all, I know there has been a few posts on this but im trying to traverse the minefield of HubAction. I understand there has been a many issues surround the use of it but I dont know if they are still relevant. There have been number of consistent people helping out but im still unable to piece together the jigsaw.

Essentially I have a bit of code and im struggling to get the response from it.

def result = new physicalgraph.device.HubAction("""${method} ${uri} HTTP/1.1\r\nHOST: ${settings.ip}:${settings.port}\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")
log.debug "Result: ${results}"

The log.debug is returning “Result: NULL” where im expecting a response from my API Server. I’m a bit unsure on where to go from here and if I can go anywhere…

1 Like

Any response from HubAction is going to go through the parse() function

try this out and see what shows up in your logs

def parse(String description){
def msg = parseLanMessage(description)
log.debug "msg: ${msg}"
log.debug "body: ${msg.body}"
log.debug “xml: ${msg.xml}”

Take a look at a some of my recent device types I did that may help


Also make sure your device’s network ID is set as ip:port in hex. That’s how ST knows how to route the data back to the right device

Thanks @kevintierney, I added the parse() method and had nothing was logged so I moved onto your next bit of advise around the devices network ID.

I have determined my hex value from the following code:

private String convertIPtoHex(ipAddress) { 
   String hex = ipAddress.tokenize( '.' ).collect {  String.format( '%02x', it.toInteger() ) }.join()
   log.debug "IP address entered is $ipAddress and the converted hex code is $hex"
   return hex


private String convertPortToHex(port) {
   String hexport = port.toString().format( '%04x', port.toInteger() )
   log.debug hexport
   return hexport

This gave me “0a5154b7:1f40”= - my api server. I have manually set when adding the device but im still not getting anything back. I read somewhere there was a bug with 10.x IP’s is this still the case?

The issue had to do with 10 converting to A when it needed to be padded with the 0 (0A), so that should be ok now

What is your port#? I noticed 1f40 converts to 8000 and you mention 800

Also, make sure you have your device assigned to your hub.

@kevintierney My mistake on the example, the webserver is 8000

@pstuart here is a screenshot of how I added the device:

Sorry, screen shot is way too small for me to read. What is the DNI? It appears you have it assigned to the hub correctly.

What should the response look like?

@pstuart DNI is: 0a5154b7:1f40

and the typical response is in json eg:
“ENABLE_ZONE”: false,
“LOCK”: false,
“ENABLE_VALVE”: false,

looks fine. The server you are trying to send from is at that is what hex 0a5154b7 is translating to.

One last thing, try to do the DNI in all upper case.

And if all else fails, try the MAC address of the server instead of IP:PORT (in hex).

I tried the DNI in upper case but it made no difference.

What is the format of the MAC. surely it will need to port as well?

MAC is all upper case without the “:” and no, you don’t need port.

I Finally got it working using the IP:Port in HEX. I tried the MAC method and noticed my device was no longer turning on/off. This was due to me testing loads of different methods of HubAction.

The one that worked for me was:
sendHubCommand(new physicalgraph.device.HubAction("""${method} ${uri} HTTP/1.1\r\nHOST: ${settings.ip}:${settings.port}\r\n\r\n""",physicalgraph.device.Protocol.LAN,"${deviceNetworkId}"))

This is what i had it set as previously, which didnt work:
results = new physicalgraph.device.HubAction("""${method} ${uri} HTTP/1.1\r\nHOST: ${settings.ip}:${settings.port}\r\n\r\n""",physicalgraph.device.Protocol.LAN,"${deviceNetworkId}")

One final question - I plan to have many devices talking to this api server, I doubt I can set them all to have the same DNI. Is there a work around for this? I can only think of having my API server listen on many ports so the DNI can be unique, but that seems a bit…

@kevintierney & @pstuart Thanks for the help so far.

Move the communication layer to a smartapps and spawn child devices from there, ala how hue connect, bridge device and hue bulbs work.

@kevintierney I wonder if you can help I downloaded your code for the wemo crockpot off git hub and added it as a smart app and it finds the device but when I select it and hit done it gives me an error java.lang.NullPointerException: Cannot get property ‘value’ on null object @ line 176 which is

		log.debug "Creating WeMo Crockpot with dni: ${selectedCrockpot.value.mac}"

I’m not even close to a program so I’m not sure what I’m missing. Do I need a device type handler as well. Thank you

Did you also install and publish the device handler as well?

I readded both files and now I get in the smartthings logs
error Device type ‘Wemo Crockpot’ in namespace ‘wemo’ not found. @ line 178

Sorry, I still had an old smartapp with the WeMo namespace on my github

Install the smart app from here

and then it should work. It has the same tierneykev namespace as the device handler

That worked perfect thank you. Now if I can only figure out how to modify this to work with my Wemo Mr Coffee.

1 Like