Hi! Im new to programming but have gotten a smartapp working. The smartapp makes four API-calls with each of them requesting a different parameter. I understand this is not good and have modified it now so that it makes ONE API-call getting all of the parameters i want.
I can get the result to the device handler but I’m stuck on sorting the different parameters out of the result and define variables for them, by still just making ONE API-call.
I would be really grateful if someone could help me, with a link to info regarding this matter or something. It could be a simple matter, what do I know? I’ve tried to illustrate my goal down below.
If I understood you correctly, have the parent service manager call a function of the child device and pass that function the AAA, BBB, CCC, etc., responses as individual parameters:
Thank you! Since I’m really new to this, I can’t get this to work though, I’ve tried for hours now. And i only get "error: groovy.lang.MissingMethodException: No signature of method: java.lang.String.setParameters() is applicable for argument types: (java.util.ArrayList) values: [[199]]"
The setup is this:
httpGet(params) {resp ->
def indoorTemp = resp.data.rawValue /*Gives an integer number*/
atomicState.childDeviceID.setParameters(indoorTemp) /* atomicState.childDeviceID is set as a randomUUID*/
}
What am I doing wrong? Cant get my head around this.
Be sure to include the set parameters function in the beginning Metadata of the DTH:
command “setParameters”
The child device was previously created by the service manager app, right? I ask because I don’t understand the atomicState.deviceID.setParamters() thing or the desire to have random numbers for deviceIDs. Assuming that your service manager app had previously created the device, then you would just need to pass the variable indoorTemp by calling the desired device’s function like:
deviceID.setParameters(indoorTemp)
You need to tell the service manager how you want the json response to be parsed. Like assigning each of the desired json data to different variables. Then you can pass those multiple variables to the device DTH at once:
Check out my Hue B Smart app and DTHs on Github (repository name is infofuend/Hue_B_Smart). The app parses json data received from the Hue Hub, and then sends that data to the appropriate light using the updateStatus function in the DTHs. Try making small edits to my code. It will really help you understand how it all works.
Check out the ST documentation. It’s now a well-written and very helpful guide.