Skip to content

DaTiC0/smart-google

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

192 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart-Google: Control your custom devices with Google Home using Python and Flask

GitHub license

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.

Environment

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

Installation

The first step is to clone the Smart-Google repository from GitHub:

git clone https://github.com/DaTiC0/smart-google.git
cd Smart-Google

Next, you need to create a virtual environment and install the required packages:

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Then, 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_KEY
  • SQLALCHEMY_DATABASE_URI
  • MQTT_BROKER_URL
  • MQTT_USERNAME
  • MQTT_PASSWORD
  • API_KEY
  • AGENT_USER_ID
  • DATABASEURL

Google Service Account

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_ID
  • PRIVATE_KEY_ID
  • PRIVATE_KEY
  • CLIENT_EMAIL
  • CLIENT_X509_CERT_URL

Testing Locally

To expose your Flask server to the internet during local testing, use either ngrok:

./ngrok http 5000

or Cloudflare Tunnel:

cloudflared tunnel --url http://localhost:5000

Health Check

The app exposes a /health endpoint:

curl -i http://127.0.0.1:5000/health
# or
make health

Example 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).

Collaboration Workflow

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-hooks

Before opening a PR:

make test
make health
make check-paths

See CONTRIBUTING.md for full details and AI-assisted code review policy.

About

Google Home integration to your custom devices by Google action and Python

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors