Integrate a Smart Plug to the SmartThings Cloud


Learn how to create a SmartThings Schema connector on a Smart Plug using webhook endpoint.


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 Smart Plug from Dawon 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-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)

  3. 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 to 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 Device Handler type which has Switch or Energy Meter capabilities is c2c-switch-energy.

Replace your code with the following:

deviceHandlerType: 'c2c-switch-energy'

Implement State Refresh handler

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 correct 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'

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 the following:

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

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-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.

    Here, you can see a Power button to turn the plug on or off, and an Energy Consumption meter measured in Wh.

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:

Smart Plug Complete Code
(71.77 KB)