But there has to be a device somewhere installed either manually or via the smartApp. It has a “Device Network Id” in Hex notation.
Just go into devices, to your tstat and tell me your DNI. It will not be in 192.168.100.1:80 format.
But there has to be a device somewhere installed either manually or via the smartApp. It has a “Device Network Id” in Hex notation.
Just go into devices, to your tstat and tell me your DNI. It will not be in 192.168.100.1:80 format.
Sorry, I didn’t make it clear perhaps. There’s no ‘device’, it’s just an app that talks to a thermostat over LAN.
So how are you viewing the Tstat data?
In a smartApp it’s not an issue, because somewhere in your code you are probably subscribing to an event like location, which will parse out responses from the hubaction.
However, devices don’t work that way.
The design map is that a SmartApp should be installed, and on set up it should “Discover” the devices and install devicetypes. During this install process, it will use the DNI from the discovery for the Device Network Id of the device it found.
Unfortunately, this concept doesn’t work for devices that can’t be “found” and there is no easy way to add a device manually in a SmartApp UI.
So that is why I wrote the Generic Camera Device to allow someone to create a camera without using a SmartApp to initiate the discovery process, like the SONOS, Dropcam, WeMo and others do.
Basically, I’m switching thermostat to Away mode when ST mode is Away. I don’t need a device for that.
WOW What a mess. This is seriously screwed up. Feels like the API is seriously flawed and incomplete. Makes one question the entire SmartThings Hub. Add to that the really slow and broken IDE and it has been a pain for the past 2 days to get to this point. Have been using standalone groovy and python for this same problem with less than 15 lines of code.
What can I say? I get what you pay for. ST is generous enough to provide practically unrestricted access to their cloud and allows you to run your apps on their servers for free. I challenge you to show me a better deal. 
Point is: This is supposed to be an open platform and that requires a solid API. The HubAction inside a Device driver is anything but.
@geko, do you have a working example of this? I"m trying to do a GET command but get the following error in my device type.
groovy.lang.MissingMethodException: No signature of method: script1409823233728390831521.sendHubCommand() is applicable for argument types: (physicalgraph.device.HubAction) values: [GET / HTTP/1.1
Accept: */*
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.111
]
My code:
...
private getReading() {
def httpRequest = [
method: "GET",
path: "/",
headers: [HOST: "192.168.111:80",
Accept: "*/*"
]
]
def hubAction = new physicalgraph.device.HubAction(httpRequest)
sendHubCommand(hubAction)
}
I bet you’re trying to call from device type. This code is for smart app.
I don’t get why the functions aren’t ubiquitous across both the device type and SmartApp. Thanks for the clarification.
So how do you do it from a device type? There are no examples and everything I try acts like it is sending the request but when I check my IIS logs, there is no request.
Converting IP address to Hex is easy patrick has done that and for those who want the code:
private String convertIPtoHex(ipAddress) {
String hex = ipAddress.tokenize( '.' ).collect { String.format( '%02x', it.toInteger() ) }.join()
return hex
}
private String convertPortToHex(port) {
String hexport = port.toString().format( '%04x', port.toInteger() )
return hexport
}
Interestingly has anyone been able to get an IP address from a Hostname inside device code?
I’ve just about given up with trying to make a HTTP POST / GET from the hub… I copied your code and the logs output the HubAction, which looks to be the correct, but no call is made… I have some debug lines which print out on my HTTP service which tell me when a GET / POST request are made…
The device network id are set correctly (as hex) in the device, but it still does not appear to make the call… 
I then went back to basics (with no luck), referring to the documentation http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/building-the-device-type.html:
def get() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/api/display",
headers: [
HOST: "192.168.1.130:9000"
])
log.debug result
result
return result
}
What does the response look like? St can only handle text, json and HTML. No binary or raw responses.
I return JSON from my web api. However, I have managed to get it working! Turns out I did not assign my device to a hub, so the local commands were not being sent anywhere. There was no debug info in the log output… and no mention of it in the api docs. But oh well, I managed to get local HTTP GET / POST commands working 
Took all day, but its done…
I do have a question though, it appears that whenever you call hubAction, the response always goes to def parse { }… However, is there anyway to get it to goto a different method? I may need to treat the data differently based on what comes back :S
Thanks for the reply 
It will always go to parse, but you can send it off to other functions however you need
OK, but there doesnt seem to be anyway of knowing where the request originated from?
Not directly, you may be able to set a state variable that tracks which function sent the request
Hi can someone tell me what I’m missing please? I tried a few methods but my parse function is never triggered. I am trying to pull a temperature from an ESP8266 wifi shield connected to a temperature sensor. I can see the temperature in the html when i go to the ip address in the browser.
//html
ESP8266 Temperature Sensor
Temp F: 79.25
Temp C: 26.25
//end html
// handle commands
def getTemp() {
log.debug "Executing 'getTemp'"
def ip = "192.168.1.7"
def hexIp = "C0A80107"
def port = "80"
def hexPort = "50"
def deviceNetworkId = "C0A80107:50"
device.deviceNetworkId = deviceNetworkId
log.debug "The device id configured is: $device.deviceNetworkId"
def macAddress = "A020A6107DA8"
/*def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/",
headers: [
HOST: ip
]
)
return result*/
//sendHubCommand(new physicalgraph.device.HubAction("""GET / HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))
def headers = [:]
headers.put("HOST", "$ip:$port")
log.debug "The Header is $headers"
def method = "GET"
try {
def hubAction = new physicalgraph.device.HubAction(
method: method,
path: path,
headers: headers
)
log.debug hubAction
hubAction
}
catch(Exception ex) {
log.debug "Hit Exception $e on $hubAction"
}
}
The logs are
Executing 'getTemp’
The device id configured is: C0A80107:50
The Header is [HOST:192.168.1.7:80]
GET path HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.1.7:80
Is the sendHubCommand after defining your hubAction just missing from your example?