Acuity Brands Logo      DGLogik is now part of Acuity Brands, Inc.   Learn More >>

“Alexa, Ask DGLux5 to Update My Dashboard”

DSA, Alexa, and DGLux5 

If you’re interested in integrating Alexa with DSA, or learning more about DSA in general, this post will definitely help you get started. It's also great for DGLux5 users who want to use the Amazon Echo to run their dashboards. We created a simple DGLux5 dashboard that updates in real-time to reflect commands that we give to our Echo.

To do this, we took data collected by a system monitor, duplicated the data to a REST server, and created some Alexa skills to talk to the data. We also created a gauge in DGLux5 that updates in real time with the values of our REST nodes. The whole process is shown in the video.

Distributed Services Architecture (DSA) is an open-source platform that facilitates communication among devices, logic, and applications in the IoT. You can download it here.

What you'll need to get started

If you want to follow along with the video, you’ll need a few things before you can get started. Of course, you’ll need an Echo or another device that runs Alexa. You’ll also need to create an Amazon developer account if you don’t already have one, and you’ll also probably want an Amazon Web Services account. Amazon says both of those are free for most users, and we didn’t need to pay in creating this example. Finally, take a look at the code samples at the bottom of this post—you can use them if you want, but you’ll have to replace the REST API pathways with your own information in order for them to work.

In the video, we use a DGLux5 gauge that has been imported into our widget palette from the Dashboard project. You can learn more about the widget palette here and more about using gauges here.

This is just the beginning

You could use these same steps to integrate Alexa with any of your DSLinks—the possibilities are endless. Tell us about your DSA and Alexa ideas in the Google Plus community and on Slack!

Example code

Here is the code that was used in the video:

Lambda JavaScript code for the getCPULoad skill

exports.handler = function( event, context ) {

var http = require( 'http' );

var url = 'http://<your URL>:<your REST server port>/<your node name>?value';

http.get( url, function( response ) {

response.on( 'data', function( data ) {

var text = 'Your current CPU usage is ' + data + ' percent';

output( text, context );

} );

} );

};

function output( text, context ) {

var response = {

outputSpeech: {

type: "PlainText",

text: text

},

card: {

type: "Simple",

title: "System Data",

content: text

},

shouldEndSession: true

};

context.succeed( { response: response } );

}

Intent schema for the getCPULoad skill

{ "intents": [ { "intent": "getCPU", "slots": [] } ] }

Sample utterances for the getCPULoad skill

getCPU help
getCPU what is the CPU load
getCPU whats the CPU load
getCPU for CPU load
getCPU for the CPU load
getCPU to find the CPU load
getCPU to give me the CPU load
getCPU what is the CPU data
getCPU whats the CPU data
getCPU for CPU data
getCPU for the CPU load
getCPU what is the CPU usage
getCPU whats the CPU usage
getCPU for CPU usage
getCPU to find the CPU usage
getCPU to give me the CPU usage
getCPU what is the CPU data
getCPU whats the CPU data
getCPU for CPU data
getCPU to find the current CPU data
getCPU to give me the current CPU data
getCPU what is the current CPU load
getCPU whats the current CPU load
getCPU for the current CPU load
getCPU for the current CPU load
getCPU to find the current CPU load
getCPU to give me the current CPU load
getCPU what is the current CPU data
getCPU whats the current CPU data
getCPU for the current CPU data
getCPU for the current CPU load
getCPU what is the current CPU usage
getCPU whats the current CPU usage
getCPU for the current CPU usage
getCPU to find the current CPU usage
getCPU to give me the current CPU usage
getCPU what is the current CPU data
getCPU whats the current CPU data
getCPU for the current CPU data
getCPU to find the current CPU data
getCPU to give me the current CPU data

Lambda JavaScript code for the postSystemPreferences skill

exports.handler = function( event, context ) {

var http = require( 'http' );

var options = {
host: '<your url>.com',
path: '/<your node>',
port: '<your REST server port>',
method: 'POST',
'Content-Type': 'application/json'
};

callback = function(response) {

var str = '';

response.on('data', function (chunk) {
str += chunk;
});

response.on('end', function () {
output(report, context);
});
};

var targetSlot = event.request.intent.slots.Target.value;
var report = 'I have updated your target to ' + targetSlot + ' percent';

if (event.request.type === "IntentRequest") {

var req = http.request(options, callback);
var postData = '{"$type":"number","@unit":"%","?value":"' + targetSlot + '"}';

req.write(postData);
req.end();
}
};

function output( text, context ) {

var response = {
outputSpeech: {
type: "PlainText",
text: text
},
card: {
type: "Simple",
title: "System Data",
content: text
},
shouldEndSession: true
};

context.succeed( {response : response} );

}

Intent schema for the postSystemPreferences skill

{
"intents": [ {
"intent": "writeTarget",
"slots": [ {
"name": "Target",
"type": "NUMBER"
} ]
}]
}

Sample utterances for the postSystemPreferences skill

writeTarget change target to {Target}
writeTarget change target CPU load to {Target}
writeTarget change load to {Target}
writeTarget change data to {Target}
writeTarget change number to {Target}
writeTarget change to {Target}
writeTarget change the target to {Target}
writeTarget change the target CPU load to {Target}
writeTarget change the load to {Target}
writeTarget change the data to {Target}
writeTarget change the number to {Target}
writeTarget write {Target}
writeTarget post {Target}
writeTarget write a target of {Target}
writeTarget post a target of {Target}
Contact Us        Blog