Alexa Announce Feature - Text to Speach via Alexa now a possability?

I’m in the Dev tools, services section trying to “call service” but I get an “Invalid JSON” message so unable to “call service”.

copied from my screen shot:

Service:
media_player.alexa_tts

Service Data (JSON, optional):

{“entity_id”: “media_player.living_room”, “message”: “speak alexa, speak already”}

there’s something wrong with my service data input…?

hehe! failure certainly is not an option!
Thank you for the tips, it does appear I had inadvertantly already done all the heavy lifting when I installed the media players so I’ll try getting that to tts but again… not soooo simple either it turns out! :rofl:

I got it to work! like you said it’s the little things… turns out I needed " " with entity id’s
only took me all day to figure that out :smiley:

2 Likes

but you learned :wink:
next time quotes are needed you will figure that out way faster :wink:

1 Like

I’ve been picking away at this on and off for months, and I have TTS working fine from the command line but I can’t get it to work when called from the HA Services page.

This works:
image

As does this (simulating what is happening in HA):
image

This is my notify config:

notify:
  - name: Alexa Office
    platform: command_line
    command: "/config/ha-alexa-tts/alexa_wrapper.sh -d 'Office Echo'"

I’m on Hass.io.

When I call it from the Services panel like this, it doesn’t work:
image

The little popup appears in the corner that the service has been called, but the Echo doesn’t say anything, and there’s nothing about it in the home-assistant.log file. It’s like it doesn’t happen.

My file permissions are fully executable:
image

And the Alexa cookie in /tmp is 777 (the only way I got this to work).

What am I missing? Why can’t I use this through HA?

your files are owned by root and you probably dont start HA as root.

OK I’ll try changing it tonight. Does that really matter since they’re executable by all? I SSH in as user “hassio” now, and that user can run the scripts from the console and it works. I’m pretty sure that’s the user HA uses.

i have no idea because its hassio.
i find it strange that user hassio has root privileges
and i have no clue if that user also starts HA.
but the command_line stuff from HA is probably using the python sub_process lib, and that gets in trouble when a file is root and you dont use sudo in the command.

I really like this solution, but my issue has been cookies. I have 2FA and the only way I can get this to work is to download the .cookie file via Firefox and put that in the tmp directory. That lasts maybeeee a week or 2 and then without notice it’ll fail. Anybody have a solution/know if one is being worked on?

i really had no trouble untill now.
but for TTS i recently added the alexa mediaplayer component.
that works like i want to, and still does.

now i wanted to use the script again to create a sensor last_alexa.
but i can login anymore with the script.
i know amazon added captcha but how do i get my cookie now?

i already logged in to alexa with firefox on the device where the script is, but that doesnt help.

and i have no clue how to get the alexa.cookie where people are speaking about.

I’ve read through here and like many others am having trouble figuring out the cookie part. My situation
Running HA in a python venv.
I do not have a browser loaded on my ubuntu machine.
I’ve tried using chrome and firefox extensions, pulled the cookie as a text file, then put in in /tmp as txt and renamed to .alexa.cookie. I get the following error

username@hass:/home/homeassistant/.homeassistant$ ./alexa_remote_control.sh -a
cookie expired, logging in again ...
rm: cannot remove '/tmp/.alexa.cookie': Operation not permitted
ERROR: Amazon Login was unsuccessful. Possibly you get a captcha login screen.
 Try logging in to https://alexa.amazon.com with your browser. In your browser
 make sure to have all Amazon related cookies deleted and Javascript disabled!

I am using 2FA, does I could not find any refrence about that in this thread. Any help is appreciated

I was able to get the - rm: cannot remove ‘/tmp/.alexa.cookie’: Operation not permitted
error solved by using sudo with my command, but of course that just deleted the cookie, and it still fails to logon.

After @ ReneTode explained the alexa_remote_control.sh script can trigger routines within Alexa I have re-established the script within my Hassio

I too switched over to the media_player as it was simpler and has been very reliable. I am currently, running both the script and media player concurrently without issue.

As you can get the script to work without issue in Hassio, try the following in HA, this works for me without a problem.

shell_command:
  alexa_talk: '/config/alexa_remote_control.sh -d "{{ device }}" -e speak:"{{ talk }}" '

Make sure the ’ and " are correct, type don’t cut and past, I wasted hours with yaml errors with corrupted text

To test go to the Developer tools, Services

Service: shell_command.alexa_talk
Service data: {“device”:“name of alexa device”,“talk”:“testing testing 1 2 3”}

replace “name of alexa device” with the correct name :wink:

Hope this works. If so you can chop up the script to do most things

alexa_vol: '/config/alexa_remote_control.sh -d "{{ device }}" -e vol:{{ volume }} '
alexa_routine: '/config/alexa_remote_control.sh -d "{{ device }}" -e automation:"{{ routine }}" '

How did you manage to get a cookies working for any amount of time with 2FA. I’m stuck

Are you saying you dont need the cookie in your configuration?

no i am saying that i dont know how to get the cookies.txt file.

in the meantime i found an addon for firefox to export the cookie to a json file, but now i still get only cookie expired :frowning:

how did you get the login to work?

Aww that makes sense. Sorry I misunderstood, I thought you had this running for a while, and when you say you dont know about getting the cookies, I thought maybe you had a trick. :slight_smile:

in firefox I get a json, in chrome I get a txt. Neither works for me

yeah i was one of the first to get it running.
back then it just triggered a browserscreen and i logged in and have been using that ever since.
so i didnt even realise there were cookies involved :wink:

and i never had anything to do with cookies before so i really had no idea how to get them.

Do you have a browser on the same system as your HA install?

yeah i got firefox on ubuntu

Install this addon/extension for Firefox: https://addons.mozilla.org/en-US/firefox/addon/cookies-txt/

Clear any Alexa.amazon.com/amazon.com cookies. Log in. Click the extension icon and download the cookies.txt file. Move it to your tmp directory, rename to alexa.cookie and you should be good.

So i don’t do it directly on the HASS device but my main desktop.