Help with subscribe error when setting child device state


(Joe) #1

Hi all, This is kind of an extension of another thread I started, but it’s now morphed more into help with debugging than an actual idea. Let me start off by stating I had help with the writing this code, so I don’t fully understand what the subscribe part of the code is doing. I am also just beginning to understand how to use and write within smartThings, so please forgive my newbie-ness.

I have this app that creates child devices when I send something like this:
https://graph.api.smartthings.com/api/token/${state.accessToken}/smartapps/installations/${app.id}/Notify?device=window1&type=ContactSensor&state=open

The app mostly works. It creates the child device but never sets the state.

The error I get is follows:
This is what the browser returns:

{“error”:true,“type”:“java.lang.IllegalArgumentException”,“message”:“An unexpected error occurred.”}

This is what the log returns:

12:17:49 PM CST: error java.lang.IllegalArgumentException: argument type mismatch @ line 100

Line 100 is where I attempt to subscribe.

/**
 *  AT&T Digital Life Hub
 *
 *  Copyright 2014 Joe Rosiak
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
    name: "AT&T Digital Life Hub",
    namespace: "keo",
    author: "Joe Rosiak",
    description: "Interfaces AT&T Digital Life with SmartThings by using the email notifications from ATTDL.  This requires a way to run a email rule on the message body.  The rule then triggers an html call to SmartThings.  This app will also create a child device in SmartThings or Update the state of the child device if one exists.",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
	section("AT&T Sensors") {
		// TODO: put inputs here

	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"

	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"

	unsubscribe()
	initialize()
}

def initialize() {
	setupWebNotify()
}

def setupWebNotify() {
    if (!state.accessToken) {
        createAccessToken() 
    }
    // url to call from your web service
    log.trace "https://graph.api.smartthings.com/api/token/${state.accessToken}/smartapps/installations/${app.id}/Notify"
}

mappings {
    path("/Notify") {
        action: [
            GET: "webNotifyCallback"
        ]
    }
}

// url would be /Notify?device=<yourdevicename>&type=ContactSensor&state=<open or closed>
def webNotifyCallback() {
    log.trace "get: " + params

    // get the inputs from the URL
    def deviceDNI = params?.device
    def deviceType = params?.type
    def deviceState = params?.state
	log.debug "${deviceDNI} : ${deviceType} : ${deviceState}"
	// see if the specified device exists and create it if it does not exist
    def d = getChildDevice(deviceDNI)
	log.debug "d = ${d}"
    if(!d) {   
    	// convert from input device type into ST device type
        def STDeviceType = null
        if (deviceType == "ContactSensor") {
        	STDeviceType = "ATT Contact Switch"
            //STDeviceType = "Open/Closed Sensor"
        } else {
        	log.debug "Unknown Device Type"	
        }

        if (STDeviceType) {
        	// we have a valid device type, create it
        	d = addChildDevice("keo", STDeviceType, deviceDNI, null, [label:"AT&T ${deviceDNI}"])
            //d = addChildDevice("smartthings", STDeviceType, deviceDNI, null, [label:"AT&T ${deviceDNI}"])
        	log.trace "created ${d.displayName} with id $yourDeviceDNI"
        }
    } else {
        log.trace "found ${d.displayName} with id $yourDeviceDNI already exists"
    }

    if (d) {
        //subscribeAll()
        subscribe(physicalgraph.app.DeviceWrapper)
        subscribe(physicalgraph.app.AttributeWrapper, java.util.Map)
    	// we have a valid device that existed or was just created, now set the state
        log.trace "${d.displayName} = ${deviceState}"
        if (deviceState == "open") {
        	// call the open function in the device type, make sure it exists and sets the device state
        	d.open()
        } else if (deviceState == "closed") {
            log.trace "setting device state to ${deviceState}"
        	// call the close function in the device type, make sure it exists and sets the device state
        	d.close() 
        } else {
        	log.debug "unknown device state = ${deviceState}"
        }

    }
}

(Joe) #2

This was solved here: