Alexa Smart Home Skill for Particle Devices

that’s the API…

Alexa + DEVICE_IDENTIFIER + utterance

I know, I just find it robotic to speak like that.

you have to wait for Apple’s new TUI

Thoughtful User Interface…

1 Like

@ctmorrison, you can use particle for both client id and secret if you are calling as a single developer user. If you are calling as a product. The second paragraph of this link explains that:

https://docs.particle.io/reference/api/#oauth-clients

If I remember correctly I create a client id and password for this example.You can create a new Client from the Dashboard/Console->Authentication

Hope this helps you to figure out.

@krvarma, I am calling as a single developer user had tried particle for both Client ID and Client Secret in several of my attempts, but without success. Since I’m in the developer mode, the Authentication facility is not available in the Console.

I’m assuming the 400 code I’m getting on the app is associated with Oauth authentication, but that’s really an assumption on my part.

Thanks for the response. Perhaps I’ll look elsewhere for the root cause of the 400 error.

@ctmorrison, @harrisonhjones has described how to create OAuth Client here, can you try and let us know?

1 Like

@krvarma and @harrisonhjones, since I don’t do a lot with API calls via the command line, I’m still struggling a bit to get the entire command formatted correctly. I’m also trying the Firefox Poster extension, but without luck. This is clearly due to my lack of knowledge of API calls. I’m also at work trying to get “work” done and it’s leaving little spare time for this. If you could give me a template for the actual call, I’d be pleased to give it a try after I substitute my information. Thanks.

Can you ping me directly? I’d be happy to walk you through this over Skype/call/etc

2 Likes

Thanks to super support by @harrisonhjones, it appears I’m one step closer to making my Alexa Smart Home work.

The documentation about creating an Oauth Client ID and Client Secret was a bit obscure for me. @harrisonhjones led me through the steps and I’d like to repeat them here for others who may also be having trouble creating the Oauth client credentials required to make a Smart Home Skill.

To make this process easy, install the Chrome application Postman. The following steps are likely similar with Firefox’s Poster, but the specific directions will apply to Postman:

  • Launch Postman
  • Enter the URL: https://api.particle.io/v1/clients
  • Select POST from the dropdown list to the left of the URL
  • Select the Body tab
  • Make sure x-www-for-urlencoded is ticked
  • Select bulk edit – you should get a text box
  • Enter the following in the textbox
    • (you will need to replace the two UPPERCASE_STRINGS)
    • For redirect_uri, It should look something like this https://pitangui.amazon.com/api/skill/link/XXXXXXXX - from the Alexa Smart Home Configuration tab)
  • For the access_token, use the “Access Token” found on the web IDE Settings page
  • The “name” can be anything. Amazon Alexa just makes sense. You will see then when you go to link your skill from the Alexa app.
name:Amazon Alexa
type:web
access_token:GET_THIS_FROM_THE_WEB_IDE
redirect_uri:THIS_IS_FROM_THE_AMAZON_SKILL_PAGE 

  • Click the “Send” button
  • The response should be provided in JSON format.
  • Use what’s shown for “id” as the Client ID in the Alexa Configuration tab
  • Use what’s in “secret” for the Client Secret in the Alexa Configuration tab

Please comment if the above isn’t adequately clear.

I’m assuming the rest of the configuration of the Alexa Smart Home skill has already been covered sufficiently.

Edit (@harrisonhjones): Formatting

2 Likes

Hello,

I tried to build this project. Thank you for the great explanation.However I am having some problems.

I can successfully open the particle login page from the alexa app. also login. Discovery devices show two devices: Kitchen and Bedroom.

Not working:

When I give command to alexa to turn on the kitchen lights , the response is OK but nothing happens on the particle photon.Same for the bedroom. The connection seems to be perfect.

I have some questions.

In the AWS lambda code

for the device ID i entered my photon ID but what is the “Full application ID” ? do we have to change it ?

i get this error when i click on test in lambda

{
“errorMessage”: “RequestId: 8a48b92c-0a51-11e7-b681-03ac90a0e430 Process exited before completing request”
}

Also anything else I cloud check that might be going wrong ?

Thank you

@imdahisaria, most probably some error on the Lambda code and as a result this error is returned. Can you check the console logs and see there is any issue?

i am getting the following error

START RequestId: f165d376-0a6b-11e7-a2ed-3d4ac945bad9 Version: $LATEST

2017-03-16T17:13:58.598Z f165d376-0a6b-11e7-a2ed-3d4ac945bad9 Input: [object Object]
2017-03-16T17:13:58.604Z f165d376-0a6b-11e7-a2ed-3d4ac945bad9 TypeError: Cannot read property ‘namespace’ of undefined
at exports.handler (/var/task/index.js:17:25)
END RequestId: f165d376-0a6b-11e7-a2ed-3d4ac945bad9
REPORT RequestId: f165d376-0a6b-11e7-a2ed-3d4ac945bad9 Duration: 33.86 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 7 MB
RequestId: f165d376-0a6b-11e7-a2ed-3d4ac945bad9 Process exited before completing request

@imdahisaria, the issue seems to be either the event object is NULL or event.header is NULL which is strange. Could you please comment out line number from 17 to 45 and replace it with this and see the crash still occurs. Also could you please log the event.header and see what headers are

if(event['header']['namespace'] == 'Alexa.ConnectedHome.Discovery')
    handleDiscovery(event, context)

else if(event['header']['namespace'] == 'Alexa.ConnectedHome.Control')
    handleControl(event, context)

Hi,

I got the skill to work with my particle photon.

I added 2 more commands for Temperature (increment, decrement and set temperature) similar to percentage with their correct request and confirmation commands.

my problem is that I got the commands to work , also my photon executes the respective code but Alexa always responds with " Sorry something went wrong"

This is only for the temperature commands. Percentage and onoff work correctly. Alexa responds OK.

Can you help me out over here ?

Thank you.

example code for increment temperature

    case "IncrementTargetTemperatureRequest":
        var tempinc = event.payload.targetTemperature.value;
        
        state = tempinc;
        funcName = "temp";
        confirmation = "IncrementTargetTemperatureConfirmation";
        
    break;

Does your Particle.function() return an integer result fast enough?
It could also be that your Amazon Lambda has got some issue. Check the logs or add some extra console log output to test the Lambda.

I sometimes also use some debug code to forward info to requestb.in out of the Lambda.

For testing purpose I have used the exact same code for Temperature like Percentage (with different variables for the temperature). I can see the return value in the cloud logs too. The logs are exactly similar to the percentage.

After giving permission to Particle photon i am getting this error

Thanks everyone for sharing your work :slight_smile:
Has anyone tried payload version v3? (Looks like v2 is deprecated now)

I am able to run my lambda function and turn ON/OFF my lights just fine.
However it does not work when I use the Alexa simulator or my echo dot.
I get “Bedroom light is not responding.” from the echo and “Server is unresponsive.” from the Alexa App.

Any ideas?

Thanks in advance

Yes, in testing now.

You know there’s a fully developed integration already?

I’m playing with v3, but no release dates yet, more other things to do.

I am looking for the simple minded approach to interacting with Alexa. Perhaps someone can help me see the forest instead of the tree.
I have been writing simple Javascript code to make POST and GET requests, following examples in the particle docs. I have a plain html file I can load on most browsers and I can interact with Photons and BluzDKs using most computer platforms. No dedicated apps needed.
The Javascript parses the responses and HTML formats the result on the screen.

Can the Alexa service execute a similar script and “speak” the content of the variable? There is so much content on how to create a skill that I don’t know where I would put my POST/GET calls. And, would the same access token method work?.
I appreciate the functionality people have added with the EchoPhotonBridge, the Patriot system, etc. I would like to push all that processing onto cloud servers. My devices already control touch displays and I2C peripherals, so I don’t want to bog them down any more than necessary.
Maybe allowing AWS to login to my particle account is safer than giving IDs and tokens to Alexa?

Thanks for reading!
Pescatore