Glow LEDs with Google Home

Recently I tried experimenting with Google Home, trying to voice control LEDs. Majorly the whole thing can be split into two parts,

  1. A custom command that makes a web POST request to fetch the result.
  2. A simple Flask app that can receive post request with parameters and glow some LEDs based on the POST request data.

For the part one, the custom commands were possible thanks to Google Actions Apis.  I used API.AI for my purpose since they had good documentation. I wont go into detail explaining the form fields in, they have done a good job with documentation and explaining part, I will just share my configurations screenshot for your quick reference and understanding. In the conversations are broken into intents.  I used one intent (Default Welcome Intent) and a followup intent (Default Welcome Intent – custom) for my application.


Heres my first intent which basically greets the user and asks for a LED colour when the custom command “glow LEDs” is activated.


As you can see the User says is what defines my command , you can add multiple statements in which you want to activate the command. The Action and Contexts is set when you create a followup Intent. Text response is the part which your Google Home will use as response.

Next is the Followup Intent which basically takes the User response as input context (which is handled automatically when you create the followup intent) and looks for required parameters and tries to process the request.


Here the expected User says would be a colour (red, blue, green) is what I allowed. In you can use their ML to process the speech and find your needed parameters and values. I needed colours hence used @sys.color. Their are other entities like @sys.address or @sys.flight etc. If these entities don’t serve your purpose then you might want to go vanilla and process the speech on your web-api end. The later part of the Followup Intent is a bit different, we are fulfilling the user request via web-hook here. Here the Response is the fallback response incase the web request fails, the success response is received from web-hook response body.


The fulfilment option won’t be activated until you add your webhook in the Fulfillment section. Thats all for the part one. Also you can use Google Web Simulator to test your application On the Go.


In part two , I used a Raspberry Pi, 3 LEDs (red, blue, green) , a 1K ohm resistor some wires, a breadboard(optional)  and a T-cobbler Board(optional). Now, we will write a flask application that will accept a post request and turn on the required GPIO pin output high/low.

from flask import Flask, request, jsonify
import RPi.GPIO as GPIO
app = Flask(__name__)
BLUE = 12
RED = 13
GREEN = 18
base_response = {
'speech':"Abra Ka Dabra,{color} LED glowing",
'displayText' : "Abra Kaa Daabra, {color} LED glowing",
'source' : 'Manual'}
def index():
if request.method == 'GET':
text = """WELCOME to RBG<br>
/red -> red LED<br>
/blue -> blue LED<br>
/green -> green LED<br>
/clear -> clear all<br>
return text
req_body = request.get_json()
color = req_body['result']['resolvedQuery']
if color == 'red':
if color == 'green':
if color == 'blue':
response = base_response.copy()
response['speech'] = response['speech'].format(color=color)
response['displayText'] = response['displayText'].format(color=color)
return jsonify(response)
def red():
return "RED"
def green():
return "GREEN"
def blue():
return "BLUE"
def clear():
return "Cleared"
if __name__ == '__main__':

view raw

hosted with ❤ by GitHub

You can check with the request and response structure you need from the docs. Next, this application receives the calls from webhook and it triggers the targeted LED depending on the resolvedQuery. The above code was written so that I can test locally with get requests too. I used to tunnel and expose my flask application to the external world. Following is the circuit diagram for the connections.


Following is the Result,

Continue reading “Glow LEDs with Google Home”

Glow LEDs with Google Home