Integrate a Blind Engine to the SmartThings Cloud


Objective

Learn how to create a SmartThings Schema connector on a Blind Engine using webhook endpoint.

Overview

SmartThings Schema is the quickest device integration method and is recommended for clouds that support OAuth 2.0. It is currently available with SmartThings app 1.7.19 or later.

In this Code Lab, you will learn how simple it is to integrate devices into SmartThings. Here, you'll learn how to integrate a Blind Engine from Brunt into SmartThings by building a SmartThings Schema connector for it.

Set up your environment

You will need the following:

To test the application, the following devices are required:

  • A mobile phone with SmartThings App
  • Blind Engine

Generate the template

Open Visual Studio Code to create a new SmartThings Schema connector template.

  1. Run the following command from the terminal:

  2. Select options for each step and generate a new template project:

    a. Select ST Schema app type (You can use arrow keys)

    b. Select c2c-blind-engine-sdc template type

    c. Specify the app name

    d. Specify the app identifier

    e. Set the app description

    f. Select the preferred linter

    g. Select the testing framework (default: Mocha)

    h. Determine whether to initialize the GIT repository

    i. Select the package manager (default: npm)

  1. Project structure should look like below (Solution Explorer window):

Implement Discovery handler

You must implement the following SmartThings interaction types:

  • Discovery: SmartThings requests a list of devices.

  • State Refresh: SmartThings requests the states of the indicated devices.

  • Command: SmartThings requests that you issue commands for the indicated devices.

First, let’s start with implementing Discovery handler by retrieving a list of devices.

Complete the blank code in discovery-handler.js file:

The interactionType of response for the Discovery request* is discoveryResponse. Replace your code with the following:


interactionType : 'discoveryResponse'

Implement State Refresh handler

Next, you should implement State Refresh handler by retrieving the device states for the indicated list of devices.

Complete the first blank code in state-refresh-handler.js file:

The correct attribute name for each capability is level. Replace your code with the following:


states.push({ 
    component: 'main',
    capability: 'st.switchLevel', 
    attribute: 'level',
    value: shadeLevel
})

Complete the second one in state-refresh-handler.js file:

The correct attribute name for each capability is windowShade. Replace your code with the following:


states.push({ 
    component: 'main',
    capability: 'st.windowShade',
    attribute: 'windowShade', 
    value: shadeStatus
})        

Implement Command handler

Finally, you should implement Command handler by triggering the commands for the list of devices.

Complete the code blank in command-handler.js file:

Replace your code with these lines:


states.push({ 
    component: 'main',
    capability: 'st.windowShade', 
    attribute: 'windowShade', 
    value: shadeValue
})

Great! You have just completed the implementation of the basic functionality of the SmartThings Schema connector.

Run Node.js app

Run the following command from the terminal:

Test the device on the SmartThings app

  1. Open SmartThings app and press the + button. Then, press Add device from the menu.

  2. Find My Testing Devices menu at the end of the brand list, and press it.

  3. Select SDC-BLIND-TEST from the list to start installation.

  4. Log in with a Brunt account:

    Brunt ID Brunt Password
    1 2019.sdc.blind1@gmail.com 1q2w3e4r5t!
    2 2019.sdc.blind2@gmail.com 1q2w3e4r5t!
    3 2019.sdc.blind3@gmail.com 1q2w3e4r5t!

    Login page looks like below:

  5. Close the connected page. The device is successfully connected and can now be controlled.

  6. Device is now ready for testing.

    The application shows the plug detail page with window shade and shade level.

You're done!

Congratulations! You have successfully achieved the goal of this Code Lab. Now, you can create a SmartThings Schema connector using a webhook endpoint by yourself! If you're having trouble, you may download this file:

Blind Engine Complete Code
(72.89 KB)