[RELEASE] Home Assistant Alexa TTS Proxy (another Alexa TTS option)

Code link here for easy visibility; description and setup below:

As I'm sure anyone who is searching is aware, there are at least a couple options for getting Alexa devices (Amazon Echo, etc.) to do text-to-speech (TTS) on Hubitat for things like announcements: Amazon Alexa Text to Speech and the famous Echo Speaks are two I've used, and you may wish to check those out before this one.


Here is a third option, which will primarily be of interest to those who already have Home Assistant (HASS) set up. It works through a service that the unofficial Alexa Media Player integration for Home Assistant exposes. On the Hubitat side, this just requires adding the driver and configuring the device to point to you HASS instance. The driver is single-purpose: proxying text from Hubitat to HASS for the purpose of TTS. It is one-way (Hubitat to HASS), TTS only (no media player functions), and very simple (under 100 lines of code).

On the Home Assistant side, you will need Alexa Media Player set up (HACS is the easiest way, but it can also be done manually). One advantage of this method is that you do not need to set up a separate server to do things like refresh the authentication/cookie; the HASS integration handles that for you. (The downside, of course, is that you need a Home Assistant setup do do this in the first place.)

Setup is basically:

  1. Ensure you have Home Assistant and the unofficial Alexa Media Player integration (formerly "component") configured
  2. Install the HASS Alexa TTS proxy driver code on Hubitat, Raw URL for copy/paste import (see above for pretty/formatted link): https://raw.githubusercontent.com/RMoRobert/Hubitat/master/drivers/HASS-AlexaTTS-Proxy.groovy
  3. Add a new (virtual) device using the newly installed driver, "HASS Alexa TTS Proxy."
  4. Configure the device:
    • Home Assistant URI: point to the URL for your HASS API, which by default runs on the same port as the front end. Include the protocol (and port if non-default), possibly something like http://192.168.0.11:8123
    • Home Assistant long-lived access token: generate from your HASS profile (username/icon in lower left)
    • Home Assistant domain/service: you will need to retrieve this from Developer Tools > Services in the HASS interface; search for notify.alexa_media_, and you should recognize device names and groups you have set up, like notify.alexa_media_johns_echo or notify.alexa_media_upstairs.

Then, use the device like you'd use any speech synthesis/TTS device in any Hubitat app (maybe test it from the device page first to see how it works :smiley: -- if it doesn't make sure you did step 4, especially the last part, correctly).

Not sure if there will be much interest in this approach, but figured I'd share anyway!

7 Likes

This makes more sense than other options.
I would have thought this would have been part of Hubitat created and support option.

Amazon does not have an official means off doing this. All the solutions I'm aware of work by more or less pretending to be the website or mobile app. They could break at any time (though so far they've all done a good job of keeping up with whatever changes Amazon makes). So...I can definitely understand why Hubitat would not want to deal with the hassle of "supporting" this as a built-in feature. :slight_smile:

1 Like

Apps that are official Alexa supported are done so with
Amazon Alexa Voice AI | Alexa Developer Official Site.

I can see this being part of the Hubitat Subscription due to the cost. As Alexa traffic increase the cost of the service will go up. So Hubitat would need charge X amount per user to cover the ongoing cost. I worked for a home automation company and this is exactly how they did this. I think they had a total worldwide customer base of about 225,000 users.

Brett

I'm aware of the ability to develop Alexa skills, and Hubitat has one (and that's all I see at that link). But last I checked, there wasn't a way to do "unsolicited" TTS with one--only with Alexa Routines or another "first-party"/Amazon option. It is possible to invoke the skill yourself and then ask it something or make it respond, but it wasn't possible to just make it do something whenever. This was a few years ago, and perhaps something has changed.

In any case, I'm not aware of anything "official" that does this on Hubitat or any similar platform--not saying they don't exist, just that I'm not aware of any or how they are done. But Hubitat does have a development environment, so you're welcome to create something if you know how. :smiley:

1 Like

If it has changed, that change has not been exploited on any platform I follow. So I don't believe it has changed.

By no means am I trying to argue. I just stating what is and has been for a good while now.

There are 1000's of service's that use Alexa for customers. Its big biz.

Sorry I was just giving an example of Dev Alexa link.

If anyone cares to look at the Business/Enterprise Alex.

Alexa and Google home integrations do not get a lot of love on hubitat. I believe this due to the automation vs control philosophy largely. There is a basic functioning Alexa skill. Requests to add some of these unofficial capabilities get shot down because they are just that, unofficial and undocumented. They could change or go away without warning.

So I guess I understand the reasoning.

The basic Alexa skill is good enough for most new users and there is not much incentive to appease us on this community, who may be vocal though we are still the minority.

1 Like

I can't get this to work. I can drive the notify in HASS and it works but when I test a message from the virtual device, I get a HTTP 408. Everything looks ok in the device.

Doing POST with params: [uri:http://192.168.0.91:8123, requestContentType:application/json, contentType:application/json, headers:[Authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI4Y2Q3YTAxYTg4NjU0MDNjYTM5NTdkYmU3MGRiNDQyNyIsImlhdCI6MTY2ODYwNTI5MiwiZXhwIjoxOTgzOTY1MjkyfQ.DN28FHNqaAYZmKdaKr5o9o8y4I4lZMH0TsVkimn_J0w], path:/api/services/notify/alexa_media_big, body:[data:[type:announce], message:hello], timeout:15]

When I get this working I change the token.
Any ideas?

That looks like what works for me, except I have a group (can't remember if this is one I created or an Amazon default) called "everywhere" and am doing an announcement to that, not a TTS message to an individual device. I'm not sure what your goal is. You may need to modify the data: map if you aren't able to call the same service in Home Assistant with the data I'm providing and have it work (this would have to be done in the code, as I didn't provide a way in the UI: this was my only use case for the driver).

But if it does, then I'm not sure why it wouldn't here.

Would you believe it.. I can send messages to every speaker using HASS but not to the everywhere group...i look at your code(which I[m sure is just fine but maybe I spot something).
Objective.. have the ability to send messages to any Alexa speaker, as one, or even as a group from HE.

I can't get this to work. I'm sure the code is good and I can send messages from HASS to my Alexa speakers so I'm thinking it must be something I need to configure on HASS to perhaps allow this api to work. I've spent a few days looking but I can't figure it out. I always get HTTP 408.

Do you have a subscription with Nabu? You have to have that for this to work.

Not sure what you mean with "this," but you do not need any subscriptions for the code in my original post to work.

1 Like

nop. Given up.. i'm trying to remove complexity and make things local. Subscriptions are web based so I'll have to figure something else out.

Very few things with Alexa are local. :slight_smile: However, as I mentioned above, there is no subscription required for the functionality that is the subject of this thread/topic. (I assume the confusion above is related to the Nabu Casa subscription required for Alexa voice control of HASS devices using their built-in integration, which is an unrelated function this driver does not handle.)

However, Hubitat does have some local or mostly local TTS options. For example, Google or Sonos TTS on Hubitat uses a local connection but does require an Internet connection generate the TTS audio for the first time (after which that exact text is cached). I've also seen some community options that are local via other means, though AFAIK all require additional hardware. For additional discussion on this or Nabu Casa, I'd recommend moving this to another thread given that it seems to be an unrelated issue.

For now, relying on an unofficial cloud API right now works well enough for me. :smiley:

2 Likes

Thank you for the write up! Works great!

1 Like