Alexa skill + Smartthings

Hi,
I’ve been doing some research and I’ve found a few sites (down below) on how to make a smart home skill. I wanted to know if anyone knew how it would be possible to make a very basic Alexa skill to link to my Smartthings account. I am very new to programming Alexa skills and I would really appreciate any help

https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/steps-to-create-a-smart-home-skill

https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/linking-an-alexa-user-with-a-user-in-your-system

http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/authorization.html

Just use the official SmartThings skill.

Jack. I did this about a year ago…it is a very well received and stable release.

It’s a big difference between a custom skill like Ask Alexa or EchoSistant (see below) and a smart home skill, which @cookierookie44 was wondering about… Maybe Jack can share more about what he is trying to accomplish with a Smart Home Skill that is not already covered by the official ST app.

I am confused about what values I’m supposed to put in for all the custom slots for your Ask Alexa. What values do I put in each slot?

If you go into Setting>>Setup Variables you will be presented with a web page with the values in each slot. Please note that it is probably best to do this from a PC and not your mobile device. The full instructions are here:
http://thingsthataresmart.wiki/index.php?title=Ask_Alexa#Custom_Slot_Information

Let me know if you run into issues…Also, you may want to join the discussion on the regular thread for Ask Alexa here:

Right. You might not want or need all the functionality of Ask Alexa, or you might want something completely custom that does not involve ST but still is part of a “smart home”.

Such things as voice control of a media center. If you don’t have one of the various IR interfaces such as Logitech, but have network-controllable AVR and TV.
Or you want direct control over a smart lock. Or garage door or IP smart plug. Etc.

I know in my case, my entire music studio could be divorced from Smartthings if I were to choose IP plugs instead of what I have. I have no automations there where one device or sensor status drives changes in another device; all commands (such as “Alexa, turn rehearsal room on”) are voice commands and therefore have no need of ST.

This autumn, when outdoor life slows down again, I’ll check out doing some custom Alexa skills.

Thanks. Another problem I’ve noticed is that when I run the AWS lambda code start test (I put in ID and token) it gives me an error. Why is this so?

{
  "response": {
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak><prosody rate='undefined'><prosody pitch='undefined'>There was an error with the Ask Alexa SmartApp execution. If this continues, please contact the author of the SmartApp. </prosody></prosody></speak>"
    },
    "card": {
      "type": "Standard",
      "title": "Ask Alexa - Lambda Error",
      "text": "There was an error with the Ask Alexa SmartApp execution. If this continues, please contact the author of the SmartApp. ",
      "image": {
        "largeImageUrl": "https://raw.githubusercontent.com/MichaelStruck/SmartThingsPublic/master/img/AmazonICO/warning.png"
      }
    },
    "shouldEndSession": true
  }
}

I am not sure what you mean by ‘start test’, but if you mean the test button on the AWS site the output is invalid as it doesn’t have any actual data to process so you will always get an error. Your output appears to be from the Developer site, however. While I know you said you put the proper code in, that does indicate something is amiss. I recommend actually copying it again, save, and try again. If that doesn’t work, try to reset the token (from the Settings menu) and then do the process over. Sometimes older or invalid tokens creep into the SmartThings system so it is best to ensure you reset the token and then pasting the data in. I also don’t recommend typing it in…just copy and paste it as I spent an hour one time troubleshooting when it was a transposed character.

(The message was from aws.amazon.com. I did press test button) I tried everything you said, but I still receive and error message. From developer.amazon.com I typed in “start smartthings” but it results in the below error message.

{
  "response": {
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak><prosody rate='undefined'><prosody pitch='undefined'>There was an error with the Ask Alexa SmartApp execution. If this continues, please contact the author of the SmartApp. </prosody></prosody></speak>"
    },
    "card": {
      "text": "There was an error with the Ask Alexa SmartApp execution. If this continues, please contact the author of the SmartApp. ",
      "title": "Ask Alexa - Lambda Error",
      "image": {
        "largeImageUrl": "https://raw.githubusercontent.com/MichaelStruck/SmartThingsPublic/master/img/AmazonICO/warning.png"
      },
      "type": "Standard"
    },
    "speechletResponse": {
      "outputSpeech": {
        "ssml": "<speak><prosody rate='undefined'><prosody pitch='undefined'>There was an error with the Ask Alexa SmartApp execution. If this continues, please contact the author of the SmartApp. </prosody></prosody></speak>"
      },
      "card": {
        "title": "Ask Alexa - Lambda Error",
        "text": "There was an error with the Ask Alexa SmartApp execution. If this continues, please contact the author of the SmartApp. ",
        "image": {
          "largeImageUrl": "https://raw.githubusercontent.com/MichaelStruck/SmartThingsPublic/master/img/AmazonICO/warning.png"
        }
      },
      "shouldEndSession": true
    }
  },
  "sessionAttributes": {}
}

Again, pressing “Test” from the AWS site will ALWAYS give you an error…Please ignore that and do not test in that manner.

If everything is working you can type “version” into the developer simulator and you should get something if your parameters are correct. Start SmartThings will give you an error as well. In the developer are the ‘open smartthings’ is already assumed since you are in the skill. Anything else indicates you do not have something in your Lambda code. Please note that if you are doing this from work (i.e. through a corporate firewall) that I have found some things you THINK are saving on the site are not…this was verified the other day with another user who swore up and down he saved the data but received an error…just FYI.

Why are you testing without a Alexa device in front of you? That is the easiest way to determine if everything is working.

I tested on the developer site as well as on the echo and I tried “open/start smartthings”, but it resulted in an error. I typed in version and it said The remote endpoint could not be called, or the response it returned was invalid.

Probably unlikely, but could my slots be a cause of this problem?

The error you are getting is because the skill can not communicate either with Lamba, or Lamda can’t communicate with SmartThings. Be sure your ARN is correct, and again, I KNOW you did the STID and Token but I would reset them, go and physically look in the About Ask Alexa app and ensure you see the security items in there, and then recopy/paste them into the Lambda code.

However, that being said, according to your slots you will be unable to control anything as you don’t have anything in there…It is almost irrelevant if you can’t get the basic Help/Version stuff to work, but you should really follow the setup of the app THEN copy and paste the items into the developer slots and Lambda site. Going out of order doesn’t hurt, but it doesn’t allow me to rule out anything if it isn’t set up.

Sorry you are having issues…I also recommend you watch the live logging…even with the ‘version’ command…you will see if any communication is going between Amazon and SmartThings. Trust me…this stuff does work…it is just a matter of getting past some of the ‘quirks’ of Amazon.

Thanks. It’s working now! I also wanted to know if I say, “Alexa, open the curtain”, is this treated the same way as turning on a device?

Excellent…you will have to have a device that is called “Curtain”, of course and it must respond to open/close commands…finally, that has to be in the proper area where "open/closed’ can be used (i.e. Window, Shades, Doors). In addition, the command would be “Alexa, tell SmartThings to Open the curtain”…without the “tell SmartThings” you would be using the native integration and open/close are hit and miss with the native integration.

Everything works now and open/close commands work great. Is there any possible way to get the Echo to automatically recognize devices that are connected to Smartthings instead of having to type it into the slot (like how I can ask Alexa to discover devices automatically)?

That would be the holy grail of Alexa Skills development…Unfortunately there is no automated way from an individual level to populate slots…In theory, I could enable free text but that reduces the reliability of recognizing the words down about 10-25%. So, every time you add something you need to update the slots. While daunting, I personally haven’t changed my slots in months…once you set it all up and are happy with it you won’t have as many changes.

Do you know of any way to get this skill to go to the Smartthings authorization page as described in http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/authorization.html? This way if I want to add devices, all I have to do is login into the authorization page and authorize devices I select.

All this does is authorize the devices and setups of the OAuth and Token…even implementing this would not eliminate the need to fill the slots up.

I HAVE figured out how to keep you from having to copy/paste your the Oauth pieces…I am just waiting to implement it as it requires additional services that will cost me a minimal charge each month. To be clear, you STILL have to copy/paste things…but it will be the whole code produced by the app instead of just the code pieces.

I have been doing this for almost a 2 years and am always on the lookout on how I can get the slots to autopopulate. Unfortunately, people a LOT smarter than me have tried and failed.

What do you believe Smartthings may have done to make Alexa automatically discover devices connected to the hub?