Need help passing variables in my first DTH

I’m attempting to write my first DTH. I have to start off with letting you know I’m not a programmer in any sense of the word. I’ve just been trying to read the documentation and understand it best I can.

So what I’m trying to do is create a DTH that I can use with a simulated switch that will turn on/off a device in my current software via cloud access. My current software is Home Control Assistant from This is not the popular open source Home Assistant.

I’ve made the connection to the HCA Cloud using HttpPostJson with the proper header which includes my token for access. I can also hard code the Json body info to turn a device on and off. What I’m trying to figure out is how to pass some variables from the simulated switch that uses the DTH to the required info in the Json body.

This is the info I have to send via Json:

    "params":["Family Room-Pole Light"]

Here is what I have coded so far:

    metadata {
        definition (name: "HCA Cloud Control", namespace: "lviperz", author: "lviperz") {
    		capability "Switch"
    		command "onPhysical"
    		command "offPhysical"

    	tiles {
    		standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
    			state "Off", label: '${currentValue}', action: "switch.on", icon: "", backgroundColor: "#ffffff"
    			state "On", label: '${currentValue}', action: "", icon: "st.switches.switch.on", backgroundColor: "#79b821"
    		standardTile("On", "device.switch", decoration: "flat") {
    			state "default", label: 'On', action: "onPhysical", backgroundColor: "#ffffff"
    		standardTile("Off", "device.switch", decoration: "flat") {
    			state "default", label: 'Off', action: "offPhysical", backgroundColor: "#ffffff"
            main "switch"

    def parse(String description) {

    def on() {
    	sendEvent(name: "switch", value: "On")

    def off() {
    	sendEvent(name: "switch", value: "Off")

    def onPhysical() {
    	sendEvent(name: "switch", value: "On", type: "physical")

    def offPhysical() {
    	sendEvent(name: "switch", value: "Off", type: "physical")

    private put(toggle) {
        def toReplace = device.deviceNetworkId
    	def replaced = toReplace.replaceAll(' ',' ')

    def params = [

        uri: "",

    	headers: [
            Authorization: "Bearer Token Goes Here"

    	body: [
    		requestId: "1234-5678-9",
            group: "HCAObject",
            command: "$toggle",
            params: "$replaced"

    try {
        httpPostJson(params) { resp ->
            // iterate all the headers
            // each header has a name and a value
            resp.headers.each {
               log.debug "${} : ${it.value}"

            // get an array of all headers with the specified key
            def theHeaders = resp.getHeaders("Content-Length")

            // get the contentType of the response
            log.debug "response contentType: ${resp.contentType}"

            // get the status code of the response
            log.debug "response status code: ${resp.status}"

            // get the data from the response body
            log.debug "response data: ${}"
    } catch (e) {
        log.debug "something went wrong: $e"
    }    }

What I’m trying to figure out is how to pass Device.On or Device.Off where I have $toggle which would be from the simulated switch being turned on or off. The other one, $replaced should be populated with the simulated switch’s Device ID.

My problem is when the variables are replaced, there is a lot of unnecessary information and it is formatted from.

This is what the returned info looks like:

response data: [response:[items:, returncode:-104, command:[values:[Device.Off], bytes:[68, 101, 118, 105, 99, 101, 46, 79, 102, 102], strings:[, ], valueCount:1], params:[values:[Family Room-Pole Light], bytes:[70, 97, 109, 105, 108, 121, 32, 82, 111, 111, 109, 45, 80, 111, 108, 101, 32, 76, 105, 103, 104, 116], strings:[, ], valueCount:1], group:HCAObject]]

This is what it should look like which is when I hard code the variables:

response data: [response:[items:[0], returncode:0, command:Device.Off, params:[Family Room-Pole Light], group:HCAObject]]

Here is the body portion I have hard coded:

	    body: [
    		requestId: "1234-5678-9",
            group: "HCAObject",
            command: "Device.Off",
            params: ["Family Room-Pole Light"]

So can anyone help me pass the variables and have it formatted correctly? And please be gentle with me as I’ve already stated I’m not a programmer.