1
votes

I have set up Google Assistant with Raspberry Pi. I'd like to define a custom action, but it's not working. The Google Assistant recognizes the sentence, but does nothing. Here's a log. How do I fix it?

I've edited action.py to put my code

class SwitchControl(object):
        """Control a RC-Socket"""


        COMMAND_ON = 'sudo /home/pi/rcswitch-pi/send 00111 3 1'
        COMMAND_OFF = 'sudo /home/pi/rcswitch-pi/send 00111 3 0'


        def __init__(self, say, toggle):
                self.say = say
                self.toggle = toggle

        def run(self, voice_command):
                try:
                        if (self.toggle == 'ON'):
                                self.say(_('Turning switch on.'))
                                for i in range(10):
                                        subprocess.call(SwitchControl.COMMAND_ON, shell=True)
                        elif (self.toggle =='OFF'):
                                self.say(_('Turning switch off.'))
                                for i in range(10):
                                        subprocess.call(SwitchControl.COMMAND_OFF, shell=True)
                except (ValueError, subprocess.CalledProcessError):
                        logging.exception("Error using codesend to toggle rc-socket.")            self.say("Sorry I didn't identify that command")

    # =========================================
    # Makers! Add your own voice commands here.
    # =========================================

    actor.add_keyword(_('pi power off'), PowerCommand(say, 'shutdown'))
    actor.add_keyword(_('pi reboot'), PowerCommand(say, 'reboot'))
    actor.add_keyword(_('switch on'), SwitchControl(say, 'ON'))
    actor.add_keyword(_('switch off'), SwitchControl(say, 'OFF'))
    return actor
1
i start google assistant with google-assistant-demo maybe a clue - aimen06
I manage to use google cloud speech api for local action with typing a terminal python3 src/main.py -T gpio --cloud-speech - aimen06
the script start [2017-07-17 22:26:26,389] INFO:recorder:started recording - aimen06
and when i press the button nothing happen whereas using the Assistant and the trigger ok-google works :( - aimen06

1 Answers

0
votes

Ok finally i manage to make it works :) First thing you need to know to make local action you need to use cloud speech. Then i was stuck because in my terminal when i start google assistant i wasn't seeing : [2017-07-26 09:25:20,672] INFO:main:ready... Press the button on GPIO 23 then speak, or press Ctrl+C to quit...

I was only seeing START RECORDING

So i grab an image of pixel raspbian for magpi and it was working with with this distrib and then i have put my old sdcard with my raspbian to retest and tada it was working !!!