Example WebHook SmartApp Source Code - New APIs!

api

(Jim Anderson) #1

Fellow developers -

One of the booths at the 2017 SDC (Samsung Developer Conference) allowed developers to come and build their own SmartApp, using the new APIs. This example is now open-sourced, and provides a good (yet relatively simple) example of the new SmartApp model.

You can find the example source code here.

We’ll be adding more open-source examples in the future, and if you haven’t yet, check out the example that shows using the REST API and personal access tokens to get information about and control devices!


Wanting a webhook to get notified of all events
Example using new SmartThings Cloud API!
Can you access REST API without installing a SmartApp?
Example using new SmartThings Cloud API!
(Bartek) #2

@Jim
Given example is only subscribing to “Schedules” wchich occur every given time specified by cron string.

Is there any example with subscribing to “Device Subscriptions” like a switch for instance ?

I see there is already an option to create and self-publish “Cloud-to-Cloud device”.
When it will be possible to add “Cloud-to-Cloud device” in Samsung Connect App ?


(Jody) #3

(Bartek) #4

@jody.albritton

But this is the same example.
I ask for example of "“Cloud-to-Cloud device”, not an automation based on cron string.


(Jody) #5

@btrial The overall process is the same. We are working on a full C2C device example to publicly release but all the info needed to get started is here:

https://smartthings.developer.samsung.com/develop/guides/cloud2cloud/c2c-basics.html


(Bartek) #6

@jody.albritton
I read this whole specifification which you point to and it is clear how to create a webhook with all lifecycle events handlers and how to subscribe webhook to device events. But what i am missing is how to create the device UI (buttons, layout etc) which will be shown in Samsung Connect app, and which my webhook will be subscribing to ?

In old smartthings developer version, device ui (tiles, layout etc) is specified in device handler.

What i dont understand in new developer version is how to create device UI itself so it shown.


(Jody) #7

The UI is built using the SDK and plugin toolkit.

https://smartthings.developer.samsung.com/develop/workspace/sdk/ui-editor.html


(Bartek) #8

Mentioned UI editor in Atom, doesn’t give possibility to create a project for Cloud2Cloud device, and only Cloud-Connected-Device.

All this is totally useless for now. Waste of time.


(Jody) #9

Can you give an example of what you are trying to do? What is the difference between a cloud to cloud and cloud connected device to you?


(Jim Anderson) #10

Just to clarify, because I find it a bit confusing:

Cloud-Connected = OCF device
Cloud-to-Cloud = Cloud device (e.g., an Ecobee thermostat)


(Jim Anderson) #11

You can certainly subscribe to configured device attribute events using the subscriptions API.

The request body would look like thisfor subscribing to any events for a configured contact sensor (with ID contactSensor in the config, in this case):

{
    sourceType: 'DEVICE',
    device: {
      componentId: config.contactSensor[0].deviceConfig.componentId,
      deviceId: config.contactSensor[0].deviceConfig.deviceId,
      capability: 'contactSensor',
      attribute: 'contact',
      stateChangeOnly: true,
      subscriptionName: "contact_subscription",
      value: "*"
    }
  };

Then any time the contact attribute of the configured device changes, your app will receive an EVENT lifecycle event with information about the triggering event.


(Bartek) #12

@Jim @jody.albritton
Thank you for your responses.

My understanding is exactly like @Jim wrote:

Cloud-Connected = OCF device
Cloud-to-Cloud = Cloud device (e.g., an Ecobee thermostat)

I want to create “Cloud-to-Cloud” device,
but in Atom, you can only create a project for “Cloud-Connected = OCF device”.
There is no possibility to create UI for “Cloud-to-Cloud” device.

What I want to do in details, is to write a webhook app (in Java language) and host it on Raspberry Pi3 (Raspbian). The app would be a middle man to execute python script controlling Xiaomi Vacuum cleaner.
In my understanding this is “Cloud-to-Cloud” integration.

I know exactly how to write webhook with all lifecycles , and how to subscribe to events, as this specified well enoguh.

But I stiil don’t know how to create a UI, because as I mentioned, you cannot create it in Atom for C2C, and only for OCF device.


(Jody) #13

I think this is a good example of where we could improve the docs and I understand why this is confusing. But in the workspace there is a section for creating a cloud connected device. You would then use the devices API to control that device, create its events, and manage its life cycles.

It’s the device profile that defines the ui manifest. That UI manifest is what determines what will be displayed in the mobile app.


(Bartek) #14

As you said, in workspace it is described how to create “Cloud connected Device” (OCF) using Atom.

But there is no description and no possibility to create “cloud to cloud device”. Based on the spec those are two different things.

So why are you keep pointing me to OCF ones ?
Or am I missing something? Can you please attach a link to description how I can create UI in Atom of “Cloud to cloud device”?


(Pablo Pizarro Aguilar) #15

Hi @Jim,

I am trying to subscribe to device events, but I am getting a 403 Forbidden. This happens with subscriptions only, I can manage the rest of the API with no problems.

I am also getting an error ( Something went wrong. Please try to install the SmartApp again) when I try to install my SmartApp in my SmartThing App. I have followed this guide with no luck.

Any clue?

Thanks


(Jim Anderson) #16

hi @pablo.pi,

Are you trying to subscribe to a specific device(s) or all devices of a certain capability? 403 typically means that your app doesn’t have the necessary permissions, so check the permissions on the app itself and in any device configuration settings.

Did you check the Troubleshooting section on that document to see if any of the common issues there might be causing that issue?


#17

Hello,

Our team is using a Groovy app for an unreleased product, and we were struggling with how to have an easy developer process for distributing builds that can be used by different Smart Things users without them needing to install the Groovy app locally and deal with the Client Id and Secrets for the Groovy App.

It seems this new API may help with that situation, and hosting the SmartApp logic ourselves is attractive, but I have some questions if someone is available to answer:

  1. My understanding is that there is no supported away around the Groovy app installation issue for development builds. Please correct me if I am wrong. And, it seems this new API allows us to programmatically install the new style SmartThings App as a web or aws lambda solution per-user, obtain the Client ID/Secret in the response, and authenticate with the App. Is this correct?

  2. If a Personal Access Token is used to install and app and obtain a Client ID/Secret, I suppose the user will still need to authenticate with the Client ID/Secret in order to work with the new app, correct?

  3. Is the Personal Access Token approach also intended to be used in Production, for example must our end users go to the token creation page, create a personal token, and then send our product the token so that we can install the SmartThings app?

If the answer to #3 is yes, are there any plans to improve this workflow? The process should be as streamlined as possible and currently it seems there may be some issues with it:

  • We can show the token creation page to the user, but it would be preferable if the user does not need to name the token.
  • Copying the token is not ideal.
  • It’s not possible to view tokens after creation, they must be deleted.
  • Permissions cannot be pre-configured. Ideally our product can define default selections for the personal access token permissions to avoid missing permissions that cause our product to fail.
  • After creation of the token they must still authenticate with the installed app, which is another step of verification and selection of permissions.

Thank you!
Edward


(Coxi Dev) #18

Hi @jody.albritton, the provided link to build a SmartApp UI is not working.

Could you please check and advise?