How to integrate Google Home to your custom devices by Google action and Python with Flask Framework
If you are looking for a way to control your custom devices with Google Home, you might be interested in Smart-Google, a project that allows you to create your own Google actions and connect them to your devices using Python and Flask. In this blog post, I will show you how to set up the environment, create a simple Google action, and use MQTT to communicate with your device.
To run this project, you will need the following:
- A Google account and a Google Home device
- A custom device that can connect to the internet and use MQTT protocol (I used a ESP 8266 board with micropython firmware)
- A Heroku or Google Cloud or AWS or any other cloud platform which supports Python apps
- A Firebase account and the Firebase CLI installed
- Python 3.8 or higher and pip installed
The first step is to clone the Smart-Google repository from GitHub:
git clone https://github.com/DaTiC0/smart-google.git
cd Smart-GoogleNext, you need to create a virtual environment and install the required packages:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtThen, you need to export some environment variables that will be used by the application. You can either set them manually or use a .env file. The variables are:
SECRET_KEYSQLALCHEMY_DATABASE_URIMQTT_BROKER_URLMQTT_USERNAMEMQTT_PASSWORDAPI_KEYAGENT_USER_IDDATABASEURL
The repository already ships with a service account template at service_account_file.json in the project root. config.py calls generate_file() (from generate_service_account_file.py) at startup, loading that template (or another file if you set the optional SERVICE_ACCOUNT_FILE to override the path) and overriding the following fields with values from your environment:
PROJECT_IDPRIVATE_KEY_IDPRIVATE_KEYCLIENT_EMAILCLIENT_X509_CERT_URL
To expose your Flask server to the internet during local testing, use either ngrok:
./ngrok http 5000or Cloudflare Tunnel:
cloudflared tunnel --url http://localhost:5000The app exposes a /health endpoint:
curl -i http://127.0.0.1:5000/health
# or
make healthExample response:
{"mqtt_connected":true,"service":"smart-google","status":"ok"}Returns 200 when MQTT is connected (status: ok) and 503 when it is not (status: degraded).
Recommended workflow is branch + pull request + merge to main.
Quick steps:
git checkout main
git pull --rebase origin main
git checkout -b feat/my-change
make install-hooksBefore opening a PR:
make test
make health
make check-pathsSee CONTRIBUTING.md for full details and AI-assisted code review policy.