How to Build a DIY Google Home Assistant With Raspberry Pi

Ian Buckley 22-10-2018

Voice controlled assistants have quickly become commonplace. Many homes have an Alexa or Google Home controlling everything from lighting to media, and even timekeeping.


The technology these devices run on is available—at least in part—to everyone. Google’s Assistant SDK allows you to use the service on your own devices. This tutorial covers how to set up the Google Assistant on your Raspberry Pi, and voice activate an LED via GPIO pins.

Hardware Required for a Raspberry Pi Home Assistant

Raspberry Pi Google Assistant Required Equipment

You Will Need:

  1. Raspberry Pi with a fresh Raspbian install on the SD card How to Install an Operating System on a Raspberry Pi Here's how to install an OS on your Raspberry Pi and how to clone your perfect setup for quick disaster recovery. Read More .
  2. USB webcam or microphone.
  3. External speaker.
  4. Circuit from the Pi LED tutorial How to Program Your Raspberry Pi to Control LED Lights Looking for an easy Raspberry Pi project to get started with coding and electronics? Try connecting some LEDs and coding them to turn on and off! Read More (optional)
  5. A browser signed into your Google account.

Note: The equipment for this tutorial can vary somewhat. I used a spare USB webcam purely for its microphone. Any compatible webcam or microphone should do fine, and there are extensive lists of Pi-compatible devices to help.

Also, I am using the 3.5mm output for audio. HDMI and other output sources will also work, though it will require modifications to the sound setup below.


Plug in the USB webcam and speaker, and set up the LED circuit if you are using it.

Setting Up the Sound

This tutorial can be followed directly on the Pi or via an SSH connection into the Pi.

Both ways begin in the terminal, to check the sound settings. Use the commands arecord -l and aplay -l to list available devices.

Check the Playback and Recording devices


The image above shows the USB webcam as card 1 and device 0. Take note of the card and device numbers for both microphone and speaker output.

Now, making sure you are in the /home/pi directory, create a new file and open it in nano:

sudo nano .asoundrc

The contents of this directory will differ depending on what card and device numbers you are using. This is where you can choose to favor HDMI output rather than 3.5mm if you wish.

asoundrec config file for microphone and speaker


When you’ve entered your version of the above code, press Ctrl + X to save and exit.

Test your setup by recording and playing back a short clip:

Make a test recording to check your setup

Optional Step: If you want to change the input volume of your microphone, open alsamixer and press F6 to cycle between devices.


That’s it! The sound is set up.

Creating the Google Project

Open the Pi’s browser, alternatively, if you are connected via SSH open a browser locally. Navigate to the Google Action Console and click New Project.

Create a new Google Project

This may take a few moments. When finished, leave the window active and open a new tab—we’ll be coming to this in a moment.

Enabling the Google Assistant API

There are a few online adjustments you’ll need to make to continue. Navigate to the Google Assistant API website and click Enable.

Enable the Google Assistant API

The project also requires activity permissions. Head to your Activity Control panel and make sure the following activities are turned on:

  • Web & App Activity (including Chrome History checkbox)
  • Device Information
  • Voice and Audio Activity

Changing Google Activity settings

Now you can move on to registering the device.

Registering Your Raspberry Pi

Back in the Action Console, select Device registration from the left panel. Under Product create an easy to remember name for your device. The manufacturer name isn’t important (but must be there), and select Auto for the device type.

Register your Pi as a Model

Click Register Model, and on the next screen click Download OAuth 2.0 Credentials. This downloads a JSON file to your computer. If you aren’t familiar with JSON files, don’t worry, but learning how to use JSON JSON Python Parsing: A Simple Guide There are libraries and tool-kits available for parsing and generating JSON from almost any language and environment. This article concentrates on methods and issues arising from JSON python parsing. Read More is worth doing for the future!

The official Google guide recommends moving the file to /home/pi, so open the file manager and do this now.

Extra step for SSH users:

If you are using SSH you will have downloaded the JSON file to your local machine instead of the Pi. To transfer it, open a separate terminal window with no SSH connection. From this window, copy over the client secret JSON file using this command:

scp ~/Downloads/client_secret_client-id.json pi@raspberry-pi-ip-address:/home/pi/

Replace “raspberry-pi-ip-address” with your Pi’s ip address, and don’t forget the colon before the path. If you downloaded the JSON file to another location modify your local path to reflect this. Enter your password when prompted, and the file will copy to the Pi’s home directory.

Copy the Secret Cient ID to the PI

Switch back to the SSH terminal, and navigate to /home/pi. Enter ls -l to list the files in the directory. You should see the transferred client secret JSON file.

Installing the SDK

Google recommends working in a Python virtual environment. Create a new virtual environment called env.

If you’ve never done this before, this tutorial will help you learn how to use Python virtual environments.

Install the latest versions of Pip, Setuptools and Wheel and activate your virtual environment:

env/bin/python -m pip install --upgrade pip setuptools wheel
source env/bin/activate

Google Assistant has some dependencies which you should install into the virtual environment now.

sudo apt-get install portaudio19-dev libffi-dev libssl-dev libmpg123-dev

Finally, install the Google Assistant SDK, Samples, and OAuth tool.

python -m pip install --upgrade google-assistant-library
python -m pip install --upgrade google-assistant-sdk[samples]
python -m pip install --upgrade google-auth-oauthlib[tool]

That is everything needed to get up and running. If any of the installations fail, check the spelling and spacing thoroughly.

Authenticating the Raspberry Pi

Use the google-auth-oauthlib[tool] with the credential JSON file downloaded earlier to authenticate your Raspberry Pi.

google-oauthlib-tool --scope \
      --scope \
      --save --headless --client-secrets /home/pi/YOUR_CLIENT_SECRET_ID.json

You’ll need to replace YOUR_CLIENT_SECRET_ID with the downloaded file, so it is worth copying the filename first. This client ID must be correct. Do not change the filename!

You should get a message with a link, asking you to paste in an authorization code.

Generating the Authorization link from the command line.

Clicking the link opens the browser. You’ll be prompted to enable the device on your Google account. Copy the authorization code which follows, and paste it back into your terminal window.

You should receive a confirmation reading Credentials Saved: /home/pi…, meaning the Pi has been authorized successfully with your Google account.

Testing It Out

Now that everything is in place, it’s time to test your Pi Google Assistant. Run the assistant with this command:

googlesamples-assistant-hotword --project-id my-dev-project --device-model-id my-model

You will need to replace my-dev-project with your Project ID (found under the Settings cogwheel of the Action Console). Your device-model-id is listed under the Device registration section of the Action Console.

Try it out! Say “OK Google” and ask a question. You can see the program output in the terminal as you hear the response:

Terminal output for Google Assistant

That’s it! Google Assistant is now running on your Raspberry Pi. Note that if the output volume is a little low, you can change it by saying “Hey Google, turn your volume up to 80%.”

Bonus: Voice Activated GPIO

It is possible to control lights with an Arduino and Siri, but there is a simpler method. If you set up an LED, you can use the Google Assistant to control it with your voice.

Setting up Google Assistant to work with the GPIO pins is relatively simple, but requires some extra steps. Head to the Google Action Console, and find your device under Device registration. Click on it, and open the traits menu:

Activating the OnOff Assistant trait

Turn the OnOff trait on, and click Save.

Now making sure you are inside the env virtual environment, clone a version of the SDK to your Pi using git:

git clone

Since this is a virtual environment, you’ll need to install RPi.GPIO before moving forward.

pip install rpi.gpio

Now, navigate to the folder containing the script.

cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library

Modifying the Script

You’ll need to add a few lines to the script, so open it in the nano editor:


Under the import statements, add your own for RPi.GPIO.

import RPi.GPIO as GPIO

Look for the process_event method. At line 66, remove or comment out the print statement, and add an if statement to control the LED.

#print('Do command', command, 'with params', str(params))
if command == "action.devices.commands.OnOff":
    if params['on']:
            print('Led turned on')

            GPIO.output(18, GPIO.HIGH)
                print('Led turned off')

                GPIO.output(18, GPIO.LOW)

This logic controls the LED, but so far it isn’t configured to output. Set it up in the main() function before the process_event method gets called.

GPIO.setup(18, GPIO.OUT, initial=GPIO.LOW)

Now the GPIO pin is set to output and initializes in a low state. Save and quit. You can run your modified script passing your model-id number (found in the Action Console) as an argument.

python --device-model-id YOUR-MODEL-ID-HERE

The terminal output is the same as before, and the assistant will work as standard. Now however, when you say “OK Google, turn on” you will see a new output:

Terminal Message showing "LED turning on" print statement

Note: The above image has been cropped, showing only the assistant hearing the request, and the print statement added to the script.

You should see your LED light up too!

Voice activated LED.

Your Own DIY Raspberry Pi Google Home Assistant

This project is a good introduction to using Google API services. Now that you have a Google Assistant device, try some of the best Google Home commands The Google Home Commands Cheat Sheet Our cheat sheet of Google Home commands contains tons of handy actions, including entertainment, information, and automation. Read More —we’ve looked at some great Google Home mini games 15 Google Home Commands for Mini Games and More You can do so many things with Google Home commands. Here are several entertaining Google Home commands worth trying. Read More .

Related topics: DIY Project Tutorials, Google Assistant, LED Lights, Raspberry Pi, Smart Hubs.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Cody
    February 25, 2020 at 10:57 pm

    I have the google assistant working on my raspberry pi and I've enabled the onoff trait, but every time I tell the assistant to turn on my light it tells me it isn't available. If someone could offer some assistance, it would be much appreciated.

  2. Monisha
    December 9, 2019 at 11:00 am

    Can I use my Bluetooth headphones instead of a speaker?

  3. Sharique
    September 22, 2019 at 10:15 am

    Couldn't find model-id please help.

  4. Ricardo Penders
    September 22, 2019 at 1:55 am

    Man I've tried everything I know to get the Google Assistant working on my Raspberry Pi 3B+ and although I don't see any errors popping up and everything seems to work there's too much information missing in this tutorial and another thing is that your example files and many other stuff looks totally different on my computer so for many things you point out that I should follow along I just can't because of the differences that are not even hinting to the right page, same with your instructions to what to look for in a file that's totally different too so I'm lost and don't know what to do anymore.

    Now I'm even more confused as before I started this tutorial, very sad face...

    Maybe Google updated the developers backend, the API page and the other interfaces that we have to use to get this working very recently causing the issue that I just can't find anything the easy way just by following your links... I don't know.

    I suggest you to update this tutorial as soon as possible since this is getting obsolete and will confuse people more than it is helpful in any way.

    Best regards

  5. Dmaxx
    September 11, 2019 at 12:57 am

    Everything is working fine except it cannot play any audiobook, and it also cannot play music. I have an error

    "I can't do that here, but you can ask me to play it one of your other devices"

    please help!

  6. Regis
    February 24, 2019 at 7:29 pm

    Will the raspberry appear as a regular Google Home device so that, for example, I could ask from another google home device to play music on the raspberry?

  7. Balazs
    February 14, 2019 at 4:37 am

    As of today (2/13/2019) the default file seems to have changed by default, would you mind posting your ENTIRE (and properly working) for those rookies like me who do not exactly know the wording and punctuation rules of python? Thank you and highly appreciated.

  8. Onur Atakan
    January 18, 2019 at 8:07 pm

    hello can I use an expression like when checking leds (turn on the light of my room)

  9. cyril
    January 14, 2019 at 8:40 am


    Is it possible to change th langague ?
    I want to speak French with my raspberry home assistant.


    • Ian Buckley
      January 14, 2019 at 11:04 am

      I've never tested it, but it's apparently possible to change the language for a Raspberry Pi Assistant in the Google Assistant Android app.

      As I say, I haven't done it, just remember reading about it. Note that it is the assistant app you want, and not the Google Home app. As far as I know this is android only too.

      Let me know if you get it working! When I have time I'd love to try it myself.

  10. Isaiah Stephens
    November 30, 2018 at 10:06 am

    Does this work for rpi zero w and the new 3a+ ?

    • Ian Buckley
      December 1, 2018 at 1:11 pm

      As far as I know it is the same process for the new 3A+ but not the Zero. There is an in depth walkthrough for getting it working on the pi zero on the Mikey's Lab YouTube channel which I haven't had time to check out yet.

      Might be a good place to start. Let me know if you get it going!