Phrases like ‘I am leaving’ and ‘I am home’ will return the ‘I’ in upper case.
There are some weird quirks in what Lambda sends back and forth. Most of the time it is lower case, but I found an unusual case where SONOS is ALWAYS capitalized when it comes from AWS. I basically filter everything to lower case so it is all consistent.
Ok, question. By reading this I’m assuming that letter case is important. If you use a capital T in one spot it must be used like that every where, as well as spaces?
I keep hanging up on my typing errors.
Yes. All case selections going to and from AWS is important. It isn’t consistent, do I filter everything to lower case just to make sure.
Its the Alexa Developer system that does that capitalization of select words, Lambda just finds a way to get what was decoded into SmartThings. I remember the docs saying things like HD or NYC, and peoples names will get capitalized…most everything though is lowercase. Here’s the guide: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference
Ok, I have a question.
In this piece of code I ask “is the garage door open?” or “is the garage door closed?”
I get the correct response based on where the door is at. So, it’s working.
case “garage door” : switch(op) {
// case “open” :
// case “closed” :
case “status” : contactSensorResponse(garagedoor,noun,op);break
default : defaultResponseUnkOp(noun,op)
}
break
Now, as you can see i omitted the two case lines “open & closed”. The program responds the exact same way even if those lines are active or not.
Why?
@N8XD - I just wanted to throw this out here on how awesome this is. Not only has your work opened up a whole new level to the home automation, it’s also made me just headfirst into learning to program myself.
After working on the code for the better part of the night (it’s almost 4am here) I’m finally going to bed.
Though, I did end up crashing the program several times, requiring multiple reinstalls. But, I did figure out how to use the logs to troubleshoot the code (somewhat) and I was able to fix a couple of my screw ups.
I only had to redo the capabilities and case sections twice tonight!
But anyway, thanks.
This is what I’ve figured out what I can do!
This uses the following -
Ask Alexa smart app - awesome bit of code here!
Roger android app - allows for a remote connection (away from home) to your registered Alexa service. You can control your home via voice from anywhere! You can now access Alexa remotely!
Alexa device
my home automation stuff
Life360 family location
This is what I can do!!!
When I’m at home I can do this -
Me: Alexa, ask home for the status of my family.
Alexa: All family members are home (if they are all there)
or
Alexa: Jason is not present, Justin is not present.
When I’m away from home I have several options:
1 - look in the ST app
2 - look at my Life360 app (I use this integration instead of ST because this one actually works)
3 - tap on the Roger app on my phone and talk into my bluetooth.
For option #3 - I say exactly what I said above and I get a response back in a few seconds telling me what I want to know. I also can ask Alexa if I left the stove on and she’ll tell me yes, the water is now boiling!
So, Now
- I can access Alexa remotely and use voice control to control my home.
- I can ask Alexa questions and get feedback from my home automation system through her
I can ask her what the temperature is in the baby’s room… she responds
I can ask her what the thermostats are set to… she responds
The next thing I’m going to figure out is this…
Me - Alexa, ask home the status of the garage door.
Alexa - The garage door is open, would you like to close it?
Me - Yes, close the garage door.
Alexa - Ok.
Alexa - The garage door is now closed.
And I absolutely can’t wait to get my hands on the New AskAlexa app by @MichaelS…
I’m going to get that set up for the family to use and then I’m going to see what I can learn from Keith’s version.
My HA system has just jumped to a whole new level of awesome! Time to start building the window blinds controllers!
Hi Jason!
Good morning, its awesome that you are having so much fun with all the cool home automation toys. It looks like you are accomplishing quite a bit! I’m impressed!
The code you are looking at above works slightly different than you expect because of something that happens just before the switch/case. Some words like “is” turn commands into questions … open / closed get changed to “status” You know how there’s the list of nouns and operations and operands…there was also a list of what I called “inquisitors” - my word for those things that turn a sentence into a question instead of a command. (I’m sure there is a “real” word for that, I just couldn’t remember what it was at 3am one morning)
if (op == "none") { op = "status" } //if there is no op, status request
if (["done","finished"].contains(op)) { op = "status" } //with or without inquisitor these are status
if (inq != "none") { //with an inquisitor these are status
if (["on","off","open","closed","locked","unlocked","about","running"].contains(op)) { op = "status" }
else if (["hot","cold","warm","cool"].contains(op)) { op = "temperature" }
}
Lol, I have no idea what that means… But I’ll understand after some sleep happens…
So, I decided something else I want to figure out.
Since I use life 360 for family presence and tracking the kids, I want to ask Alexa for and updated on the family and if someone is not home, she will tell me their location.
I know it can be done, I just have to figure it out!
Cause you really don’t need the operands unless you want to trigger different responses for different operands. They’ll all just fall through to the contactresponse handler.
BTW, if you have multiple doors, a better way to code this would be to set the noun to doors, and some operands (front, back, garage). Then you could ask for ‘front door’, ‘garage door’, and ‘back door’ from a single case statement.
I do this with my temp sensors, and if it is used without an operand, it falls through to a response handler that reports all of them. Interestingly, with temperatures as the noun, Alexa is smart enough to let me ask for temperature, and even temp, but only when an operand is used. I assume door and doors would work similarly.
I was wondering about that because it just didn’t make sense to have a separate case statement for every single device.
Well you give me a short example?
// inputs
input "outTemp","capability.temperatureMeasurement", title: "Select the Outdoor temp sensor", required: true, multiple: false
input "medTemp","capability.temperatureMeasurement", title: "Select the Media temp sensor", required: true, multiple: false
input "brTemp","capability.temperatureMeasurement", title: "Select the Bedroom temp sensor", required: true, multiple: false
input "dwnsTemp","capability.temperatureMeasurement",title: "Select the Downstairs temp sensor", required:true, multiple: false
input "frzTemp","capability.temperatureMeasurement", title: "Select the freezer temp sensor", required: true, multiple: false
input "frdTemp","capability.temperatureMeasurement", title: "Select the fridge temp sensor", required: true, multiple: false
input "gTemp","capability.temperatureMeasurement", title: "Select the Garage temp sensor", required: true, multiple: false
input "outdoorHu","capability.relativeHumidityMeasurement", title: "Select the Outdoor humidity sensor", required: true, multiple: false
// Case
case "temperatures" : switch (op) { //tell me my temps
case "outdoor" : temperatureMeasurementResponse(outTemp, noun, op); break
case "indoor" : temperatureMeasurementResponse(medTemp, noun, op); break
case "attic" : temperatureMeasurementResponse(dwnsTemp, noun, op); break
case "status" : environmentNounResponse(outTemp,medTemp,brTemp,dwnsTemp,frzTemp,frdTemp,gTemp,outdoorHu); break
default : defaultResponseUnkOp(noun,op)
}
break
// Responses
// Individual sensor
def temperatureMeasurementResponse(handle, noun, op)
{
def arg = handle.currentValue("temperature")
state.talk2me = state.talk2me + "The ${op} temperature is ${arg} degrees. "
if (op == "outdoor") {
def outHU = outdoorHu.currentValue("humidity")
state.talk2me = state.talk2me + "With a relative humidity of ${outHU} percent. "
}
}
// All sensors
def environmentNounResponse(outTemp,medTemp,brTemp,dwnsTemp,frzTemp,frdTemp,gTemp,outdoorHu)
{
def otemp = outTemp.currentValue("temperature")
def mtemp = medTemp.currentValue("temperature")
def btemp = brTemp.currentValue("temperature") as Integer
def dtemp = dwnsTemp.currentValue("temperature") as Integer
def fretemp = frzTemp.currentValue("temperature")
def fritemp = frdTemp.currentValue("temperature")
def gtemp = gTemp.currentValue("temperature")
def outHU = outdoorHu.currentValue("humidity")
state.talk2me = state.talk2me + "SmartThings reports the outdoor temperature is ${otemp} degrees, with a relative humidity of ${outHU} percent. "
state.talk2me = state.talk2me + "Indoors, it is ${btemp} upstairs, and ${mtemp} downstairs. "
state.talk2me = state.talk2me + "Attic is ${dtemp} degrees, the garage is ${gtemp}. "
state.talk2me = state.talk2me + "Freezer is ${fretemp} degrees, the refridgerator is ${fritemp}. "
}
Yeah conversational commands is something I’m gonna look at this week. My main issue with Alexa is “Alexa” (I mean the keyword). I find myself many times wanting to give Alexa two or three instructions. It would be much nicer if Alexa offered a two or three second window after its response to accept another command without having to repeat the keyword.
So I am imagining something like this:
me: Alexa, ask SmartThings for control
it: How can I help?
me: set the lighting to sunset
it: Done. anything else?
me: yes, turn the heater on
it: Done. Anything else?
me: no
it: Alright then.
This so cool…I love all the different directions you guys are exploring!
Now that the mold had been cast with the link from Alexa to HA, this is going to go amazing places!
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.
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
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.