[Release] Amazon Alexa Text to Speech (TTS) v0.5.8 - Direct Integration (USA, Canada, UK, Italy, Australia, & Brazil)

Direct Text to Speech integration from your Hubitat Hub to Amazon's cloud servers.

v0.1.0 - Initial Release
v0.2.0 - Fixed a bug causing the app to hang when the cookie is invalid. Added support for more 'Alexa Devices' like tablets, thermostats, etc... Thanks @stephack!
v0.3.0 - Added multi-country support and ability to rename app
v0.4.0 - Added Virtual Container support - Thanks @stephack
v0.4.1 - Added Error Notification support (e.g. Pushover) for cookie issues (e.g. expiration)
v0.4.2 - Improved notification for expired cookie
v0.4.3 - Prevent sending empty messages to Amazon
v0.4.4 - Added Notification for Message Rate Exceeded
v0.4.5 - Added support for direct copy and paste of the cookie header into the App - Thanks @stephack
v0.4.6 - Added support for Italy - Thanks @gabriele
v0.5.0 - Added support for automatic cookie refresh with external NodeJS webserver - Thanks @gabriele
v0.5.1 - Change contentType for http call in order to eliminate a nagging exception
v0.5.2 - Attempt to add volume control, but not working so commented out
v0.5.3 - Added app events to have some historic logging
v0.5.4 - Attempt to add support for Australia (Successfully tested)
v0.5.5 - Reduced live log messages
v0.5.6 - Added support for a new "All Echos" child device, which allows for broadcasts to all Echos.
v0.5.7 - Added an override switch that disables all voice messages when off (thanks @rjb.bob!)
v0.5.8 - Added support for Brazil (thank you Marco Felicio / @maffpt)

**v0.5.6 Adds optional support for an "All Echos" child device which you can choose to select along with your other Echo devices. This device, allows Alexa Broadcast TTS to all of the Echo devices on your Amazon Account (whether or not you have selected them as part of this integration.) All of your devices will perform the TTS at approximately the same time, however they are not precisely synchronized. Using this broadcast feature does have the advantage of only issuing one call to Amazon, thus preventing the tripping of Amazon's rate limiting/throttling of calls to their servers.

v0.5.1 addresses an exception that was raised and caught each time a TTS message was sent to Amazon. The exception was thrown by the underlying platform while trying to process the response as json. Working with support, I have changed the expected contentType to text/plain and the exceptions appear to be resolved. Hubitat Support noticed this error while troubleshooting various users' hubs over the past few months. Please upgrade your Alexa TTS App to v0.5.1 as soon as possible to eliminate this issue.

v0.5.0 Thanks to the amazing efforts of @gabriele, you can now automatically keep your Alexa Cookie refreshed using an external NodeJS web server (e.g. a Raspberry Pi.) Please read the revised ReadMe for instructions on setting this up!

WARNING: v0.4.x will delete and create new child devices if you choose to enable the virtual container support feature. To use the Virtual Container feature, you will need @stephack's Virtual Container Driver from his repo at Hubitat/Virtual Container.groovy at master · stephack/Hubitat · GitHub

Most users have found that the cookie expires after 14 days. You will need to get a new cookie each time it expires. With v0.5.0, you can now use a local NodeJS server to help automate this process. You can also continue to use the F12 method found in the ReadMe to manually update the cookie. I have added a new Notification Device selection option to the App. Choosing a device, like Pushover, will tell you when the Alexa TTS Manager App is having an problem taking to the Alexa servers.


  • No Raspberry Pi required (except for AlexaCookie.js for automatic Cookie Renewal! v0.5.0)
  • No link back to your old SmartThings hub

Just a simple Parent App / Child Driver pair to install (and some web browser cookie stealing/editing/hacking :wink: ) Read on if you're interested!

As someone who does not own any devices that natively support Text to Speech (TTS), I have been waiting for Amazon to implement an open TTS API so I can use my Alexa Devices. It seems like Amazon is not quite ready to release this functionality, so I decided I would develop a workaround. Initially, I was inspired by the work of @cwwilson08 to use a Telnet session to a Raspberry Pi to run a shell script. I am happy to see that @cwwilson08 was able to get this working after the Hubitat team resolved an issue in the Telnet Client.

The directions for getting this integration up and running can be found in my ReadMe below:


Here are a few pictures to help make some of the steps a little easier to visualize.

"Alexa TTS Manager" Apps Code Installation

"Child Alexa TTS" Drivers Code installation

Configuring the "Alexa TTS Manager" App
Enter your cookie string and click Next.
Note: Creating this cookie string is the hardest part of the process and is detailed in the ReadMe. As of v0.5.0, you can now optionally use @gabriele's awesome AlexaCookie NodeJS server app on an external server (e.g. Raspberry Pi) to automate the cookie renewal process.

Click the drop down list and select the devices you want to use.
If this list is empty, check the logs (most likely your cookie string is not correct, or your cookie is no longer valid.)

Optionally, you can turn on the Virtual Container feature to keep your Alexa devices grouped together in your Devices list. Click Done, which will create a "Child Alexa TTS" device for each of your Alexa devices you just selected. Note: Unchecking a device, after the child is created, will not remove the child. You will need to manually remove the child if desired. This is to prevent accidentally deleting a child that is used by a bunch of automations.

Now go take a look at your "Devices" list and you will see the new "AlexaTTS name" child devices. Do not change the Device Network ID's of these. You can safely change the Label to whatever you'd like though.

You can then click on one of these child devices to bring up a very simple TTS device. Type in any text you'd like below the Speak button, and then click Speak. The appropriate Alexa device will then wake up and speak your phrase.

You can then incorporate these child devices into any automations that are able to utilize the "Speech Synthesis" Capability, like Rule Machine.

I would like to thank @cwwilson08 and @chuck.schwer for their inspiration and technical assistance. Also, I appreciate the very quick beta testing done by @stephack which helped to improve the documentation.

As always, feedback is appreciated. If anyone wants to add more functionality or improve the ReadMe, I'd be happy to entertain pull requests.

26 Likes
How do you use TTS?
Sound Tone or TTS using Google Home or Alexa
Best TTS Speaker/most compatible?
VLC Thing with multiple instances
Alexa TTS via Google Assistant to SmartThings
Alexa TTS Workaround
Echo speaks help plz
Alexa / Google home or Chrome cast text to speech
Best TTS device to use with HE
[DEPRECIATED] Welcome Home
Audio Notification Options
Hue Scene Automation
Alexa alerts when contact sensors are opened/closed
Ipad speaking
[Updated] Presence Central
Amazon Adding Contact and Motion Capability’s to Echo
[Updated] Presence Central
How to trigger Alexa Routine from Hubitat
Driver Preferences - store long strings
Arlo Motion Automation with IFTTT
Sound Tone or TTS using Google Home or Alexa
[RELEASE] Echo Speaks v3 + Actions
[RELEASE] Other Hub SmartThings Integration 2.0
Alexa - -Unsolicited TTS
Making Alexa work for me
Notifications App - Where does the number go?
Notifications App - Where does the number go?
[Release] Unofficial Ring Integration
Alexa not present as a Hubitat TTS Device
What are some cool raspberry pi “server” type projects?
Send SMS or Email via App
Hub process slowdown after several days
Community Apps
Need guide for Alexacookie.js Implementation
Need guide for Alexacookie.js Implementation
Echo Dot Used Just For Speech
QNAP NAS Integrations for UPS Monitoring, NodeRed, Home Bridge, etc
Help - Rule Machine Washer & Dryer notifications
Another hub lockup
Rule for Garage Door Left Open
How to have Hubitat, Konnected interface an Alexa play nice
[Release] - Speaker Central

This is great work @ogiewon.

Although now I think I am having a @Cobra moment....

6 Likes

Thanks.

I know there are a lot more features that you've exposed in your integration. Do you have a top 1 or 2 that should be focused on? I am guessing everyone will want volume control, if that is possible?

Volume control is possible. The thing is I have noticed once the devices go idle for awhile they stop responding to some of these calls. The only way I have found to get them to respond again is to send a play command. Volume is one such command. My workaround was I found a "silent tone" track so when the device reports idle I tell it to play this track. A bit hacky but seems to work.

I would guess the ability to play specific tracks / playlist would likely be at the top of people list. Many options are there for this. It is too bad amazon quit letting us upload our own music, as that would be my top pick.

Aside from that I particularly like being able to query the device for what is currently playing and the album art that goes with it.

Interesting. In my testing over the past few days, I have not noticed this yet. How long does the Alexa device need to be idle before it exhibits this behavior? I will definitely keep an eye out for it.

Actually managed to miss the other important feature people will want. And that would be the ability to trigger routines. It is only a slight tweak on the speak command - this is one of the commands I was having trouble with no response as well. At one point I thought the whole thing was broken as I could not get any of my many many echo products to respond.

It seems to happen after several hours. The query device response seems to change twice. I have not looked at it in awhile, as trying to parse the telnet responses was giving me headaches and I was working on features I did not think I was ever going to use. I will pay closer attention the next time I am playing with them and try to get a more solid number.

Happily the TTS call always seems to work.

1 Like

If during your efforts you figure out how to hook into the Plex integration I would be most interested.

1 Like

Compiling the cookie is a total PITA and I had to use Chrome because the FireFox cookie crashed the application, but once I got past that everything worked great. Thanks for creating this.

I just logged out of the Amazon website and it stopped working so am I correct to assume that every time you log out you're going to have to re-create that cookie?

How exactly did you do this in Chrome? I've never installed extentions in a browser before and the readme for coockies-txt seems to be missing information on how to install it.

Menu
More Tools
Extensions
Left Menu > Open Chrome Web Store
Searched for cookies.txt

1 Like

Thanks!

The method used grabs all the cookies into one. ONE of them is "session-id" -- logging out invalidates that cookie at amazon.com and thus, yes, you need to rebuild it.

There's also: "session-id-time" and it probably invalidates too. Maybe most go invalid, but the point is, if one is invalid, you have to rebuild.

1 Like

FYI, Once that cookie is invalidated you can no longer get into the app to change the cookie so you have to force remove the app and start over.

I know I'm speaking to a tiny subset here, but on the Mac, the FF cookie is stored as "cookie.sqlite" and I just happened to have sqlite3 installed on my Mac.

SELECT name, value FROM moz_cookies WHERE host = ".amazon.com";

this sql command extracts them all (I think) and then there's just the text editor work remaining to replace spaces with = and replace \n with ;

No, I haven't started that experiment.. yet.

As a last resort, clear all cookies. If possible, only the amazon ones. YMMV

I just figured out an easier way to get the cookie.

Log in, open Chrome developer tools, got to the Network tab, filter by XHR, and copy the entire cookie from any of the entries.

Paste the cookie into the app and add a semi-colon to the end of it

2 Likes

Worked for me also!

Hmmm... I wonder why this would be? I have never invalidated my cookie (having used a different browser than normal to create it, and never logged out of the site), but I have entered in invalid cookie strings numerous times and the app seemed to handle it fine (there is a try/catch around the http calls.)

Yeah I get an App is not responding error when I click the "Next" button. I also can't add another device after a single device is selected.

I believe you. I just have not seen that behavior. Is this after you've invalidated your cookie somehow?

That's so strange. Is this with a still valid cookie? I have gone back into the app numerous times during testing, on two hubs, and have always been able to select and deselect the various alexa devices without any issues. (of course, deselecting a device really doesn't do anything as you have to manually delete the child device.)

I would truly like to understand more about the issues you're seeing. My only hypothesis is that it has something to do with how you generated your cookie. I used FireFox on Windows with the Cookies.txt extension to save my cookie file. Then I used Notepad++ to generate the string, making sure to remove all double quotes, adding semicolons between each line, and replacing the spaces with = signs. I also made sure that there were no CR's or LF's within or at the end of the line of text (I only selected/copied the one huge line of text.)