AskHome - Alexa/SmartThings programmers kit. Alexa can do anything

This is awesome. I now ask Alexa for the status of the house and she goes and report the status of the lights, the house temperatures, all presence sensor status and all door open/closed status then she even tell me i’m the boss of the house and she’ll kick anyone ass if they mess with it. LOL… driving my wife nuts with the last comment.

1 Like

Just a reminder: these are all doable in Tasker on android as well. I’ve got conversational interaction occurring already, and I’m in the process of using multiple conditions and regex to generalize it more. So that fewer questions, and/or conversational variations on questions, generate the results you want.

Anyone able to get Alexa to control LIFX color? I can get her to change the color correctly but she also respond with “The remote endpoint could not be called, or the response it returned was invalid.” (via the simulator).

//All Color Controlls
input "colorlights","capability.colorControl", title: "Select All Color Bulbs", required:true, multiple: true


    case "LIVING ROOM LIGHTS"	:  switch(op) {        // Report the Thermostat status 
                                    case "go"     	  : colorControlResponse(colorlights,noun,op,opa);break
                                    default           : defaultResponseUnkOp(noun,op)
                                  	} 
                                  	break    

//capability.colorControl
def colorControlResponse(handle, noun, op, opa)
{
handle.each{
if (op == “go”) {
def hueval = colorWordtoHue(opa)

  	def satval = 0
  
  	if (opa == "white") {satval = 20} else {satval = 100}
  
  	if (hueval == -2) {state.talk2me = state.talk2me + "I don't know that color yet.  " } 
  	else if (hueval == -1) { handle.off()}
  	else {
       	def map = [switch: "on", hue: hueval, saturation: satval, level: level as Integer ?: 100]
       	handle.setColor(map)
       	handle.on()
  	}  
}

state.talk2me = state.talk2me + "${Noun} turning ${opa}. "
}
}

Looking at LAMDA log, here is what I see

START RequestId: xxxx-1553-11e6-8448-xxxxx Version: $LATEST
2016-05-08T19:34:17.149Z xxxx-1553-11e6-8448-xxxxxxx https://graph.api.smartthings.com/api/smartapps/installations/xxxxx-e029-xxxxx-ae0c-xxxxxxxxxxx/living room lights/go/blue/none?access_token=fd6ebc4b-cd36-4c45-8111-xxxxxxx
END RequestId: da303548-1553-11e6-8448-xxxxxx xxx
REPORT RequestId: xxx-1553-11e6-8448-xxxxxxx Duration: 5002.30 ms Billed Duration: 5000 ms Memory Size: 128 MB Max Memory Used: 17 MB
2016-05-08T19:34:21.866Z xxxxx-1553-11e6-8448-xxxxxxxx Task timed out after 3.00 seconds
START RequestId: xxxxxxxx-xxx-xxx-xxxx-xxxxxxxx Version: $LATEST
2016-05-08T19:34:22.588Z xxxxxxxx-xxx-xxx-xxx-xxxxxxx TypeError: Cannot read property ‘name’ of undefined at exports.handler (/var/task/index.js:10:28)
END RequestId: xxxxxxx-xxxxx-xxx-xxx-xxxxxxxx
REPORT RequestId: xxxxx-xxx-xxx-xxx-xxxxxx Duration: 822.17 ms Billed Duration: 900 ms Memory Size: 128 MB Max Memory Used: 16 MB
Process exited before completing request

1 Like

Hi cuboy!

The error in the lambda log you included was:
Task timed out after 3.00 seconds

The lifex web site takes a long time to respond, and lambda times out and gives up on its call to smartthings to change them. The default timeout is 3 seconds, I had to set my lambda time out to 6 to turn on two lifx sequentially. Lambda, config tab, advanced…make the timeout seconds higher.

1 Like

Thanks… I tried 10 seconds and still got an error. Did 15 seconds and it worked. WOW… super slow but it works. :slight_smile: Thanks…

1 Like

Michael just released his new Ask Alexa app…give it a try!

2 Likes

Yes, it’s a great program and he’s already working on ver 2.

1 Like

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 } );
}
6 Likes

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;
1 Like

Thanks Keith… Not sure how I missed the intent name :slight_smile: Got it working.

1 Like

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
      }    
}
2 Likes

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.

1 Like

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. :slight_smile:

1 Like

I’m studying his code now :slight_smile: 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 :slight_smile:

1 Like

Some folks like to code and let their imagination run wild. :wink: