{"id":18695349,"url":"https://github.com/smartthingscommunity/st-schema-callback-example-js","last_synced_at":"2026-07-04T22:31:43.021Z","repository":{"id":90221958,"uuid":"195087463","full_name":"SmartThingsCommunity/st-schema-callback-example-js","owner":"SmartThingsCommunity","description":"ST Schema virtual device example with proactive state updates","archived":false,"fork":false,"pushed_at":"2021-10-05T17:40:07.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-26T22:36:12.825Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SmartThingsCommunity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-07-03T16:04:57.000Z","updated_at":"2021-11-21T17:34:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"b4a81186-8abd-4e6f-ab12-cabd6b20ebd9","html_url":"https://github.com/SmartThingsCommunity/st-schema-callback-example-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SmartThingsCommunity/st-schema-callback-example-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fst-schema-callback-example-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fst-schema-callback-example-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fst-schema-callback-example-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fst-schema-callback-example-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SmartThingsCommunity","download_url":"https://codeload.github.com/SmartThingsCommunity/st-schema-callback-example-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fst-schema-callback-example-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35138074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T11:14:40.960Z","updated_at":"2026-07-04T22:31:42.972Z","avatar_url":"https://github.com/SmartThingsCommunity.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ST Schema Callback Example\n\nThis application builds on the [ST Schema Simple Example](https://github.com/SmartThingsCommunity/st-schema-simple-example-js)\nto all proactive state callbacks. Proactive state callbacks update the SmartThings cloud when a\ndevice changes state due to physical events or through control from another application. \nIn these cases calls the SmartThings cloud rather than just responding to requests. To do so\nit needs an access token, which is obtained by adding a _callbackAccessHandler_ to accept \nand access code and request access and refresh tokens from SmartThings.\n\n. The application built using the\n[ST Schema SDK for NodeJs](https://github.com/SmartThingsCommunity/st-schema-nodejs) and \n[Express](https://www.npmjs.com/package/express) web framwork. This example creates a single simulated dimmer device\nnamed _Test Dimmer_. The state of the dimmer is saved in memory to keep the\nimplementation as simple as possible, so restarting the server will reset it's\nswitch status to 'off' and switch dimmer level to 100%. In addition to handling ST schema \nrequest the app exposes an endpoint to control the device with HTTP requests, so that the\nproactive state callbacks can be tested\n\nNote that ST Schema requires your cloud application to support [OAuth 2](https://oauth.net/2/) for authentication.\nThis example does not include an OAuth server, but it does include instructions for\nremixing a [Glitch dummy OAuth server](https://glitch.com/~st-dummy-oauth-server) to handle that part of the login process\n\n## Files\n\n- connector.js -- The ST Schema connector app built with the [st-schema](https://www.npmjs.com/package/st-schema) SDK\n- index.js -- An [AWS Lambda](https://aws.amazon.com/lambda/) handler that hosts the connector.\n- server.js -- An [express](https://www.npmjs.com/package/express) web server that hosts the connector\n\n## Getting Started\n\n### Running locally\n\n#### Prerequisites\n\n- [Node.js](https://nodejs.org/en/) and [npm](https://www.npmjs.com/) installed\n- [ngrok](https://ngrok.com/) or similar tool to create a secure tunnel to a publically available URL\n- A [Samsung Developer Workspace account](https://smartthings.developer.samsung.com/workspace/)\n- The SmartThings mobile app (available from the [iOS App Store](https://apps.apple.com/us/app/smartthings/id1222822904)\nor [Google Play Store](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect))\n\n#### Instructions\n\n1. Clone [this project](https://github.com/SmartThingsCommunity/st-schema-callback-example-js)\n\n1. CD into the project directory and run `npm install`\n\n1. Copy `.env-sample` into a file named `.env` and change the `ACCESS_TOKEN_PREFIX` value some other string so that only\nyou can access your server. \n\n1. Start the server with `node server.js`\n\n1. Start ngrok to tunnel traffic to your server URL and port (`localhost:3000`).\n\n1. Register the webhook url in SmartThings Developer Workspace and deploy it for testing.\n\n1. Install the SmartThings mobile app from the [iOS App Store](https://apps.apple.com/us/app/smartthings/id1222822904)\nor [Google Play Store](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect),\nlog in with the same email address and password used for your developer workspace account, and \ncreate a location (if you have not already done so)\n\n1. Put the SmartThings mobile app in [developer mode](https://smartthings.developer.samsung.com/docs/guides/testing/developer-mode.html) and tap the \"+\" button at the top to\nadd a device. Scroll down to _My Testing Devices_ tap on it, and select your connector. Complete\nthe OAuth login process and return to the Devices page. You should be prompted to assign\na device named _Test Dimmer_ to a room. \n\n### Running in Glitch\n\n#### Prerequisites\n\n- A [Glitch](https://glitch.com/about/) account\n- A [Samsung Developer Workspace account](https://smartthings.developer.samsung.com/workspace/)\n- The SmartThings mobile app (available from the [iOS App Store](https://apps.apple.com/us/app/smartthings/id1222822904)\nor [Google Play Store](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect))\n\n#### Instructions\n\n1. Remix the [st-schema-callback-example](https://glitch.com/edit/#!/st-schema-callback-example) project.\n\n1. Set the values in the `.env` file using `.env-example` as a guide. \n\n1. Once the remixed app is up and running copy its URL.\n\n1. Register the webhook url in SmartThings Developer Workspace and deploy it for testing.\n\n1. Install the SmartThings mobile app from the [iOS App Store](https://apps.apple.com/us/app/smartthings/id1222822904)\nor [Google Play Store](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect),\nlog in with the same email address and password used for your developer workspace account, and \ncreate a location (if you have not already done so)\n\n1. Put the SmartThings mobile app in [developer mode](https://smartthings.developer.samsung.com/docs/guides/testing/developer-mode.html) and tap the \"+\" button at the top to\nadd a device. Scroll down to _My Testing Devices_ tap on it, and select your connector. Complete\nthe OAuth login process and return to the Devices page. You should be prompted to assign\na device named _Test Dimmer_ to a room. \n\n## Configuring the Dummy OAuth Server\n\nST Schema connectors require an OAuth2 connection journey. Since this example \napp does not include OAuth support you must use some other server to complete\nthat journey. It can be any server supporting OAuth2 as long as it is configured\nwith the same client ID and client secret as the ST Schema connector you registered\nin the Developer Workspace. For convenience we've provided a dummy OAuth server\nthat accepts any username and password and can be configured with your client ID and\nsecret.\n\n1. Remix the [st-dummy-oauth-server](https://glitch.com/~st-dummy-oauth-server) project\n\n2. Edit the `.env` file to set your own client ID and secret, for example:\n```\n  EXPECTED_CLIENT_ID=\"somerandomvalueyouchoose\"\n  EXPECTED_CLIENT_SECRET=\"anotherrandomvalueyouchoose\"\n  AUTH_REQUEST_PATH=\"/oauth/login\"\n  ACCESS_TOKEN_REQUEST_PATH=\"/oauth/token\"\n```\n\n## Testing the device\n\n### From the SmartThings mobile app\n\nTap the _Test Dimmer_ device icon in the main devices view and it should turn on and off. You should see ST Schema requests\nand responses logged to the console. Remove the `.enableEventLogging(2)` line from `connector.js` to stop these\nmessages. Go into the detail view of the device to see the brightness control. Sliding this control will also \nresult in calls to your connector and messages logged to the console.\n\n### Proactive state testing\n\nYou can post commands to the `http://localhost:3000/command` endpoint (or your ngrok URL) to control\nthe device and send proactive state updates to SmartThings. To test this behavior open the SmartThings\nmobile app to show you device and post a command like the device on or off:\n```\ncurl -H 'Content-Type:application/json' \\\n     -d '{\"name\": \"switch\", \"value\": \"on\"}' http://localhost:3000/command\n```\nTo change the brightness level send a command like this one:\n```\ncurl -H 'Content-Type:application/json' \\\n     -d '{\"name\": \"brightness\", \"value\": 50}' http://localhost:3000/command\n```\n## Did that, what's next?\n\nCheck out the [ST Schema OAuth Example](https://github.com/SmartThingsCommunity/st-schema-oauth-example)\nto see an example of a complete device cloud integration that connects to ST Schema with its own\nOAuth server and includes a simple web UI for testing proactive state callbacks.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Fst-schema-callback-example-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartthingscommunity%2Fst-schema-callback-example-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Fst-schema-callback-example-js/lists"}