Amazon Echo and ThingLayer

Continuing the discussion from Does anyone know what's up?:

Continuing the discussion from Playing around with Amazon Echo (technical interface discussion):

Author of ThingLayer here.

I am working on this. Let’s fork this discussion into a new topic. What are you having trouble with?

For starters, what I’m looking for is a REST endpoint that I can access to perform dimming commands. The example application commonly used here only supports on/off commands. In the Amazon Echo thread it was suggested that the ThingLayer SmartApp might allow for dimming via a REST call. I’ve installed the application but couldn’t get it to work, but I might be doing something dumb. In order to troubleshoot this I recorded a detailed step-by-step procedure for installing the app. As a sanity check I’m going to post it here for review:

  1. Log in and navigate to Device List:
  2. Click the link for each desired device. The link will be in the format:[Device ID]
  3. Record the Device ID value for each device you want to control
  4. Navigate to My SmartApps:
  5. Click “+ New SmartApp”
  6. Click “From Code” tab
  7. Copy full code from GitHub raw dump here:
  8. Paste raw code into “From Code”
  9. Click “Create” at bottom of page
  10. Click “App Settings” at the top right
  11. Click “OAuth” and then click “Enable OAuth in Smart App”
  12. Click “Update” at bottom of screen
  13. Click “Code” button at top of screen
  14. Click “Publish” button, select “For Me”
  15. Select correct location in Location drop down
  16. Click “Set Location” button
  17. Select one or more Dimmer devices under “Which Dimmers?”
  18. Click “Install” button
  19. Record “API Token” and “API Endpoint” value at the bottom right
  20. Issue HTTPS request in browser as follows:
    [API Endpoint]/switches/[Device ID]/on?access_token=[API Token]
    [API Endpoint]/switches/[Device ID]/level/50?access_token=[API Token]

In the browser I receive the following error:

{"error":true,"type":"java.lang.NullPointerException","message":"An unexpected error occurred."}

In the IDE I see the following error logged:

error java.lang.NullPointerException: Cannot get property 'id' on null object @ line 471

I think I should further clarify: this has nothing whatsoever to do with ThingLayer itself. All we’re after is a way to send one or more ST-controlled devices a command to turn on, off, or dim (from 0-100 or 0-255) via HTTP request. The amazon-echo-ha-bridge will call this HTTP request in response to commands issued by the echo.

Some Background
The amazon-echo-ha-bridge application takes a JSON device creation request and uses it to emulate a hybrid Hue/WeMo device that the Amazon Echo is able to discover and control. A typical configuration would look like this:

“name” : “Kitchen Lights”,
“deviceType” : “switch”,
“onUrl” : “[installation id]/switches/[device id]/on?access_token=[access token]”,
“offUrl” : “[installation id]/switches/[device id]/off?access_token=[access token]”

This works with the demo App Endpoint Access app and it allows me to turn my Kitchen Lights on and off. The latest release of amazon-echo-ha-bridge has added the ability to include replaceable parameters for brightness. The author explains it here:

in the “on” url just replace the brightness with ${intensity.percent} or ${intensity.byte} (for 0-255)

So then I was looking for a way to send the “${intensity.percent}” value in my URL. @DarcRanger noted that he was able to use the following format to access dimming: CODE/switches/DEVICE ID/level/##?access_token=ACCESS TOKEN

“##” is the value between 0% and 100%.

Using the App Endpoint Access app I found that the “level” API is not implemented. I asked about this, and in this post he suggested it might have been ThingLayer that he installed to get the “level” API.

So that is why people are posting about ThingLayer and Amazon Echo. I have little to no code expertise and I’m looking for a way to access dimmers via a URL, and the ThingLayer smartapp was suggested as a means to that end.

Am I barking up the wrong tree here?

I understand that you are just using the ThingLayer SmartApp, but I needed to move the discussion to a different thread.

The url should look something like this[install_id]/dimmers/[device_id]?access_token=[token]

You cannot really test dimming in the IDE, but I tested it using the postman chrome app.

You can use your clientId and secret to to for oAuth2 using postman.

Select oAuth2 for authentication and click the get authorization button

Authorization URL:
Authorization Token URL:
Client ID: Your ID
Client Secret: Your Secret
Scope(optional): app

After you obtain the token

Do a get request on a url like this[client_id]?access_token=[access_token]

It will return a json response with a url. That is the base url for your app. It will look like this:[install_id]

1 Like

How do I pass the value for the dimmer? For example, if I want to dim to 50%, what would the REST URL look like?

Update: I’ve found an endpoint application that will allow me to submit a dimmer value between 0-100 which is required by the amazon-echo-ha-bridge tool I’m using for Amazon Echo integration. This means that I won’t be needing the ThingLayer endpoint, but I really do appreciate you taking the time to help me out @jody.albritton

1 Like

Hey bud Vera is Z-Wave only just a heads up on that. That is a huge non starter for me.

1 Like

That was a quote from @Keo

My problems are mostly with response. I’ve had far too many problems with response from smartThings that I’ve stopped trying to implement anything until hub V2 comes out.

For those that come to this point and are stuck after following @jody.albritton’s steps here is how I got it working.[install_id]/dimmers/[device_id]/on?access_token=[token]


Those two commands both work.

However when I send[install_id]/dimmers/[device_id]/level/[level]?access_token=[token]

I get the following response

{"error":true,"type":"SmartAppException","message":"Not Found"}

So I added the device in the auth section as a switch and as a dimmer, then I send the level command as a switch and it works.[install_id]/switches/[device_id]/level/[level]?access_token=[token]

To use this with the Echo, I created a virtual dimmer switch and a simple smart app that copies the dimmer level to the thermostat. So I can say “Alexa set thermostat to 72” She then does just that :smile: