A Regex Plugin for Events

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Flyingsubs
Experienced User
Posts: 116
Joined: Sat Dec 29, 2012 11:26 pm

A Regex Plugin for Events

Post by Flyingsubs » Tue Jan 07, 2014 3:24 pm

I am not sure how to code in Python but i wanted to explore this idea. The reason i want to make a pluggin, is the ability to take a voice command send it to eventghost and the parse it. I already use the HTTP Send to eventghost and i am able to process only one command at a time.

I would like to be able to handle multiple commands: Turn off the light and turn off the computer. The pluggin would recognize the word "and" and split it up into two events and send them seperatly.

Turn off the Light
Turn off the computer.

Is this already implemented? Any one have any pointers of where to start?

Thanks,
Flyingsubs

Sem;colon
Experienced User
Posts: 589
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: A Regex Plugin for Events

Post by Sem;colon » Wed Jan 08, 2014 12:18 pm

well, you won't need a plugin to split a command into two...

your HTTP request in EG sould look like: HTTP.command [u"Turn off the light and turn off the computer"]

You can just use a phyton script like:

Code: Select all

data=eg.event.payload[0]
data=data.split(" and ")
i=0
while i<len(data):
    eg.TriggerEvent(data[i])
    i+=1
this will generate the two events:
Turn off the light
turn off the computer

(not tested)

Flyingsubs
Experienced User
Posts: 116
Joined: Sat Dec 29, 2012 11:26 pm

Re: A Regex Plugin for Events

Post by Flyingsubs » Wed Jan 08, 2014 6:15 pm

Oooh, thats a good idea. Thank you. I guess since all incoming payloads are http., i should have it always check for the "and". What if i wanted to do 3 commands in one sentence. How would the script differetiate? I guess for every "and" its splits the payload.

Well at least i have something to play around with and try out myself. Thanks again!


-Flyingsubs

Sem;colon
Experienced User
Posts: 589
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: A Regex Plugin for Events

Post by Sem;colon » Wed Jan 08, 2014 6:28 pm

Flyingsubs wrote:Oooh, thats a good idea. Thank you. I guess since all incoming payloads are http., i should have it always check for the "and". What if i wanted to do 3 commands in one sentence. How would the script differetiate? I guess for every "and" its splits the payload.

Well at least i have something to play around with and try out myself. Thanks again!


-Flyingsubs
you're welcome!

Two times " and " will generate 3 events and so on...

Flyingsubs
Experienced User
Posts: 116
Joined: Sat Dec 29, 2012 11:26 pm

Re: A Regex Plugin for Events

Post by Flyingsubs » Wed Jan 08, 2014 6:38 pm

I really want to get into the python side of eventghost. I have a few stability issues that I think would be fixed if i coded in python. Every so often a macro executes but doesn't do everything the macro was suppose to do. IE execute another macro. Seems like i might be extending the limitations of eventghost.

-Flyingsubs

Sem;colon
Experienced User
Posts: 589
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: A Regex Plugin for Events

Post by Sem;colon » Wed Jan 08, 2014 8:54 pm

Flyingsubs wrote:I really want to get into the python side of eventghost. I have a few stability issues that I think would be fixed if i coded in python. Every so often a macro executes but doesn't do everything the macro was suppose to do. IE execute another macro. Seems like i might be extending the limitations of eventghost.

-Flyingsubs
Do it, python is a nice programming language and there are many tutorials in the web!

Post Reply