Service Manager?


I’m working on a Project where we want to Integrate a cloud based System into SmartThings.
What I don’t understand, do I need a Service Manager and a Device Handler? And how can I use the Service Manager in the Device Handler and how can I add a Device with a Service Manager?

Thanks for helping

You probably do.


  1. Did you thoroughly read the documentation first? Community members are a helpful bunch, but the dev docs are really thorough and a critical starting point and have excellent examples.

  2. Did you check the SmartThings GitHub for more examples?

  3. Please describe your project, cloud, architecture in as much detail as possible. A cloud-cloud link is a typical scenario, but if you want help: (a) knowing the details help ensure good answers, and (b) hearing about your project is motivational! :smile:


Fully agree. Short definition: A Service Manager manages the devices and cloud-based services for the Devices (Device Handler) including, but not limited to:
a. Establishing and maintaining the cloud connection,
b. Maintaining the WiFi connection to the device (i.e., keep track of changes),
c. Provide for device installation.
d. Providing general services to the device when that is most efficient.

The Device Handler provides

  1. The user interface to control the device and display status, data, video
  2. Provide explicit commands to the device (or in some cases the Service Manager)
  3. Manage the device itself, including state, data, and user preferences.

Again, there is a good discussion in the documentation (particularly the WAN and LAN-based device discussions in the on-line edition). However, the pdf version of the documentation is impractical and virtually unreadable due to colors used in the examples.

Final comment. Think of your architecture and design first. SmartThings has a general architecture; however, your project needs a specific architecture. Uderstand where you are going and define an incremental path to get there. (This is a personal lesson-learned from going down rabbit holes on TP-LInk plugs, bulbs, and switches as well as Samsung WiFi Speakers).


Offside, but this may be useful information for @Jim to take note off. Changing the color theme might not be too hard.

1 Like

Thanks for your Answers. There is a Device that pulls the Informations from our Cloud. To get Access to the Cloud you must authorize yourself first with username and password. I have read the documentation but the problem is that it isnt really understandable how the service manager works with the device handler.

Let me speak to an example I wrote (easiest to discuss this). You can pull the device handlers and the service manager from my github site:

In my example, the Service Manager:
a. gets a token for the cloud.
b. gets the device data from the cloud (multiple devices), and installs the user selected devices.
c. Manages the token automatic update.
d. Sends update data to the device handlers.
e. Communicates with the cloud for the device handler.
The Device Handler (for each device)
a. Composes the command for the cloud.
b. Sends the data to the Service Manager for interchange with cloud.
c. Receives the cloud-returned data from the SM and then parses to update states.
d. When uninstalled, tells the service manager to delete the device from the SM database.

Yours may vary depending on a lot of factors. But this worked for my system (I have nine devices and some users have in excess of 20 devices). Mine is complicated since I use pass-through of the raw device command through the cloud (limitation of available API data). Your cloud API may have a significantly easier command structure.

PS - my total java/groovy experience started in Jan, 2017. So, my techniques are not perfect!

1 Like

Hello. Thanks, very helpful. But I got one more question. How do I use the Methods of the Servicemanager in the Device Handler?

From the child, you call the method directly, passing needed data. The Service Manager is the “parent”, so the call is:


Example (modified from real code for simplicity). Here the DH sends a command to the ServiceManager for forwarding to the Cloud. The Cloud sends the command and then returns the cloud return data to the DH (or an error message if there was a problem).

Device Handler
private sendCmdtoCloud(command){
	def deviceId = getDataValue("deviceId")
	def cmdResponse = parent.sendDeviceCmd(deviceId, command)
	String cmdResp = cmdResponse.toString()

Cloud Method:

def sendDeviceCmd(deviceId, command) {
	def cmdResponse = ""
	def appServerUrl = [URL OF AP SERVER}
	def cmdBody = [
		method: "passthrough",
		params: [
			deviceId: deviceId, 
			requestData: "${command}"
	def sendCmdParams = [
		uri: "${appServerUrl}/?token=${[CLOUD SERVER TOKEN]}",
		requestContentType: 'application/json',
		contentType: 'application/json',
		headers: ['Accept':'application/json; version=1, */*; q=0.01'],
		body : new groovy.json.JsonBuilder(cmdBody).toString()
	httpPostJson(sendCmdParams) {resp ->
		if (resp.status == 200 && == 0) {
			def jsonSlurper = new groovy.json.JsonSlurper()
			cmdResponse = jsonSlurper.parseText(
		} else if (resp.status != 200) {
			state.currentError = resp.statusLine
			cmdResponse = "ERROR: ${resp.statusLine}"
	return cmdResponse
1 Like

And how do I make it the Parent?

When you install the device from the Service Manager, the parent-child relationship is established.

Additionally, you can add a child device via the command addChildDevice() (see documentation API section in Smart Apps). Remember, a child can only have one parent and a parent is limited to 500 children!

1 Like