shivasiddharth / GassistPi

Google Assistant for Single Board Computers
Other
1.02k stars 304 forks source link

[Question] Can't modify "actions.py" to invoke a shell script via GA voice command - what am i doing wrong? #212

Closed jabulonboaz closed 6 years ago

jabulonboaz commented 6 years ago

@shivasiddharth and all why when i amend the "actions.py" file like this (bellow) GA does not startup at boot any more? when i comment out all my amendments it works again. I have a script that switches on and off the WiFi of my router that works when i execute it from a terminal in the Pi3 that i have GassistPi running and i am trying to invoke it via a voice command similar to the one you created for "shutdown" . e.g. "Hey Google trigger internet" and then sudo ./myscript.sh is executed. I have been trying many different combinations for some time to get it to work but i am no coder i am afraid. if anyone can please help me unstuck i will be graceful.

GPIO Device Control

def Action(phrase): if 'script' in phrase: say("Script running") time.sleep(10) os.system("sudo /home/pi/myscript.sh")

subprocess.call(["sudo ./myscript.sh"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if 'shutdown' in phrase:
    say("Shutting down Raspberry Pi")
    time.sleep(10)
    os.system("sudo shutdown -h now")
    #subprocess.call(["shutdown -h now"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Enzoinventor commented 6 years ago

all the changes you create in action.py must also be called in main.py

jabulonboaz commented 6 years ago

There was no need to change anything in main.py unless you want to change the trigger word but I left it as it was. I found the solution and it was really very simple I am surprised nobody pointed it out to me before. I removed side and it worked this is an example of the code that I inserted near the end of the actions.py file near the ‘trigger shutdown’ part.

if 'script' in phrase: say("Initiating script") os.system("./my script.sh")

And this is how you can voice trigger run a shell script file locally in GassistPi and I bet it works with GA AYI too