Hi, I’m having problems creating a simple device Handler to refresh/poll data from a HTTP get request.
The get request returns a body with a percentage value (radiator valve opening).
When I tap on the ‘refresh’ tile in my device handler, it works and I can parse the data and update the UI tile with the correct value.
The problem is when smartthings calls refresh() on it’s own (without me tapping on UI) - as the hubAction command is created but parse() is never called with data.
What is going on? I’m at a loss.
//capability "Refresh"
def refresh() {
log.debug "refresh()"
// build empty command array
def cmds = []
cmds << runCmd("0")
//return the array of hubAction commands
log.debug "refresh() cmds: $cmds"
return cmds
}
private runCmd(String varCommand) {
def host = DeviceIP
def hosthex = convertIPtoHex(host).toUpperCase()
def porthex = convertPortToHex(DevicePort).toUpperCase()
device.deviceNetworkId = "$hosthex:$porthex"
def userpassascii = "${HTTPUser}:${HTTPPassword}"
def userpass = "Basic " + userpassascii.encodeAsBase64().toString()
def DevicePostGet = "POST"
log.debug "The device id configured is: $device.deviceNetworkId"
//def path = DevicePath
def path = "/get-valve-max?cube=144F47"
//log.debug "path is: $path"
//log.debug "Uses which method: $DevicePostGet"
def body = ""
//log.debug "body is: $body"
def headers = [:]
headers.put("HOST", "$host:$DevicePort")
headers.put("Content-Type", "application/x-www-form-urlencoded")
log.debug "The Header is $headers"
def method = "GET"
log.debug "The method is $method"
def hubAction = new physicalgraph.device.HubAction(
method: method,
path: path,
body: body,
headers: headers
)
return hubAction
}
logs when called by smartthings:
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:32:18 AM: debug refresh() cmds: [GET /get-valve-max?cube=144F47 HTTP/1.1
Accept: */*
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.0.24:812
Content-Type: application/x-www-form-urlencoded
]
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:32:18 AM: debug The method is GET
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:32:18 AM: debug The Header is [HOST:192.168.0.24:812, Content-Type:application/x-www-form-urlencoded]
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:32:18 AM: debug The device id configured is: C0A80018:032C
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:32:18 AM: debug refresh()
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:31:25 AM: debug poll()
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:31:18 AM: debug refresh() cmds: [GET /get-valve-max?cube=144F47 HTTP/1.1
Accept: */*
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.0.24:812
Content-Type: application/x-www-form-urlencoded
]
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:31:18 AM: debug The method is GET
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:31:18 AM: debug The Header is [HOST:192.168.0.24:812, Content-Type:application/x-www-form-urlencoded]
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:31:18 AM: debug The device id configured is: C0A80018:032C
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:31:18 AM: debug refresh()
logs when refresh tile tapped in mobile app:
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:54 AM: debug off()
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:54 AM: info Turning heat off (demand= 0)
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug setLevel() adjusted value 0)
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug setLevel(0%)
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: info valveposition: 0%
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: info header OK 200 so update the tile
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: info msg: [index:15, mac:E83935F07D9D, ip:C0A80018, port:032C, requestId:3819b700-3823-4faf-ac3e-5bf92acd53bc, headers:[content-length:2, http/1.1 200 ok:null, connection:close, content-type:text/plain; charset=UTF-8, date:Wed, 22 Nov 2017 00:33:52 +0000], body:0%, header:HTTP/1.1 200 OK
Date: Wed, 22 Nov 2017 00:33:52 +0000
Content-Type: text/plain; charset=UTF-8
Connection: close
Content-Type: text/plain; charset=UTF-8
Content-Length: 2, status:200]
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug Parsing 'index:15, mac:E83935F07D9D, ip:C0A80018, port:032C, requestId:3819b700-3823-4faf-ac3e-5bf92acd53bc, headers:SFRUUC8xLjEgMjAwIE9LDQpEYXRlOiBXZWQsIDIyIE5vdiAyMDE3IDAwOjMzOjUyICswMDAwDQpDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9VVRGLTgNCkNvbm5lY3Rpb246IGNsb3NlDQpDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9VVRGLTgNCkNvbnRlbnQtTGVuZ3RoOiAy, body:MCU='
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug parse()
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug refresh() cmds: [GET /get-valve-max?cube=144F47 HTTP/1.1
Accept: */*
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.0.24:812
Content-Type: application/x-www-form-urlencoded
]
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug The method is GET
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug The Header is [HOST:192.168.0.24:812, Content-Type:application/x-www-form-urlencoded]
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug The device id configured is: C0A80018:032C
65c75a5a-e466-4c98-bed8-4f997511b8c9 12:33:53 AM: debug refresh()