Skip to content

Python code enables Google Home to talk with IFTTT and MQTT triggers

License

Notifications You must be signed in to change notification settings

HidekiA/google-home-talker-mqtt

Repository files navigation

Google Home Talker MQTT

日本語ページはこちら

What's this

  • This code enables Google Home (and other chromecast devices) to talk with IFTTT or other triggers
    • Motivation: I wanted my smart speaker to notify my schedule exactly one minute before
  • Full SSL/TLS Internet connections

Overview


Index


Install

Download

git clone https://github.com/HidekiA/google-home-talker-mqtt

Install packages

pip install --upgrade pychromecast
pip install --upgrade google-cloud-texttospeech
pip install --upgrade google-cloud-storage
pip install --upgrade paho-mqtt
pip install --upgrade parse

Configuration

Edit configurations.py (See Configurations section)

Run

cd google-home-talker-mqtt
python3 main.py

Test

(After Beebotte configurations)
(Replace CHANNEL_NAME, RESOURCE_NAME, and TOKEN_STRING)

curl -X POST -H "Content-Type: application/json" -d '{"data":"Hello world!"}' https://api.beebotte.com/v1/data/publish/CHANNEL_NAME/RESOURCE_NAME?token=TOKEN_STRING

Example of cron to have a wake-up call at 7 a.m. on weekdays.

0 7 * * 1-5 /usr/bin/curl -X POST -H "Content-Type: application/json" -d '{"data":"Good morning!"}' https://api.beebotte.com/v1/data/publish/CHANNEL_NAME/RESOURCE_NAME?token=TOKEN_STRING

Run Automatically (by systemd)

To set up a system service

  1. Replace ExecStart path in google-home-talker-mqtt@.service
ExecStart=/usr/bin/python3 /home/USERNAME/google-home-talker-mqtt/main.py
  1. Copy Unit file
sudo cp google-home-talker-mqtt@.service /etc/systemd/system/
  1. Enable and Start the service.
    (Replace USRENAME with the actual user name)
systemctl enable google-home-talker-mqtt@USRENAME.service
systemctl start google-home-talker-mqtt@USRENAME.service

To check the service status

systemctl status google-home-talker-mqtt@USRENAME.service

To see the logs

journalctl -e -u google-home-talker-mqtt@USRENAME.service

Configurations

General

CHROMECAST_DEVICE_IP IP address of the chromecast device (Google Home / Google Nest / Smart TV, etc.)
This is shown in the Device Info page of "Home" App.
POLLING_INTERVAL Polling interval to check for scheduled talk [second]

Text-to-Speech

TTS_ACCOUNT_JSON File name of service account key of Google Cloud Text-to-Speech (How to get the key file)
TTS_DEFAULT_LANGUAGE Text to talk to
TTS_CHECK_JAPANESE Use ja-JP if the text includes Japanese (and Chinese) character, TTS_CHECK_JAPANESE otherwise.
Set False when you use Chinese text.
TTS_GENDER Voice gender (Details in the official document)
- texttospeech.SsmlVoiceGender.SSML_VOICE_GENDER_UNSPECIFIED
- texttospeech.SsmlVoiceGender.MALE
- texttospeech.SsmlVoiceGender.FEMALE
SSML_VOICE_GENDER_UNSPECIFIED is not a neutral voice, but seems to be either a male or female voice depending on the specified language. NEUTRAL has not yet supported.)
TTS_SPEED Talk speed (0.25 - 4)
TTS_PITCH Voice pitch (-20 - 20)
TTS_GAIN_DB Volume (-96 - 16)
TTS_PROFILE Optimization profile for the speaker device
See the official document for available profiles.

Google Cloud Storage

GCS_ACCOUNT_JSON File name of service account key of Google Cloud Storage
This can be same as the one for Text-to-Speech.
BUCKET_NAME Bucket name to store the temporary audio file
TTS_TEMPORARY_AUDIO_FILENAME Name of the audio temporary file
This will be overwritten but not automatically removed.

Beebotte

MQTT_CACERT Server Certificates of the Beebotte server
Download https://beebotte.com/certs/mqtt.beebotte.com.pem
MQTT_TOPIC MQTT topic ("CHANNEL_NAME/RESOURCE_NAME")
MQTT_TOKEN Beebotte channel token (See bellow.)

Message Format

<talk> Text to talk to
If there is no <talk> field, the entire message is taken as the text to talk to.
<time> (optional) Make schedule to talk.
Accept any of dateutil.parser formats.
Talk immediately if a past time is specified.
<before> (optional) Shift the time specified in <time> field.

Examples:

<talk>Hello world!</talk>
>> Say "Hello world!" immediately

Hello world!
>> Say "Hello world!" immediately

<talk>Happy New Year!</talk><time>Jan 1, 2030 at 9:00AM</time>
>> Say "Happy New Year!" at 9am on January 1, 2030

<talk>The meeting will begin soon.</talk><time>15:30</time><before>60</before>
>> Say "The meeting will begin soon." at 15:29 today

Related Cloud Services

Google Cloud Platform

Google Text-to-Speech

  1. Make a service account and download a service account key file, following the official manual.

  2. Enable Text-to-Speech API
    https://console.cloud.google.com/marketplace/product/google/texttospeech.googleapis.com
    Free up to 1 Million characters per month (as of May 2021)

Google Cloud Storage

  1. Make a bucket in Google Cloud Storage
    Free up to 5GB and 5,000 times operations per month with the following settings (as of May 2021)
Location type Region
Location us-west1 (or us-central1 or us-east1)
Storage class Standard

Beebotte

  1. Sign-up Beebotte
  2. Make a new Channel and a new Resource
  3. Copy the channel token string to the MQTT_TOKEN

IFTTT

  1. Sign-up IFTTT
  2. Create an Applet
  3. Press If This and set a trigger
    • For example, select Google Calendar, and select Any event starts.
      And set a calendar in Which calendar field and 15 minutes in Time before event starts filed
      • Note that IFTTT triggers tend to be a minute or two late
  4. Press Then That and select Webhooks with the following settings
    • Replace CHANNEL_NAME, RESOURCE_NAME, and TOKEN_STRING
    • Body is an example to talk Schedule title one minute before the schedule starts
URL https://api.beebotte.com/v1/data/publish/CHANNEL_NAME/RESOURCE_NAME?token=TOKEN_STRING
Method POST
Content Type application/json
Body {"data":"<talk>{{Title}}</talk><time>{{Starts}}</time><before>60</before>"}

About

Python code enables Google Home to talk with IFTTT and MQTT triggers

Topics

Resources

License

Stars

Watchers

Forks

Languages