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
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
2
You probably do.
But:
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. http://docs.smartthings.com
Did you check the SmartThings GitHub for more examples?
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!
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
The user interface to control the device and display status, data, video
Provide explicit commands to the device (or in some cases the Service Manager)
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).
2 Likes
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
4
Offside, but this may be useful information for @Jim to take note off. Changing the color theme might not be too hard.
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.
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!
From the child, you call the method directly, passing needed data. The Service Manager is the “parent”, so the call is:
parent.method(data)
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).
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!