I am trying to write a device handler where a refresh button will do a local http get and the JSON output will be used to change a label to red or green.
My sendEvent are based on the output of the JSON. How can I put the sendEvent in the refresh() method in this case?
So if the state.bri JSON output is “0” it will be the sendEvent with low value and if it is “254” it will be the the one with ok value.
Is it possible to get the JSON output in the refresh() method itself?
The HubAction command doesn’t get executed until it’s been returned from the method so the response has to be handled in the parse method.
Does the line below generate anything in Live Logging?
log.debug "Parsing '${description}'"
I’ve never seen an Import command used in a SmartApp or DTH so if the parse method is throwing an exception, try removing the import line and change the slurper declaration to;
I am parsing the JSON output to def parse(String description) so when the hubaction returns it is supposed to populate String description with the JSON output.
If I am not wrong, I remember reading somewhere that httpGet does not work with local LAN ip. I think for local LAN hubaction is required.
{“state”:{“on”:false,“bri”:0,“hue”:34111,“sat”:254,“effect”:“none”,“xy”:[0.3132,0.3288],“ct”:153,“alert”:“none”,“colormode”:“xy”,“reachable”:true},“type”:“Extended color light”,“name”:“EuropAce Climate Control”,“modelid”:“LCT007”,“manufacturername”:“Philips”,“uniqueid”:“1922029999”,“swversion”:“5.38.1.14919”}
And when I log the hubaction return I get this;
GET /api/usename/lights/1922029999 HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.8.3:80
I’m randomly guessing at this point, but does anything get logged by the parse method if you exclude the header below?
, Accept: "application/json"
I’m asking because it’s not in the example from the documentation, it wouldn’t be included when you tried it on your browser, and it doesn’t appear to be in the output generated by logging the hubaction object which makes me wonder if it was partially stripped out.
Your problem is ${description} is not in your json. Everything in your json with a " " is what you would put a ${} around. Everything after the " " is what your json is returning. So for example you could say: log.debug “result: ${resp.data.bri}”.
sendEvent(name: “your Device”, “${resp.data.bri}”)
The result of this is that your device would be set to 0.
I tried adding the query and still nothing logged from the parse method. I think I read in the documentation that query parameter is optional though.
Thanks for your help.
I changed the line to log.debug (description) and nothing was logged. I then changed it to log.debug “parsing” still nothing was logged. I think the problem is with the hubaction not returning anything so the parse method was not called?
I tried looking at some hubaction examples with GET and they seem similar. Only thing is I am hardcoding the IP and Path and not using a variable. Would that cause a problem? I wouldn’t think so right?
I agree, the problem’s not in your parse method, the problem is that the parse method isn’t getting called.
That’s why I was comparing your hubaction section against my device handler’s, but besides the things I mentioned, everything else matches so I have no idea why it’s not working.
I’m currently out of ideas so sorry I wasn’t able to help.