Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

How to Add Switch to trigger Google Assistant ? #18

Closed
Kinjalk opened this issue May 7, 2017 · 3 comments
Closed

How to Add Switch to trigger Google Assistant ? #18

Kinjalk opened this issue May 7, 2017 · 3 comments
Labels

Comments

@Kinjalk
Copy link

Kinjalk commented May 7, 2017

Please can you help me with adding switch to trigger google assistant ? Pressing enter every time is very annoying

@proppy proppy added the question label May 8, 2017
@proppy
Copy link
Contributor

proppy commented May 8, 2017

See the Google+ discussion about a similar topic.

@oscartprom
Copy link

We have an example of this in the Mocktails Mixer write-up. Instructions to wire the button are here and the code is here (lines of interest are mainly 150-181).

@capitalfuse
Copy link

capitalfuse commented Jun 17, 2017

sysfs method;
Pushed a switch and turn on the LED, talt to the mic and output the voice from google, and turn off the LED. Repeat this process again pushed a switch.
1. Add import sys library

import json
import logging
import os.path
import sys

2.Add the followings definitions

def read_button():
    fp1 = open("/sys/class/gpio/gpio6/value","r")
    value = fp1.read()
    return int(value)
    fp1.close()

def write_led(value):
    fp2 =  open("/sys/class/gpio/gpio20/value","w")
    fp2.write(str(value))
    fp2.close()

3. Modify the code

        while True:
            if wait_for_user_trigger:
                while True:                
                    #print(read_button())
                    button_status = read_button()
                    if button_status == 1:
                        break
            write_led(1)
                #click.pause(info='Press Enter to send a new request...')
            continue_conversation = assistant.converse()
            # wait for user trigger if there is no follow-up turn in
            # the conversation.
            wait_for_user_trigger = not continue_conversation
            write_led(0)
            # If we only want one conversation, break.
            if once and (not continue_conversation):
                break

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants