Development

Step 1: Generating 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 finish generating template:

    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)

    j. Finish creating a new template project

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


Step 2: Implementing the code – Discovery

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.

[Answer]

The interactionType of response for the Discovery Request is discoveryResponse.

Replace your code with the following:

interactionType : 'discoveryResponse'


Step 3: Implementing the code – State Refresh

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.

[Answer]

The 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 code blank in state-refresh-handler.js file.

[Answer]

The attribute name for each capability is windowShade.

Replace your code with the following:

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


Step 4: Implementing the code – Command [Advanced]

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

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

[Answer]

Replace your code with below lines:

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

Great! We have just completed the implementation of the basic functionality of the ST Schema Connector. Right now the application can be run.

Step 5: Running Node.js app

Run the following command from the terminal.


Step 6: Testing 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 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. 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 activity. Now, you can create a SmartThings Schema Connector using a Webhook endpoint by yourself! But, if you're having trouble, you may check out the link below.

Blind Engine Complete Code72.89 KB