- 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
git clone https://github.com/HidekiA/google-home-talker-mqtt
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
Edit configurations.py (See Configurations section)
cd google-home-talker-mqtt
python3 main.py
(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
- Replace ExecStart path in google-home-talker-mqtt@.service
ExecStart=/usr/bin/python3 /home/USERNAME/google-home-talker-mqtt/main.py
- Copy Unit file
sudo cp google-home-talker-mqtt@.service /etc/systemd/system/
- 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
systemctl status google-home-talker-mqtt@USRENAME.service
journalctl -e -u google-home-talker-mqtt@USRENAME.service
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] |
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. |
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. |
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.) |
<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
-
Make a service account and download a service account key file, following the official manual.
-
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)
- 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 |
- Sign-up Beebotte
- Make a new Channel and a new Resource
- Copy the channel token string to the
MQTT_TOKEN
- Sign-up IFTTT
- Create an Applet
- 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
- For example, select Google Calendar, and select Any event starts.
- Press Then That and select Webhooks with the following settings
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>"} |