Thanks… I tried 10 seconds and still got an error. Did 15 seconds and it worked. WOW… super slow but it works. Thanks…
Michael just released his new Ask Alexa app…give it a try!
Yes, it’s a great program and he’s already working on ver 2.
So I now have pseudo-conversational abilities with Alexa; it turned out to be far simpler than any of the examples had me thinking.
This uses 3 additional intents, only one of which needs a slot “exodus”, with the name “rejection”, and a list like “no, not now, no thanks, no thank you, nope, etc.”. The other two are simply “AMAZON.CancelIntent” and “AMAZON.StopIntent”.
Now when you invoke your skill, you will be asked “anything else” after it completes. You can then issue additional commands without “Alexa” or the invocation word. This example uses the exodus intent to end the session if you answer no to “anything else”. You can also use stop or cancel to exit the session, as well as using ask|tell|run invocationWord to start the session. If you simply leave Alexa hanging with no response, it will timeout like any other call to Alexa.
BTW, if you want Alexa to respond to various commands differently, you’ll just need another intent from which to originate those params.
Here is the updated lamba function (note I removed the inquisitors intent as I had no use for it - add it back if you need it):
'use strict';
exports.handler = function( event, context ) {
var https = require( 'https' );
var STappID = ''; // AppID from Apps Editor
var STtoken = ''; //Token from Apps Editor
var areWeDone=false;
if (event.request.type == "LaunchRequest") {
var speech = "How can I help?";
output(speech, context, areWeDone);
}
else if (event.request.type === "SessionEndedRequest"){
}
else if (event.request.intent.name == "command") {
var Operator = event.request.intent.slots.Operator.value;
var Noun = event.request.intent.slots.Noun.value;
var Operand = event.request.intent.slots.Operand.value;
if (!Operator) {Operator = "none";}
if (!Noun) {Noun = "none";}
if (!Operand) {Operand = "none";}
var url = 'https://graph.api.smartthings.com/api/smartapps/installations/' + STappID + '/' +
Noun + '/' + Operator + '/'+ Operand +'?access_token=' + STtoken;
console.log(url);
https.get( url, function( response ) {
response.on( 'data', function( data ) {
var resJSON = JSON.parse(data);
var speechText = 'The App on SmartThings did not return any message.';
if (resJSON.talk2me) { speechText = resJSON.talk2me; }
console.log(speechText);
if (areWeDone === false) { speechText = speechText + 'Anything else?'; }
output(speechText, context, areWeDone);
console.log("after the fact");
} );
} );
} else if (event.request.intent.name == "exodus") {
areWeDone=true;
output("OK then.", context, areWeDone);
} else if (event.request.intent.name == "AMAZON.StopIntent") {
areWeDone=true;
output("", context, areWeDone);
} else if (event.request.intent.name == "AMAZON.CancelIntent") {
areWeDone=true;
output("Canceling.", context, areWeDone);
}
};
function output( text, context, areWeDone ) {
var response = {
outputSpeech: {
type: "PlainText",
text: text
},
card: {
type: "Simple",
title: "SmartThings Call",
content: text
},
shouldEndSession: areWeDone
};
context.succeed( { response: response } );
}
Totally cool Scottinpollock! That’s a great option!
Anyone able to get this new code to work? When I copy and pasted it over the existing one, it doesn’t work. Both STappID and STtoken were copied over from my old setup so everything should work but all i get is “sorry, i am having trouble accessing your askhome skills right now”
Any thoughts?
I haven’t tried it yet.
He’s adapted it, added, and deleted stuff cuboy29. You’ll have to do a little re-programming to have it work with yours. I would start by just putting the “command” section back as “home” with inquisitor like this:
if (event.request.intent.name == "Home") {
var Operator = event.request.intent.slots.Operator.value;
var Noun = event.request.intent.slots.Noun.value;
var Operand = event.request.intent.slots.Operand.value;
var Inquisitor = event.request.intent.slots.Inquisitor.value;
if (!Operator) {Operator = "none";}
if (!Noun) {Noun = "none";}
if (!Operand) {Operand = "none";}
if (!Inquisitor) {Inquisitor = "none";}
var url = 'https://graph.api.smartthings.com/api/smartapps/installations/' + STappID + '/' +
Noun + '/' + Operator + '/'+ Operand + '/' + Inquisitor +'?access_token=' + STtoken;
Thanks Keith… Not sure how I missed the intent name Got it working.
I’m a Dim Wit,
Ok…here’s a quick dim routine for Ask Home. Feel free to change the logic a bit. I’m more of a setpoint
dim wit, so When I say Dim or Lower it means set at 25% for me. and Raise or higher it means 75%.
To you it may mean slightly increase or decrease something, which is fine
…the current status variable percent is in the routine and you can adjust the logic to work anyway you want!
This code turns on the light and sets it to a percent value of on. If the value is less than 10 it assumes
the user is giving a 0 to 10 level value and converts it to percent. If it’s 0, it just turns the light off.
//Inputs -- use an existing dimable light
// put a few extra lines in utterances if you want:
Home {Noun} {Operator} {Operand}
Home to {Operator} the {Noun}
Home to {Operator} the {Noun} to {Operand}
//put some extra words in Alexa skill under the LIST_OF_OPERATIONS
dim, lower, brighten, raise, set, level
// case example
case "bedroom light" : switch(op) { // simple on and off
case "on" :
case "off" :
case "status" : switchResponse(brlight,noun,op); break
case "dim" :
case "lower" : switchLevelResponse(brlight,noun,op,25); break
case "brighten" :
case "raise" : switchLevelResponse(brlight,noun,op,75); break
case "set" :
case "level" : switchLevelResponse(brlight,noun,op,opa); break
default : defaultResponseUnkOp(noun,op)
}
break
// add a switchLevel capability into the code
//capability.switchLevel [number]
def switchLevelResponse(handle, noun, op, opa)
{
def arg = handle.currentValue("level") //value before change (use for % change if you want)
def intensity = opa.toInteger()
if (intensity <= 0) { // intensity 0, turn off instead
switchResponse(handle,noun,"off")
} else {
if (intensity <= 10) { intensity = intensity * 10 } // turn a 0-9 level into a percent
if (intensity > 100) { intensity = 100 } // more than 100% is just 100%
switchResponse(handle,noun,"on") // turn light on
handle.setLevel(intensity) // set level
state.talk2me = state.talk2me + "and set to ${intensity} percent. " // talk2me : switch is intensity
}
}
Anyone get this to execute routine yet?
Routines…hmmm.
I didn’t think it has the code for it. I want to say Alexa, ask home to execute goodnight routine.
Oh…yea…no, not routines. Sorry. I didn’t code it because I don’t use them (yet). Michael’s ask alexa might do that already.
I’m studying his code now I like this app better since I can code it to give me status of a group of devices and let me know only the ones that are on or OFF.
beside… this is fun
Some folks like to code and let their imagination run wild.
Got mode/routine working. Alexa, ask home to set mode to Away … and Alexa, ask home to execute goodnight routine.
Nice. when you get the chance,share with us how you did it!
It does…
YES it does… I just have to fix all of my programming… ugh… I’m thinking of taking my entire system down and starting from absolute zero… 130 physical devices… almost 100 rules across a lot of apps running this system… I’ll need a month to get it back up and running!!!
But I really think it will be worth it.