22

I have several lights connected to relays which are connected to a wiolink

I can turn the lights on and off through the REST API, like so:

curl https://us.wio.seeed.io/v1/node/GroveRelayD0/onoff/[onoff]?access_token=xxxxx

How can I access this REST API through Alexa with an Echo Dot?

1 Answer 1

14

See these instructions.

Create an AWS developer account & AWS account.

In the AWS console

  • Create a lambda function. Include in the lambda function some code that will access the API. This can either be python or java or node.js.

Here is a python script. Change modify_state to be either 1 or 0

import urllib2

def modify_state( port, state, token):
    url = 'https://us.wio.seeed.io/v1/node/%s/onoff/%s?access_token=%s' % (port, state, token)
    req = urllib2.Request(url,'')
    response = urllib2.urlopen(req)

def lambda_handler(event, context):
    modify_state('GroveRelayD0', <STATE:0:1>, '<APIKEY')
    # TODO implement
    return {
        'version': '1.0',
        'sessionAttributes': {},
        'response': {
            'outputSpeech': {
                'type': 'PlainText',
                'text': '<whatever whitty remark alexa should say>'
            },
            'card': {
                'type': 'Simple',
                'title': "SessionSpeechlet - foo",
                'content': "SessionSpeechlet - bar" 
            },
            'reprompt': {
                'outputSpeech': {
                    'type': 'PlainText',
                    'text': 'I know right'
                }
            },
            'shouldEndSession': True
        }
    }
  • Make sure to publish new version (copy the ARN in the top right, you'll need it later)

aws lambda code

  • Set the 'trigger' to alexa skills

aws trigger configuration


In the developer console

  • Create a skill create a skill dialog

  • Create an Interaction Model with an intent, and a sample utterance intent schema dialog

  • Link the endpoint

endpoint configuration dialog

You can skip the last 2 steps. The skill will run in development mode and only you will be able to access it. Complete the last 2 steps only if you want to share your skill with anyone in the world.

1
  • 1
    If one doesn't publish I have to connect my Echo to a developer account, right?
    – Helmar
    Dec 14, 2016 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.