There is a project call Anna: Alexa Powered Interactive Light. But that does not use the Smart Home Skill. This project will use the Smart Home Skill to connect to a NeoPixel Ring thru Raspberry Pi and Arduino Uno.
Step 1. Create a Smart Home Skill and Connected Lambda.Follow the steps here to create the Smart Home Skill and Lambda. Setup LWA and take note of the client id and client secret which will be used in the Skill Configuration.
Here I create a Skill (v3) called Edison Nightlight Lantern and a Lambda with the same name.
Step 2. Create an IoT Thing.Follow step 2 of this to create the IoT Thing. I named the thing edison_nightlight_lantern. Remember to download the public key, private key and certificate.
Step 3. Connect Lambda to the Thing.Follow step 3 of this to connect the Lambda to the IoT Thing. For now, you can use the Lambda function from the steps of the guide to check that you have setup the skill and lambda correctly. In Step 6 below, you will use the actual lambda function (code section) of this project.
Step 4. Setup Raspberry PiFollow this link to setup the Raspberry Pi. Follow this resource to get the newer version of Node.js.
Step 5. Connect the Raspberry Pi to AWS IoT using JavaScript SDKFollow this guide and this to setup the connection between Raspberry Pi and AWS IoT using the JavaScript SDK. You are good to continue if you can run some of the examples of the SDK.
I follow the custom configuration file approach to run those example applications. See the command line in Step 7. I named the configuration file as config.json. It is a JSON file with the following properties:
{
"host": "a22j5sm6o3yzc5.iot.us-east-1.amazonaws.com",
"port": 8883,
"clientId": "MyRaspberryPi",
"thingName": "MyRaspberryPi",
"caCert": "root-CA.crt",
"clientCert": "4bbdc778b9-certificate.pem.crt",
"privateKey": "4bbdc778b9-private.pem.key"
}
Step 6. Copy the Lambda function from the CODE SectionUpdate the Lambda function by copying the Python code from the CODE section. The Python code implements the PowerController and ColorController interfaces.
These are the capabilities in Python code:
"capabilities": [
{
"type": "AlexaInterface",
"interface": "Alexa",
"version": "3"
},
{
"interface": "Alexa.PowerController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"supported": [
{
"name": "powerState"
}
],
"proactivelyReported": True,
"retrievable": True
}
},
{
"type": "AlexaInterface",
"interface": "Alexa.ColorController",
"version": "3",
"properties": {
"supported": [
{
"name": "color"
}
],
"proactivelyReported": True,
"retrievable": True
}
}
]
This is the Power Controller code:
if request_namespace == "Alexa.PowerController":
if request_name == "TurnOn":
# light_state("on")
value = { 'hue': 0, 'saturation': 0, 'brightness': 1 }
set_color(value)
value = "ON" # this is for response
else:
# light_state("off")
value = { 'hue': 0, 'saturation': 0, 'brightness': 0 }
set_color(value)
value = "OFF"
response = {
"context": {
"properties": [
{
"namespace": "Alexa.PowerController",
"name": "powerState",
"value": value,
"timeOfSample": get_utc_timestamp(),
"uncertaintyInMilliseconds": 500
}
]
},
"event": {
"header": {
"namespace": "Alexa",
"name": "Response",
"payloadVersion": "3",
"messageId": get_uuid(),
"correlationToken": request["directive"]["header"]["correlationToken"]
},
"endpoint": {
"scope": {
"type": "BearerToken",
"token": request["directive"]["endpoint"]["scope"]["token"]
},
"endpointId": request["directive"]["endpoint"]["endpointId"]
},
"payload": {}
}
}
This is the Color Controller Code:
elif request_namespace == "Alexa.ColorController":
value = request["directive"]["payload"]["color"]
set_color(value)
response = {
"context": {
"properties": [ {
"namespace": "Alexa.ColorController",
"name": "color",
"value": value,
"timeOfSample": get_utc_timestamp(),
"uncertaintyInMilliseconds": 1000
} ]
},
"event": {
"header": {
"namespace": "Alexa",
"name": "Response",
"payloadVersion": "3",
"messageId": get_uuid(),
"correlationToken": request["directive"]["header"]["correlationToken"]
},
"endpoint": {
"scope": {
"type": "BearerToken",
"token": request["directive"]["endpoint"]["scope"]["token"]
},
"endpointId": request["directive"]["endpoint"]["endpointId"]
},
"payload": {}
}
}
Step 7. Setup Arduino Uno and Neo Pixel with Johnny-Five and node-pixelFollow this to install Johnny-Five.
Follow this to install the node-pixel module. Take note that you need to install a custom firmata to your Arduino.
Install the hsv-rgb node module:
npm install hsv-rgb
This node module is used inside the handleDelta() to convert the HSV value to RGB value, like:
let color = stateObject.state.color;
let h = isUndefined(color.hue) ? 0 : color.hue;
let s = isUndefined(color.saturation) ? 1 : color.saturation;
let v = isUndefined(color.brightness) ? 1 : color.brightness;
let value = rgb(h, s*100, v*100);
console.log(JSON.stringify([h, s, v]));
console.log(JSON.stringify(value));
strip.color(value);
strip.show();
Setup the Arduino and Neo Pixel as follows:
- Arduino Pin 6 -> NeoPixel Din
- Arduino 5V -> NeoPixeo 5V
- Arduino GND -> NeoPixel GND
Copy the JavaScript (edison_nightlight_lantern.js) from the CODE section to the examples directory and run the following command:
node examples/edison_nightlight_lantern.js -F config.json
Pictures and Video
Comments