Create a new cloud-to-cloud device

A cloud-to-cloud device communicates indirectly to SmartThings Cloud through a third-party cloud and a SmartThings Connector.

Cloud-to-cloud device

We will guide you through the steps to create your first cloud-to-cloud device.

This article demonstrates how to use Workspace to create a cloud-to-cloud light bulb. We provide a WebHook SmartApp that serves as the Connector. The [sample code] (https://github.com/SmartThingsCommunity/example-lifx-nodejs-web-connector) also uses the SmartThings API to import LIFX bulbs into your SmartThings account.

In this tutorial, we will cover:

  • SmartApp installation and configuration flow.
  • HTTP Signature verification to ensure that the incoming requests are from SmartThings.
  • Integrating with a third-party API (LIFX API, in this case).

Prerequisites

  • Node.js and npn installed (verified with npm version 4.0.5 and Node 7.4.0).
  • ngrok installed to create a secure tunnel for a globally available URL for fast testing.
  • Docker for running Redis. Alternatively, install and run Redismanually.
  • A Samsung account and the SmartThings app (currently available for Android).
  • At least one LIFX light bulb and the LIFX Mobile app (to install the light).
  • Either a LIFX Client ID and Client Secret (obtained from LIFX) or a LIFX personal API Token(generated during Connector installation).

Step 1. Set up the Connector

Use our sample Connector to enable communication between LIFX and SmartThings Cloud.

NOTE

Learn how to create your own Connector.

  1. Download the SmartThings LIFXConnector on GitHub, using steps 1-7 in the README to set up the sample.
  2. Set your OAuth configuration.
  3. Run WebHook Service.

Step 2. Create a device profile

A device profile contains the components, capabilities, and metadata (ID, name, ownership, etc.) that define a SmartThings device.

  1. Follow the steps to create a device profile.

    • Enter My Bulb as the Device profile name.
    • For the Device type, select Light.
    • Inside the main component, click Add capability and select the following capabilities:

      • Color Control
      • Color Temperature
      • Switch
      • Switch Level
        Device Profile
    • For both Dashboard state and Dashboard command, select main as a component and select Switch as a capability. Device Profile2

    1. Click SAVE.

Step 3. Create a new cloud-to-cloud device

  1. Follow the steps to create a cloud-to-cloud device in Developer Workspace.
    • Select My Bulb (created in Step 2) as the device profile. Select the device profile
  2. Set the SmartApp information for the Connector.
    • Enter a SmartApp name to represent your Connector on the SmartThings app.
    • Leave Multi instance set to Single and SmartApp type to WebHook endpoint.
    • For the Target URL paste the ngrok URL you previously copied (Step 7 of setting up the SmartThings LIFX Connector).
    • For the Scope, click on Settings , select the following scopes, and click SET:
      • r:devices:*
      • w:devices:*
      • i:deviceprofiles
      • r:schedules
      • w:schedules Connector Info1
    • Enter a Display name to represent your Connector on the SmartThings app.
  3. Click SAVE.
  4. Copy the Public Key into the config/smartthings_rsa.pub file in your server directory. Also copy the Client ID and Client Secret values into the corresponding entries in config/default.json under “Connector”.
  5. Click SELF-PUBLISH.
  6. Click on your entry in the list and select Set the device information. Copy and paste the device profile ID field into config/default.json in the "deviceProfiles": {"color": ""} entry.

Step 4. Restart your WebHook service

  1. Stop the npm server: CTRL-C.
  2. Start the server again: npm start (this ensures that the Public Key will be used to verify requests from SmartThings).

Step 5. Test your device

Test your light bulb in the SmartThings app.

  1. Make sure you enable the Developer Mode.
  2. Go to the Devices tab and add your device. After a moment you will see the light bulb. Tap on it to install it.
  3. Check your OAuth configuration.
    • If you have configured your server for OAuth with a Client ID and Client Secret from LIFX, you will be prompted to connect to the LIFX site to import your devices into SmartThings. In this case, the LIFX access token is stored for use by your app via the standard OAuth process.
    • If your server isn’t configured for OAuth (i.e. no Client ID and Client Secret) then you will be prompted to manually enter a personal access token. Generate a new token (Step 3 of setting up the SmartThings LIFX Connector) and paste the token into the “Enter your LIFX API token” field.
  4. Test your device.

NOTE

If you want to distribute the devices you create, enroll as an organization member and publish your device.

Troubleshooting

  • When installing the SmartApp, if you get the error Something went wrong. Please try to install the SmartApp again, then:
    • Make sure you restart the npm server as specified in Step 4 above. If you did not restart the npm server, you will see this error in the npm server terminal: forbidden - failed verifySignature.

More Information