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

Tags: #<Tag:0x00007f47fc29f310>


That is exactly what I do minus the scan for last alexa. So I send TTS to a specific alexa at the moment.


appdaemon app :wink:
and because everything i got is in appdaemon, i can scan at any given point.
the only thing that throws things out of order is when i ask AD for music, the weather or a routine.
the last one i do rarely, but i could always include a input_boolean inside every routine
the fact that music is started i can see in the media players (so they change state, so that can also be a trigger for the scan)


Im slowly trying to to grips with appdaemon, how are you scrapping the output from on demand ?


i got a small app like this:

import appdaemon.plugins.hass.hassapi as hass
import datetime
import tempfile
import subprocess

class last_alexa_sensor(hass.Hass):

  def initialize(self):
    runtime = + datetime.timedelta(seconds=5)
  def check_last_alexa(self,kwargs):
    cmd = ["/home/renetode/alexamedia.shl","-lastalexa"]
      with tempfile.TemporaryFile() as f:
        self.subprocessresult = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=f)   
        out,err = self.subprocessresult.communicate()
        if out != None:
          state = out.decode("utf-8").strip()
          self.set_state("sensor.last_alexa", state = state)
          #self.log("last alexa: "+ state)
          self.set_state("sensor.last_alexa", state = "cookie problem")
          #self.log("last alexa: subprocess did return None") 
      self.log("last alexa couldnt be updated")

that scans for last alexa every minute.
the function check_last_alexa i can call everywhere inside appdaemon by using the get_app function from appdaemon.


Thank you I have lot learn


even the people who know the most have still a lot to learn :wink:
i think thats about the best part from living. (besides giving on what i have learned)


@ptdalen latest HA version now has a service to force sensor scan. Id wait till all the bugs are ironed out :slight_smile: its messed up my lovelace interface


Does logging in to amazon with the script still work for you guys? I have to manually copy over the cookie settings from the browser every 2-3 days what makes it a bit impractical…


it depends on how much use you make from it.
when i tried to read out the last alexa every minute it didnt last a day
but when i make normal use of it (only a few times a day) it lasts pretty long.


Hey, just wanted to report back. I have this working now using the upddate sensor.

  - service: homeassistant.update_entity
      entity_id: sensor.last_used_echo
  - service: script.audio_notify
      tts_msg: "stuff you want to say"
      mplayer: "{{ states('sensor.last_used_echo') }}"
  - platform: command_line
        command_on: "/home/homeassistant/.homeassistant/ -lastalexa"
        command_off: ""
  - platform: command_line
    name: Last Used Echo
    command: "/home/homeassistant/.homeassistant/ -lastalexa"
    entity_id: switch.last_echo_used

The hardest part is still getting that cookie. I rebooted and lost it and it took me a while to remember how to get it back, but… IT’s WORKING. :slight_smile:


yeah, i had it working without trouble for months.
now i also have trouble that the cookie expired every once in a while.
i think it must be possible to retrieve a cookie automaticly, but i need to find out how.


Good deal. I know you had it working using App Daemon, since I was not familiar with that I was focusing on the Yaml. The issue I had (mentioned above) was that the sensor for last used echo took a bit to update, but now with the ability to force the update of the sensor, it’s working great. My only issue left (a yaml issue), is that some of my echo names have spaces, so I need to change the names for my yaml.

For example living room echo, ends up being
media_player.Living Room Echo, which does not work
vs what it needs to be

I’ve done that before, just need to look up how I did it.

Anyway, I’m happy to be able to have this mostly working, and I’m sure I’ll be fully working soon


first thing i learned in automation. never use spaces.

in your case i would change the names from your echos to things like livingroom_echo
then you only got 1 time to change stuff :wink:


Yeah, that is a good and simple fix. Great idea. I named these echos quite a while ago, before I ever had hopes of really using them like this.


As said before, mine has been working flawlessly and I was one of the lucky ones where it just worked without any of the cookie malarky when first setting up.

However, it did stop working, I think, around the time you first said yours died and you thought Amazon had been messing at their end. Added it to my list of things to get around to when all of a sudden it announced my youngest was home last night and now everything appears to be back to normal with no changes made from when i first started using it.

Kind of suggests people have been trying to fix something that wasn’t actually broken at their end?


I’ve had to give up on this. Without a way to keep it reliably connected, it’s a non-starter. Downloading the cookie file is good as a one time setup, but not every week or two.


Is it possible to use TTS by Alexa locally without opening port?


there is no need to open any ports.



Do you know is there a need to opening port for Google TTS as well, having HA in docker?


google TTS is just something you get from a webserver, so also for google TTS you dont need to open ports