Amazon Echo Skill EchoToEventGhost

If you have a question or need help, this is the place to be.

Re: Amazon Echo Skill EchoToEventGhost

Postby blaher » Sun Jul 10, 2016 4:10 am

How can I define what utterance, or phrase, etc., Alexa should be expecting?

I'd like to say, 'Alexa, tell INVOCATION NAME we're going upstairs', but it often gets it wrong with 'where going upstairs', or other stuff not even close. Is there a way to help her out?

And on a separate note: is there a way to go the other way, i.e., an Eventghost event triggers a voice response in Alexa. It could be handy with home automation, e.g., if motion is detected, or if someone rings the doorbell, or you get a new email, whatever the event may be, Alexa could announce that. That would be pretty cool. :)

Cheers!
blaher
Experienced User
 
Posts: 440
Joined: Thu Nov 17, 2011 1:27 am

Re: Amazon Echo Skill EchoToEventGhost

Postby DanRoss » Tue Jul 12, 2016 2:28 am

blaher wrote:How can I define what utterance, or phrase, etc., Alexa should be expecting?

I'd like to say, 'Alexa, tell INVOCATION NAME we're going upstairs', but it often gets it wrong with 'where going upstairs', or other stuff not even close. Is there a way to help her out?

The easiest thing would be to say 'Alexa, tell INVOCATION NAME we are going upstairs' and use that for your stuff

I personally use a python script to parse eg.event.payload[0] which is where 'we're going upstairs' is passed along. With that you can have it look for 'going upstairs' and use just those words to trigger your event.

The other option is to use blackbox service Brandon uses. I haven't used it myself since I find it easier to do it all in python

And on a separate note: is there a way to go the other way, i.e., an Eventghost event triggers a voice response in Alexa. It could be handy with home automation, e.g., if motion is detected, or if someone rings the doorbell, or you get a new email, whatever the event may be, Alexa could announce that. That would be pretty cool. :)

Cheers!


This is a limitation on Alexa. I wish Amazon would enable this feature also, I'd love to have her announce when a door is opened or if my vera is in away mode have her start a count down till my alarm goes off. I'm probably going to do this with my PC I just haven't had time to play with it yet.
DanRoss
 
Posts: 19
Joined: Wed Mar 23, 2016 2:15 am

Re: Amazon Echo Skill EchoToEventGhost

Postby blaher » Tue Jul 12, 2016 6:48 am

DanRoss wrote:The easiest thing would be to say 'Alexa, tell INVOCATION NAME we are going upstairs' and use that for your stuff

Thanks, that's far more accurate, but I forget sometimes. :)

I personally use a python script to parse eg.event.payload[0] which is where 'we're going upstairs' is passed along. With that you can have it look for 'going upstairs' and use just those words to trigger your event.

Would you mind sharing your code, please? I have no idea how to start, but by copying an example, I might have a fighting chance.

The other option is to use blackbox service Brandon uses. I haven't used it myself since I find it easier to do it all in python

Easier sounds better to me!

This is a limitation on Alexa. I wish Amazon would enable this feature also, I'd love to have her announce when a door is opened or if my vera is in away mode have her start a count down till my alarm goes off. I'm probably going to do this with my PC I just haven't had time to play with it yet.

Oh, I see, thanks for the info. Hopefully it's just a matter of time before they do, or someone hacks a way around it.
blaher
Experienced User
 
Posts: 440
Joined: Thu Nov 17, 2011 1:27 am

Re: Amazon Echo Skill EchoToEventGhost

Postby kgschlosser » Tue Jul 12, 2016 11:41 am

DanRoss wrote:This is a limitation on Alexa. I wish Amazon would enable this feature also, I'd love to have her announce when a door is opened or if my vera is in away mode have her start a count down till my alarm goes off. I'm probably going to do this with my PC I just haven't had time to play with it yet.


are you familiar with the MicasaVerdeVera Plugin?

http://eventghost.org/forum/viewtopic.p ... fb2c76dade

if you are using it could you please tell me if the functionality of the alarm works or not? and if i can improve it in some way please let me know. i do not have any of the alarm pieces hooked up. and i do not know if you are using an alarm panel interface or just security sensors. but either way i can change how the plugin functions on that side of things and also add vera plugin support. there is no standardization on that side of things for the vera so one plugin doesn't have all the same variables as another and if i don't code it to be specific to a plugin it might be handicapped and not provide all of the functions that the plugin does.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Amazon Echo Skill EchoToEventGhost

Postby DanRoss » Wed Jul 13, 2016 11:52 pm

blaher wrote:
I personally use a python script to parse eg.event.payload[0] which is where 'we're going upstairs' is passed along. With that you can have it look for 'going upstairs' and use just those words to trigger your event.

Would you mind sharing your code, please? I have no idea how to start, but by copying an example, I might have a fighting chance.


My comment should have said I personally would use a python script. I don't have one for your exact purpose but if you give me an idea of what you're controlling I could probably get you something to start with.

Currently I use it to convert a word number to a decimal number (I.e. convert ten to 10) I also have a script to parse the string I get from alexa and email parts of that string to a custom shopping list so I can say "Alexa, tell the grocery list to add thing one and thing two and thing three and thing four" and my custom grocery shopping list will have a separate line for each thing.

The other option is to use blackbox service Brandon uses. I haven't used it myself since I find it easier to do it all in python

Easier sounds better to me!


Easier for me may not be easier for you. If you're not familiar with python or something close to it you may not think it's easier. I've done a lot with Raspberry Pi and Arduino so after my crash course with that I can hack together python with the help of google..
DanRoss
 
Posts: 19
Joined: Wed Mar 23, 2016 2:15 am

Re: Amazon Echo Skill EchoToEventGhost

Postby DanRoss » Wed Jul 13, 2016 11:58 pm

kgschlosser wrote:
DanRoss wrote:This is a limitation on Alexa. I wish Amazon would enable this feature also, I'd love to have her announce when a door is opened or if my vera is in away mode have her start a count down till my alarm goes off. I'm probably going to do this with my PC I just haven't had time to play with it yet.


are you familiar with the MicasaVerdeVera Plugin?

http://eventghost.org/forum/viewtopic.p ... fb2c76dade

if you are using it could you please tell me if the functionality of the alarm works or not? and if i can improve it in some way please let me know. i do not have any of the alarm pieces hooked up. and i do not know if you are using an alarm panel interface or just security sensors. but either way i can change how the plugin functions on that side of things and also add vera plugin support. there is no standardization on that side of things for the vera so one plugin doesn't have all the same variables as another and if i don't code it to be specific to a plugin it might be handicapped and not provide all of the functions that the plugin does.


I had the plugin going once but I stopped using it for some reason that I don't remember. I will say it isn't necessary for the stuff I do. For anything that needs to be done between EG and Vera I just use http actions.
DanRoss
 
Posts: 19
Joined: Wed Mar 23, 2016 2:15 am

Re: Amazon Echo Skill EchoToEventGhost

Postby m19brandon » Sun Sep 25, 2016 6:15 am

Hopefully the Alexa API will open up soon. Telling us the door was just opened would be very useful.

There is also no ID per Echo device past in the payload, so if you have a Family Room and Bedroom Echo it makes room selection interesting while programming.
m19brandon
Experienced User
 
Posts: 171
Joined: Mon Feb 03, 2014 10:36 pm

Re: Amazon Echo Skill EchoToEventGhost

Postby blaher » Mon Sep 26, 2016 12:17 am

Someone PMed me asking for an example of how I use this plugin, so here it is:

I haven't figured out the 'intent' bit of the skill, so it's not expecting 'pause', in this example...a bit dodgy; thus the permutations, or mishearings of 'pause', and 'press pause'.
Attachments
aCapture.JPG
blaher
Experienced User
 
Posts: 440
Joined: Thu Nov 17, 2011 1:27 am

Re: Amazon Echo Skill EchoToEventGhost

Postby m19brandon » Wed Sep 28, 2016 3:41 am

Looking good.

The example intent file should leave Alexa wild over to accept just about anything said.

I think you can also use a wildcard event. EventToEG.*pause*

Or a python script to search the payload for pause and fire a trigger if true.
Code: Select all
cmd = eg.event.payload[0]
if 'pause' in cmd:
   eg.TriggerEvent('PauseMe');
else:
   print 'Command is unknown: ' + cmd'
m19brandon
Experienced User
 
Posts: 171
Joined: Mon Feb 03, 2014 10:36 pm

Re: Amazon Echo Skill EchoToEventGhost

Postby Phil » Tue Oct 04, 2016 11:05 am

Hi
I got an echo last week and got this to work briefly.
One of the bits im not clear about is with the alexa skills part, it takes you through the various steps Skill Information, Interaction Model, Configuration, Test. But then the next step is publish, presumably to the skills store or...? It doesnt seem like something I would want to do.
I can see the skill in the alexa app on my phone and it did work for a while but now I get an error each time, is that because its not published?

thanks

Phil
Phil
Experienced User
 
Posts: 105
Joined: Tue Apr 15, 2014 10:42 am
Location: Merseyside, UK

Re: Amazon Echo Skill EchoToEventGhost

Postby blaher » Wed Oct 05, 2016 11:48 pm

Phil wrote:I can see the skill in the alexa app on my phone and it did work for a while but now I get an error each time, is that because its not published?


No, as you said, you don't want to publish it. Do you get a green tick on the test step of this page?
https://developer.amazon.com/edw/home.html#/skill/
blaher
Experienced User
 
Posts: 440
Joined: Thu Nov 17, 2011 1:27 am

Re: Amazon Echo Skill EchoToEventGhost

Postby Phil » Tue Oct 11, 2016 9:41 am

Yes, Ive got all the ticks.
I think the issue is getting the response from EG back to the echo.
Am I right in thinking the {{bb_response}} in the index.html file is the response? so if I populate that variable in EG is should get back to the echo?
Phil
Experienced User
 
Posts: 105
Joined: Tue Apr 15, 2014 10:42 am
Location: Merseyside, UK

Re: Amazon Echo Skill EchoToEventGhost

Postby Phil » Wed Oct 12, 2016 9:48 am

All seems to be working well now. thanks!

If its of any use to anyone, this is the code im using (im not a programmer so there is sure to be a much neater way to do this).
It works via a csv file that has two columns, this compares words received with a list of keywords. For example if you were to say TV or television they would both return the result tv to trigger an event.
the csv files looks like this

television,tv
tv,tv
lounge,lounge
living,lounge
on,on
off,off
kill,off
etc...
the script then takes all matched keywords, removes duplicates, puts them in alphabetical order and triggers an event. This should then limit the number of triggers needed to set on macros. It means if you say "turn on the television" or "turn the tv on" you will generate a trigger called on-tv for both. If it doesn't find any words it creates a not.known event

May be no use to anyone but thought I'd share anyway.
Code: Select all
import csv

#On the line below change your path to point to the csv file
#the csv should have lines with item,standard
#eg television,tv
csv_location = 'c:\mycsv\mycsv.csv'

eg.globals.action = eg.event.payload[0]
#To setup comment the line above and uncomment the line below, type in what you need
#eg.globals.action = "school lunch tomorrow"

known_list = {} # this is an empty dictionary

with open(csv_location) as csvfile:
    readCSV = csv.reader(csvfile)
    for row in readCSV:
        known_list[row[0]] = row[1]

what_said = eg.globals.action.split(' ')

results = [(item, known_list[item]) for item in what_said if item in known_list] #compares input to csv to find keywords

res_list = [i[1] for i in results] #Remove the first column of data
res_list = list(set(res_list)) #Remove any duplicate keyword entries
res_list.sort() # Sort the list
print res_list

eg.globals.echotrigger = '-'.join(res_list) # Convert list to a string with a - separator

if len(res_list)<1:
    eg.globals.echotrigger = "not.known" #checks that the are any keywords and gives not know if there isnt

eg.plugins.EventGhost.TriggerEvent(u'{eg.globals.echotrigger}', 0.0)



At the end of each macro, if needed I add the action to set the string on the website to give the response to echo (remembering the Return Msg: part which is mentioned in an earlier post, or cmd is unknown: for the failed one)
Phil
Experienced User
 
Posts: 105
Joined: Tue Apr 15, 2014 10:42 am
Location: Merseyside, UK

Re: Amazon Echo Skill EchoToEventGhost

Postby wacind » Fri Oct 21, 2016 6:29 pm

Guys

I'm sorry but can someone help me out here:
I am unable to connect to my eventghost.

Here is what i've done so far

1) I enabled the webserver plugin. Set my port to 5000. Set my Documents root folder to the folder provided by m19brandon which contains index.html

2) Port forwarded my port and IP on my router

3) Created a Lambda Function and i've pasted the code posted by m19brandon.
- I typed in my EG_ip into the code
- I typed in my EG_Port = '5000'
Its configured to Node js 4.3. Handler = index.handler, Role = Choose and existing role, Existing role = lambda_basic_execution. No VPC. Triggered to 'Alexa Skills Kit'

4) I went into the Amazon developer console and under Alexa created a new 'Alexa Skills Kit'
- Set Skill Type to "Custom"
- Gave it a name "eventghost"
- gave it an invocation name 'EG'

5) copied the Intent Schema and Sample Utterances from m19brandon files.

6) Set the endpoint to 'AWS Lambda ARN' instead of HTTPS. Selected North America and in the service endpoint text box pasted my arn:aws code "arn:aws:lambda:us-east-1:555555555555:function:EventGhost"

7) set account linking to "no" and set test to enabled.


Now here is where i believe i am messing up:
When i go back to 'Skill Information' under the developer console, the Application ID = "amzn1.ask.skill.55c555ff-0555-555b-a555-a5555555555c"
Now i assume i am suppose to paste the numeric part of this application id in the Lambda Function code that was provided by m19brandon but the format is different. m19brandon's code starts off with "amzn1.echo-sdk-ams.app." where as the application id is "amzn1.ask.skill"

in the Lambda Function, when i run test i get ""errorMessage": "Invalid Application ID"'

and in the skills when i run a test i get
"The remote endpoint could not be called, or the response it returned was invalid."

Would appreciate some help in setting this up. Thanks

*** EDIT:
looks like i found out whats happening. Amazon changed the way app IDs are listed (https://forums.developer.amazon.com/que ... ged-f.html)
So i commented this out
Code: Select all
if (event.session.application.applicationId !== Echo_App_ID) {
               context.fail("Invalid Application ID");


and things seem to be working now.

Also thanks so much m19brandon! This is a great addition to EG
wacind
 
Posts: 20
Joined: Fri Jan 30, 2015 6:50 pm

Re: Amazon Echo Skill EchoToEventGhost

Postby rdgerken » Wed Nov 23, 2016 2:59 am

Thanks for all the help with this guys - I used bits and pieces from all of your posts to get something working pretty good for my home.

I ended up reworking the CSV script that someone here posted as a starting point, and used a MySQL database instead. I have some tables in here to define the devices in my system, and a separate table with speech phrases for each "device" - and then with some parsing and some more sophisticated queries (Natural language full text search which then falls back to a LIKE query) - it seems to get the proper device almost every time, but to be fair, I did spend quite a bit of time on my "speechphrase" table, making sure I put in most every combination I could think of for phrases that people would use to control a specific device. I doubt that the LIKE query is actually all the helpful, unless the phrase is really short to begin with. Using the MySQL database was also nice because it allows me to store custom responses for the different scenes or devices as well to make it a little bit more fun.

There was some brute forcing as far as the parsing goes... I was surprised to see Alexa return numbers in full english - like "twenty three" instead of "23" - so that took a bit of messing around for when I say something like - "set office light to level 23". Parsing the integer out would have been WAY easier. I'm a bit of a python hack though... so I'm sure somebody that knows what they are doing could probably have found a much easier way. -So after some research on this, it seems like if you were able to make use of slot variables, then Alexa could return numbers to you instead of language - but that's ok - I like it this way because it gives the most flexibility, if I understand how this works.

Overall, seems to work very well. The only issue that I have, is that it seems about 1 out of every 5 times or so - The response back to Amazon doesn't work. Seems like maybe it's a timing thing or something, but I'm not sure. If anyone has any ideas on that, please let me know.

Next up - tying in Google Assistant / Siri...

If any of you Alexa gurus out there know how to rework the code that Brandon posted to use the smart home groups instead of the lambda invocation word - I'd be interested in that. It seems much more natural to not have to say the invocation phrase. I named my invocation phrase to "the house" - so that you say "Alexa, ask the house to turn off...whatever..." - and it's not too bad that way, but not as nice as just saying "Alexa, turn off ... whatever"

Thanks for the contributions!

Code: Select all
import MySQLdb

MySQLdb_IP = "xx"
MySQLdb_User = "xx"
MySQLdb_Password = "xx"
MySQLdb_Database = "xx"

#Initialize the response in case this script does not set it to something valid
eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "EventGhost Macro Error", False, False)

#Use this line to test without Alexa
#voice = "change the television input to tivo"
voice = eg.event.payload[0]
print "Incoming Alexa Speech = " + voice

#Initialize Zone, SubID, DeviceName, ClassType, ResponseOverride, and Level variables
zone=-1
subid=-1
devicename=""
classtype=""
responseoverride=""
level=-1
levelsuffix=""

#Filter unneeded words from speech for better matching
voice=voice.replace("the"," ")
voice=voice.replace("to"," " )
voice=voice.replace("turn"," " )
voice=voice.replace("set"," " )
voice=voice.replace("please"," " )
voice=voice.replace("change"," " )
voice=voice.replace("level"," " )
voice=voice.replace("percent"," " )
voice=voice.replace("activate"," " )
voice=voice.replace("scene"," " )
voice=voice.replace("'","" )

#Remove whitespace & split into words
voice=voice.strip()
voicewords=voice.split()

#Parse sublevels out if there is one present, before handling levels
if "dash one" in voice:
    levelsuffix="-1"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash two" in voice:
    levelsuffix="-2"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash three" in voice:
    levelsuffix="-3"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash four" in voice:
    levelsuffix="-4"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash five" in voice:
    levelsuffix="-5"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash six" in voice:
    levelsuffix="-6"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash seven" in voice:
    levelsuffix="-7"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash eight" in voice:
    levelsuffix="-8"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""
elif "dash nine" in voice:
    levelsuffix="-9"
    voicewords[voicewords.index("dash")+1] = ""
    voicewords[voicewords.index("dash")] = ""

if "high" in voicewords:
    level=100
    voicewords[voicewords.index("high")] = ""
elif "medium" in voicewords and "high" in voicewords:
    level=75
    voicewords[voicewords.index("medium")] = ""
    voicewords[voicewords.index("high")] = ""
elif "medium" in voicewords:
    level=50
    voicewords[voicewords.index("medium")] = ""
elif "low" in voicewords:
    level=25
    voicewords[voicewords.index("low")] = ""
elif "on" in voicewords:
    level=100
    voicewords[voicewords.index("on")] = ""
elif "off" in voicewords:
    level=0
    voicewords[voicewords.index("off")] = ""
elif "ten" in voicewords:
    level=10
    voicewords[voicewords.index("ten")] = ""
elif "eleven" in voicewords:
    level=11
    voicewords[voicewords.index("eleven")] = ""
elif "twelve" in voicewords:
    level=12
    voicewords[voicewords.index("twelve")] = ""
elif "thirteen" in voicewords:
    level=13
    voicewords[voicewords.index("thirteen")] = ""
elif "fourteen" in voicewords:
    level=14
    voicewords[voicewords.index("fourteen")] = ""
elif "fifteen" in voicewords:
    level=15
    voicewords[voicewords.index("fifteen")] = ""
elif "sixteen" in voicewords:
    level=16
    voicewords[voicewords.index("sixteen")] = ""
elif "seventeen" in voicewords:
    level=17
    voicewords[voicewords.index("seventeen")] = ""
elif "eighteen" in voicewords:
    level=18
    voicewords[voicewords.index("eighteen")] = ""
elif "nineteen" in voicewords:
    level=19
    voicewords[voicewords.index("nineteen")] = ""
elif "twenty" in voicewords:
    level=20
    voicewords[voicewords.index("twenty")] = ""
elif "thirty" in voicewords:
    level=30
    voicewords[voicewords.index("thirty")] = ""
elif "forty" in voicewords:
    level=40
    voicewords[voicewords.index("fourty")] = ""
elif "fifty" in voicewords:
    level=50
    voicewords[voicewords.index("fifty")] = ""
elif "sixty" in voicewords:
    level=60
    voicewords[voicewords.index("sixty")] = ""
elif "seventy" in voicewords:
    level=70
    voicewords[voicewords.index("seventy")] = ""
elif "eighty" in voicewords:
    level=80
    voicewords[voicewords.index("eighty")] = ""
elif "ninety" in voicewords:
    level=90
    voicewords[voicewords.index("ninety")] = ""
elif "hundred" in voicewords:
    level=100
    voicewords[voicewords.index("hundred")] = ""
    voicewords[voicewords.index("one")] = ""

if level>=20 or level==-1:
    if "zero" in voicewords:
        if level==-1:
            level=0
        else:
            level=level+0
        voicewords[voicewords.index("zero")] = ""
    elif "one" in voicewords:
        if level==-1:
            level=1
        else:
            level=level+1
        voicewords[voicewords.index("one")] = ""
    elif "two" in voicewords:
        if level==-1:
            level=2
        else:
            level=level+2
        voicewords[voicewords.index("two")] = ""
    elif "three" in voicewords:
        if level==-1:
            level=3
        else:
            level=level+3
        voicewords[voicewords.index("three")] = ""
    elif "four" in voicewords:
        if level==-1:
            level=4
        else:
            level=level+4
        voicewords[voicewords.index("four")] = ""
    elif "five" in voicewords:
        if level==-1:
            level=5
        else:
            level=level+5
        voicewords[voicewords.index("five")] = ""
    elif "six" in voicewords:
        if level==-1:
            level=6
        else:
            level=level+6
        voicewords[voicewords.index("six")] = ""
    elif "seven" in voicewords:
        if level==-1:
            level=7
        else:
            level=level+7
        voicewords[voicewords.index("seven")] = ""
    elif "eight" in voicewords:
        if level==-1:
            level=8
        else:
            level=level+8
        voicewords[voicewords.index("eight")] = ""
    elif "nine" in voicewords:
        if level==-1:
            level=9
        else:
            level=level+9
        voicewords[voicewords.index("nine")] = ""

#Remove empty words removed by level extraction
voicewords=filter(None, voicewords)

#Use MySQL Database to search speech phrases
searchstring=""
for word in voicewords:
    searchstring+=" +%s" % (word.strip())
db = MySQLdb.connect(MySQLdb_IP,MySQLdb_User,MySQLdb_Password,MySQLdb_Database)
cursor = db.cursor()
strQuery="SELECT D.DeviceID AS Zone, S.SubID, D.Device, C.Class, S.ResponseOverride FROM Speech AS S JOIN Devices AS D ON S.DeviceID=D.DeviceID JOIN DeviceClasses AS C ON D.ClassID=C.ClassID WHERE MATCH (SpeechPhrase) AGAINST ('" + searchstring + "' IN NATURAL LANGUAGE MODE) LIMIT 1"
cursor.execute(strQuery)
try:
    variablefetch = cursor.fetchone ()
    zone=variablefetch[0]
    subid=variablefetch[1]
    devicename=variablefetch[2]
    classtype=variablefetch[3]
    responseoverride=variablefetch[4]
    print "NaturalLanguage_Search=" + searchstring + ", ZoneID=" + str(zone) + ", SubID=" + str(subid) + ", ClassType=" + classtype + ", Level=" + str(level)
except Exception:
    try:
        print "Natural Speech Search failed - trying LIKE query"
        searchstring=""
        for word in voicewords:
            searchstring+="%%%s%%" % (word.strip())
        strQuery="SELECT D.DeviceID AS Zone, S.SubID, D.Device, C.Class, S.ResponseOverride FROM Speech AS S JOIN Devices AS D ON S.DeviceID=D.DeviceID JOIN DeviceClasses AS C ON D.ClassID=C.ClassID WHERE SpeechPhrase LIKE '" + searchstring + "' LIMIT 1"
        cursor.execute(strQuery)
        variablefetch=cursor.fetchone ()
        zone=variablefetch[0]
        subid=variablefetch[1]
        devicename=variablefetch[2]
        classtype=variablefetch[3]
        responseoverride=variablefetch[4]
        print "LIKE_Search=" + searchstring + ", ZoneID=" + str(zone) + ", SubID=" + str(subid) + ", ClassType=" + classtype + ", Level=" + str(level)
    except Exception:
        print "No records found using Natural Speech or LIKE queries for: " + str(voicewords)
        zone=-1
cursor.close()
db.close()

#Return unknown command if no zone is found in CSV, otherwise process command
if zone==-1:
    eg.plugins.Webserver.SetValue(u"bb_response", "\ncmd is unknown: ", False, False)
else:
    if classtype=="TV": #Television Command
        if zone==1000: #Family Room Television Command
            if level != -1: #This must be a power on/off command
                if level==100:
                    state="on"
                else:
                    state="off"
                eg.TriggerEvent("LGTV", prefix="Alexa", payload=["power", state ])
                eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "turning television " + str(state), False, False)
            else:  #This must be a volume event
                if "up" in voicewords:
                    eg.TriggerEvent("LGTV", prefix="Alexa", payload=["volume", "up"])
                    eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "ok", False, False)
                elif "down" in voicewords:
                    eg.TriggerEvent("LGTV", prefix="Alexa", payload=["volume", "down" ])
                    eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "ok", False, False)
                elif "mute" in voicewords or "unmute" in voicewords:
                    eg.TriggerEvent("LGTV", prefix="Alexa", payload=["volume", "mute" ])
                    eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "ok", False, False)
                elif "tivo" in voicewords:
                    eg.TriggerEvent("LGTV", prefix="Alexa", payload=["input", "tivo" ])
                    eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "ok", False, False)
                elif "fire" in voicewords:
                    eg.TriggerEvent("LGTV", prefix="Alexa", payload=["input", "fire tv" ])
                    eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "ok", False, False)
                elif "chromecast" in voicewords:
                    eg.TriggerEvent("LGTV", prefix="Alexa", payload=["input", "chromecast" ])
                    eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "ok", False, False)
                else:
                    eg.plugins.Webserver.SetValue(u"bb_response", "\ncmd is unknown: ", False, False)
    elif classtype=="Tivo Mini": #Tivo Mino Command
        if zone==1001: #Family Room Tivo Command
            if "channel" in voicewords:
                eg.TriggerEvent("TivoMini", prefix="Alexa", payload=["channel", str(level), levelsuffix])
            elif "pause" in voicewords:
                eg.TriggerEvent("TivoMini", prefix="Alexa", payload=["pause"])
            elif "play" in voicewords or "resume" in voicewords:
                eg.TriggerEvent("TivoMini", prefix="Alexa", payload=["play"])
            else:
                eg.plugins.Webserver.SetValue(u"bb_response", "\ncmd is unknown: ", False, False)
    elif classtype=="Security System": #Security System Command
        if "away" in voicewords:
            eg.plugins.Envisalink.ArmAway()
            eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "Security System Armed Away", False, False)
        elif "stay" in voicewords:
            eg.plugins.Envisalink.ArmStay()
            eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "Security System Armed Stay", False, False)
        elif level==0 or "disarm" in voicewords:
            eg.plugins.Envisalink.Off()
            eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "Security System Disarmed", False, False)
        else:
            eg.plugins.Webserver.SetValue(u"bb_response", "\ncmd is unknown: ", False, False)
    else:  #RadioRA2 Command
        if any(classtype in ct for ct in ["Maestro","SivoiaQS","Fan","MaestroDiscrete"]):
            if responseoverride is not None:
                eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + responseoverride, False, False)
            else:
                if classtype=="MaestroDiscrete":
                    if level==0:
                        eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "Setting " + devicename + " off", False, False)
                    else:
                        eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "Setting " + devicename + " on", False, False)
                else:
                    eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "Setting " + devicename + " to level " + str(level), False, False)
            command = "#OUTPUT," + str(zone) + ",1," + str(level)
            eg.plugins.LutronRadioRA2.MyCommand(command)
        elif classtype=="Keypad" and subid is not None:
            if responseoverride is not None:
                eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + responseoverride, False, False)
            else:
                eg.plugins.Webserver.SetValue(u"bb_response", "\nReturn Msg: " + "Activating scene " + devicename, False, False)
            command = "#DEVICE," + str(zone) + "," + str(subid) + ",3"
            eg.plugins.LutronRadioRA2.MyCommand(command)
        else:
            eg.plugins.Webserver.SetValue(u"bb_response", "\ncmd is unknown: ", False, False)
#Done
rdgerken
Experienced User
 
Posts: 85
Joined: Fri Sep 21, 2012 7:41 pm

PreviousNext

Return to General Support

Who is online

Users browsing this forum: Google [Bot] and 1 guest