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

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

    b. Select c2c-plug-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:

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

Step 2: Implement 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 code in discovery-handler.js file:


The Device Handler type which has Switch or Energy Meter capabilities is c2c-switch-energy.

Replace your code with the following:

deviceHandlerType: 'c2c-switch-energy'

Step 3: Implement the code – State Refresh

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

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


The attribute name for each capability is switch and energy.

Replace your code with the following:

    component: 'main',
    capability: 'st.switch', 
    attribute: 'switch',
    value: response[id].power === 'on' ? 'on' : 'off'
    component: 'main',
    capability: 'st.energyMeter', 
    attribute: 'energy',
    value: parseFloat(response[id].electricityUsage.toFixed(4)), 
    unit: 'kWh'

Step 4: Implement 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.


Replace your code with the following:

if (command.capability === 'st.switch') 
    { states.push({
        component: 'main',
        capability: command.capability, 
        attribute: 'switch',
        value: command.command

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

Step 5: Run Node.js app

Run the following command from the terminal.

Step 6: 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-PLUG-TEST from the list to start installation.

  4. Log in with the Google Accounts available below:

    Google Email Password
    1 qqqq12345!
    2 qqqq12345!
    3 qqqq12345!

    Login pages are as seen below:

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

  6. Device is now ready for testing.

    The application shows the plug detail page with Power and Energy Consumption card.

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.

Smart Plug Complete Code71.77 KB