Use Google Assistant to control Raspberry Pi without writing code
This project is about using your Google Assistant to control your Raspberry Pi GPIO pins. You can implement this project without writing a single line of code and use it as out of the box solution for controlling your Raspberry Pi through a physical Google Home Assistant device or Google Assistant of your mobile phone.
What you need for this project
1. Google Home device OR Phone Google Assistant.
You need a Google Assistant to give voice commands for this project. You can either have a physical device such as Google Home mini or you can use the built in Google Assistant feature of your Andriod phone.
2. An account with this website (helloworld.co.in)
You need to create account with this website for following reasons:-
- To access a browser based widget (online remote). Using this remote, you can tell the website which Raspberry Pi pins you want to control. A GPIO state table is maintained in the cloud with respect to the Raspberry Pi pins you configured using this remote. This state table governs the behaviour of your Raspberry Pi.
- You get an authentication token via email. This token is required to be pasted in the code running in Raspberry Pi.
3. IFTTT Applet.
You need to create an applet on IFTTT to forward your Google Assistant data to your helloworld.co.in account. IFTTT applet is the bridge between your Google Assistant and your helloworld.co.in account.
4. Raspberry Pi.
Raspberry Pi can control external devices through its GPIO pins. The code running inside Raspberry Pi fetches the GPIO state data from your account in helloworld.co.in and set the GPIO pins accordingly. You can interface a relay board with GPIO pins to control your home appliances.
All the above components are elaborated further in this article.
The Google Assistant
How Google Assistant Works normally
You speak to your assistant. The data goes to the Google cloud and processed. A suitable response is generated by Google and sent back to your device. Which is spoken back to you.
How Google Assistant is used in this project
You speak to your assistant begining with a specific phrase or keyword. The data goes to the Google cloud. Presence of keyword is detected and IFTTT trigger is generated. IFTTT forwards the text you spoke after the keyword (called text ingredient) to helloworld website via a webhook. The text ingredient is processed by helloworld website and the GPIO state table with respect to your Raspberry Pi is updated as per the command received.
The helloworld account
This website provides IOT widgets which work with your Raspberry Pi to give you an out of the box serivce. One of the widget is Online Remote. This remote can be used to control the GPIO pins of your Raspberry Pi from anywhere through internet. The remote allows you to choose and configure the GPIO pins you want to control. Once configured, the pin numbers and their current state is stored in the cloud in a GPIO state table. The states of the pins in the cloud can be toggled through the remote.
Now, this project is about changing the state table of your Raspberry Pi (maintained in helloworld website) through voice commands using Google Assistant. After initial configuration of the GPIO state table, you can speak the number of the desired pin to your Google Assistant to make it High or Low.
You would have noticed that Google Assistant and Online Remote are two different web services running in different clouds. So how is it possible to use Google Assistant to change GPIO state table in your helloworld website account?
This is where IFTTT comes into the picture. This popular tool is created for the sole purpose of bridging two different web services via a Trigger & Action mechanism. The great news is, it is free of cost !!!
IFTTT Applet
IFTTT bridges two different web services by means of Applets. You can create upto 5 applets, each capable of bridging two different web services. For this project, you need to create only one applet as per the configuration described below. An applet has two parts.
Part 1: IF
This part is responsible for trigger generation. Here you have to select Google Assistant as service and choose 'Say a phrase with a text ingredient' option. Fill the 'trigger' section as shown in the example below. Here, the trigger keyword is 'turn' which is followed by a '$' that means text ingredient (anything spoken after the keyword).
Part 2: Then
This part handles the action to be performed when the trigger is generated. Here you have to select Webhook as service and choose 'Make a web request' option. Fill the 'action' section as shown in the example below. Here you need to enter the URL pertaining to your helloworld account. This URL is unique to you and can be copied from here.
In the above example ‘turn’ is the keyword for the Google assistant. When this keyword is detected by Google Assistant, a Webhook is triggered and a web request is made to helloworld website with two parameters i.e. your auth_token (your identity on helloworld) and the text ingredient (text you spoke after the keyword). This text ingredient should be a valid command. A valid command to control your Raspberry Pi through Google Assistant is your keyword followed by GPIO pin number and its desired state. For example, if you wish to make GPIO 14 Low, then you can speak "turn 14 OFF". If you wish to make it High again, the speak "turn 14 ON" to your Google Assistant.
You can turn ON or OFF all the pins at once by saying following statements to Google Assistant:-
- turn ON
- turn OFF
Check Your Connection
How do you know whether your IFTTT configuration is correct and your voice messages are being received in your helloworld account? To check this part, go to this link. If your configuration is correct, you should be able to see the text ingredient in the green box as shown below.
Raspberry Pi Configuration
To fetch data from GPIO state table in your helloworld account, your Raspberry Pi need to run a code which can be downloaded from this Github link. The code fetches the GPIO state table from your account in helloworld website at a regular interval of time. Based on the state table data, the GPIO pins are set High or Low. You can see the detailed instructions for setting up this code in this article.
Build your own smart switches with this project
You can build your own smart switches with is technique and go beyond than what is offered by commercial smart switches. The whole process of setting up your online remote, IFTTT applet and Raspberry Pi code can be completed in a matter of minutes.
Let me know if you build this project and share your experience.
Comments
Hello
Getting Below Error
Unrecognized ingredient {{GoogleAssistant.voiceTriggerWithOneTextIngredient.turn}}
while putting url in THEN THAT any solution
It helped when you talked about Google Assistant or Participant. Recently, I have been in search of a better blog that explains more about Google Assistant and I'm interested in knowing more about more qualities of your Posts. Thanks for the enlightenment. I will like you to check out my site I give updates on how to use Google Assistant and the benefits.
https://www.tecteem.com/google-assistant