Help with handling Json response

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.

Thanks
Petter

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:

[YOURCHILDDEVICEID].[NAMEOFFUNCTION] (AAA, BBB, CCC)

Then add the corresponding function to your child device:

[NAMEOFFUNCTION] (json1, json2, json3)

Then you can update the child device’s attributes like normal using sendEvent.

Thank you! I will try that when I get home. Im reading upp a bit on the subject and do I have to parse the json data to objects first? Like:

def data = JSON.parse(resp.data)
nameOfFunction(data)

Yeah, my suggestion was based on your saying that you already parsed the json data in service manager.

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:

In the device handler:

def setParameters(json1) {
	log.debug "Indoor temperature: ${json1}"
}

In the service manager:

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.

  1. Be sure to include the set parameters function in the beginning Metadata of the DTH:

command “setParameters”

  1. 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)

  1. 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:

deviceID.setParameters(indoorTemp, outdoorTemp, heatingSetpoint)

  1. 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.

  2. Check out the ST documentation. It’s now a well-written and very helpful guide.

  3. Send me a PM if you still have issues.