Creating custom capabilties for schema devices
Using the SmartThings CLI and Developer Workspace
We are going to create a Cloud Connected Device using Schema and webhooks. Our base device will be a basic switch.
The first part of this tutorial will cover create the connector, oAuth server, and adding the Switch to SmartThings. The second part of the tutorial will cover adding a custom capability to this new device.
- Samsung Account
- Developer Workspace Access
- Developer Mode Enabled
- Glitch Account
- Text File
Step 1: Remix this Glitch account (connector)
Set the values in the
.env-exampleas a guide.
Once the remixed app is up and running copy its URL to your text file.
Register the webhook url in SmartThings Developer Workspace and deploy it for testing.
Step 2: Remix this Glitch account (OAuth)
- Edit the
.envfile to set your own client ID and secret, for example:
EXPECTED_CLIENT_ID="somerandomvalueyouchoose" EXPECTED_CLIENT_SECRET="anotherrandomvalueyouchoose" AUTH_REQUEST_PATH="/oauth/login" ACCESS_TOKEN_REQUEST_PATH="/oauth/token"
Step 3: Run each of your newly remixed apps in their own browser window.
You should now have three browser windows open.
- Developer Workspace
- Remixed Connector
- Remixed oAuth Server
Step 4: Register in the developer workspace
Name your Connector
Click Register App In the Cloud Connector Box
Click Webhook Endpoint
Enter your connector URL
Now Move to the oAuth app tab from Step 2.
Create a Client ID and Secret in the .env file
Back in the workspace these are the ID and Secret you will use in the form.
"Client ID" = the client ID you created in step two "Client Secret" = the client secret you created in step two "Authorization URI" = your-glitch-project.glitch.me/oauth/login "Token URI" = your-glitch-project.glitch.me/oauth/token
Edit your catalog entry. NOTE your image must be 240x240px
WARNING - You need to copy the values from the screen
Edit the .env file for your connector app, using the copy button from this screen and copy the Client ID and Client Secret to their fields.
Click Go To Project Overview
Click Deploy to Test
Click Got It
Step 5: Create Your Starter Device Profile
Choose Option 2
Add a Device Profile
Create a new one
On this screen
Give your profile a name and description
Select “Switch” for the Device Type
Enter a random string for the Vendor ID
Click Add Capability
Find the Switch Capability, click add and close the window.
Set the State to “Switch”
Set the Action to “Switch”
Click Create Device Profile
On the following screen copy your “Device Profile ID”
Step 6: Edit your connector.js file on the connector app tab
Step 7: Confirm that you can install this device in your mobile app
Put the SmartThings mobile app in developer mode and tap the “+” button at the top to add a device. Scroll down to My Testing Devices tap on it, and select your connector. Complete the OAuth login process and return to the Devices page. You will be prompted to complete the integration and your device will be added to the room.