Premise Amazon Echo works with Premise!

Motorola Premise

etc6849

Senior Member
I set up an Amazon Web Services (AWS) lambda function and a new Alexa Skill to control my home using Premise via an Amazon Echo.  It works in a very generic and automatic fashion too.
 
The Echo sends to AWS a plain text command string of what you ask Alexa to have Premise do.  Then an AWS lambda function and a new Alexa Skill I've defined send the command to my Premise server using HTTPS.
 
Premise then process the command string and even responds with a phrase of what was completed (for confirmation).  You can also ask questions like: "is the front door open?"
 
What Premise is doing:
The command phrase (e.g. "turn on the master bedroom light") is processed using regular expressions to automatically find the room location, get the device type (e.g. light), automatically infer the property and requested state.  All this is done by recursing locations under Home, and then recursing the objects for the matched location (to find a matching device type).  After that the objects properties are recursed (to find the property and set the value).
 
It's even smart enough to infer a PropertyName based on the object type (e.g. for "turn on", the PowerState property is inferred (if the object has that property), and its value would be set to true).  Since this method uses AWS, it's going to be very reliable and something that one could actually install for non-techie folks.
 
Finally no more Android kludge for voice control of my home using my Android Wear device (via Tasker + Autovoice + xposed framework + Google search api).  That method is reliable, but relies on Google Now which is constantly updated, so one has to update the Google search api's hooks to ensure everything keeps working after each Google Now update.  Google really missed the boat by not offering a Google Now sdk.  It took me some time to study AWS and the Echo SDK, but overall, this method is the best so far as it will work (unless Amazon goes away which is unlikely).
 
Nice work! I don't have an Echo but I'd like to have a look at the code if you're in the sharing mood. :)
 
You mentioned "recursion" and I wondered if you meant explicitly (you wrote recursive functions) or implicitly (you relied on Premise's built-in methods). For example, the following few lines will find an object by name and then set its state to either true or false.
 

sItemName = "Door Lock"
bItemState = True

set oItems = Home.GetObjectsByPropertySearch("Name", sItemName, True)
if oItems.Count > 0 then
for each oItem in oItems
debugout "Set " & bItemState & " " & oItem.Path
oItem.setvalue oItem.ValueProperty.Name, bItemState
next
else
debugout "Not found: " & sItemName
end if


The code makes two assumptions:
  1. The object has a unique name (otherwise all Home objects with the same name will be controlled).
  2. The object has a binary property (toggle on/off).
It will control anything that inherits from PowerState or DigitalOutput and it uses "ValueProperty" to simplify the code.
 
Spoken directives like "dim to 50%" would obviously need to call a different function that explicitly sets the object's Brightness value.
 
I did the code two years ago, and would like someone someone very intelligent to look it over like yourself (provided the code is not shared here due to an issue I had with the moderators and another user, I've kind of quit supporting cocoontech altogether), and give feedback (please).
 
The code you are using would work very efficiently.  On my setup, I have a property value and property name global script that uses tons of regexps to extract the property name and implied or actual value.  It also accounts for any consistent speech recognition errors such as "paul" = "pause", etc...
 
I also have a thing I call "pseudo objects," that lets you say: "turn on the kitchen."  This would turn on the kitchen lights, of it there's a mediazone in there, it would turn that on instead.
 
Do you have an Android device with Tasker and Autovoice installed?  That is all you need to test it, and the easiest way to get started.  The Echo looks like it will need a plain language number to number global script (e.g. Twenty Five = 25).  Google already does this conversion for you.  My Echo will not come until Tuesday, but this is how the virtual Echo Service Simulator in the SDK is working right now as I control my house using Amazon's cloud.
 
I'll send you the Tasker javascript and the module, but you have to actually purchase Tasker and Autovoice as I never made a standalone app just for this purpose.  You just link the javascript to a Tasker profile that passes an autovoice recognized regular expression ".*"  The javascript in Tasker is very easy to follow...
 
You can also test things by sending words to the mb function, but ensure the words are formatted in a way that is valid for a URL.  I just used underscores to separate words in a URL.
 
Oops, to answer your recursion question: I use global scripts that rely on a boolean flag for recursion, and of course use some of Premise's built-in methods that recurse.
 
Just go to: sys://Schema/Modules/SpeechParser/GlobalScripts/.  The global scripts do all the processing needed, and are in order and *hopefully* well commented.
 
Sorry to hear circumstances have led to a deep divide. I'll respect your wishes.
 
I don't have an Android device handy. My current interest in the Echo is purely academic; just curious to know how it is implemented. 
 
Thanks for the Amazon links. I didn't realize you can get free AWS for a trial period.
 
Yeah, the other half of it is I was spending too much free time on here, and there weren't enough users for any of the projects I had worked on.  Several of the modules on here took some time to document and might have two users (e.g. the Event Ghost module I built).  I know you probably feel the same way, as your stuff is always very well documented and structured.  It is clear Premise is a labor of love for you also.
 
Obviously, there are a lot of really smart folks here, and you personally have taught me all sorts of stuff.  I think of things in a much more logical and ordered fashion even in daily life thanks to your mentoring.  I'm not in IT in my daily job, so I will never have the knowledge you do though.
 
I think it's wiser going forward for me to post modules on other sites regardless (e.g. http://forum.kodi.tv/index.php), that way Premise hopefully gets a bigger user base.
 
BTW, the AWS Free Tiers never expire for many of the AWS services from what I understand.  You just have to stay under whatever cap.  I sent you an email discussing the fees, and also included a few questions on how to implement an Amazon Echo app.

 
123 said:
Sorry to hear circumstances have led to a deep divide. I'll respect your wishes.
 
Wow Ellery, do you ever sleep?  The Echo seems like an interesting device.  It will be a while before the wife will let me spend any money on one, but your work might help me convince her ;)  
 
 
 
I appreciate everyone's work on Premise, I got into it late in the game, but you guys are great.
 
If the Echo did multiroom audio, like a Sonos, it would be perfect.  That and having the ability to change the attention word to something besides Alexa and Amazon :)
 
But THIS does make me think it might be worth buying, when my wife lets me :)
 
It will, but only via a fully mSense compatible module like the KODI module I'm working on.  I'll be able to say "Alexa, ask Premise to play album hotel california in the master bedroom" or "Alexa, ask Premise to play movie 12 Monkeys in the great room."  Only KODI support will be guaranteed to work though as I didn't write the Sonos module and don't know how it's setup.
 
samgreco said:
If the Echo did multiroom audio, like a Sonos, it would be perfect.
 
Well, I actually meant having the Echo play music in sync from one to another.  Then I could do away with the matrix switch altogether.
 
PS: there will be two choices here:  each of you goes through setting up your own AWS account and Echo developer account (complicated, but I'll post a youtube video and hopefully someone donates some for my time).
 
Or each of you will pay a yearly fee to cover the cost of using AWS and we have common AWS code.  I don't know what this cost will be until I use it more.  
 
Right now, I'm guessing about ~$1 per month as the S3 puts required will almost certainly exceed the free tier limit. 
 
EDIT: Well, actually I played with the Echo all night and on a gained a few more S3 puts.  I think almost all of us will remain under the free tier limit for AWS.  I'm not sure what I was doing to gain so many S3 puts originally, but I was playing with other stuff.
 
You'll have to ask Amazon about that...  The Echo can't receive unsolicited events according to the SDK, so this will never happen is my guess.  This is  unfortunate as I'd like to send messages to it using an HTTP GET that points to my AWS lambda function, but can't.
 
The KODI module however, lets you join a zone that you already have content playing in ;)
 
samgreco said:
Well, I actually meant having the Echo play music in sync from one to another.  Then I could do away with the matrix switch altogether.
 
Here's how things work within Premise Builder for the above example:  https://www.youtube.com/watch?v=AqmC1gXqrR4
 
That is awesome.  I need you to come to my house and setup all my devices like that.  Great work.
 
Have you released the updated KODI module?  I still want to get that working.  Also, you mention Tasker.  Do you use Bluetooth, wifi, GPS, NFC, or something else to trigger the away from home stuff?
 
Back
Top