Alexa Speak entity attributes. A Speech Engine

Glad it working

The lines you removed make the chain command work (cNN). The variable holds the NN and the action fires the dummy bulb with the NN basically runs the automation again

@Bobby_Nobble. is this really too complex ?

I know the code is dense ,but it is just a copy and paste.

The idea was I got fed up with trying to mangle a template to get Alexa to say something.

States.sensor.patio_door.state:replace(‘on’,‘open’):replace(‘off’,‘closed’)

Or

(e01s)

I use the speak list as a single database for all my notifications then just set the dummy bulb. I can test simply by just firing the input select.

Is this just a program looking for a solution ?

Think you misunderstood where i was coming from, like most i ‘learnt’ home assistant copying and pasting snippets of others code, working out what it did and then tweaking for my own ends.

This works fine as it is and is simple to get going following your original instructions BUT rather than just sticking at that and taking it all on blind faith like an add-on or integration, as all your code was there in front of me i wanted to learn how it did what it did. So much of home assistant is hidden nowadays, it’s nice to do it the old fashioned way again.

OK . The simplest way to figure out what all that code does is to copy the Jinja2 code to the developers template . so everything in the message template. Turn off the automation or it will reset the input select and you won’t see whats the code does.

Then you can add {{ ‘variable name’}} at various points in the code in the developers template to see what it is doing .

This is the way I wrote and debugged the code.

Basically the code just splits the input select into words . Then searches the words for (…) . then splits out the key letters and finally substitutes the (…) with the replacements.

Thanks again for taking the time to look at this :slight_smile:

1 Like

Cheers, sussed most of it, just that bit to do :+1:

I hadn’t done anymore with TTS since the early days with the lötzimmer method, remember discussing things with both you and duceduc back then, but thought I’d try the Media Player route as I now have a particular need for some new announcements and stumbled on your developments in that thread. Surprised you haven’t had more interest as even without the replace parts you’ve got everything you need in one place. I used the last alexa routine and just exposed simple scripts to Alexa but saw your post about using a dummy bulb and brightness levels and liked the idea of not filling up Alexa with dozens of fake scenes…and here we are :slightly_smiling_face:

Haaska is still working a charm as the go between.

1 Like

As I have been playing with TTS and Alexa , I have discovered how clever she (it?) is at converting shorthand’s to real speech so

2020-10-04 , 04-10-2020 will speak 4th of October 2020 i’m sure the strange american month, day thing will also work :slight_smile:

22:20 will speak 22 hundred hours

WW2 will speak World War two

1th will speak first
2th will speak second etc.

10 * 2 will speak 10 times 2

All units of measure will speak properly as long as they are in context so

20 mph will speak 20 miles per hour

mph will speak m p h

Very useful for breaking down time stamps , so

{{’(e06$)’[11:16]}} will work giving the correct time from 2020-10-04T21:00:00 BST

{{’(e06$)’[0:9]}} will give date

1 Like

So, what I am hoping it does is to reply back from the device and I am talking to and not to the device stated in sensor.last_alexa .

Note to myself: I think I may have found out why Alexa isn’t responding from the device you are speaking too when it used to work before.

Reload Alexa Media Player from Integration. Alexa integration may not have started up properly after a restart of HA.

I’m trying this and works well. Only one thing: the automations name are changed, so I grab them from GitHub.
TY.

By(t)e

1 Like

thanks will update the post

First of all, thanks for your code @lonebaggie!
Sadly I can’t have it working, no matter what, changing the speak list item doesn’t output audio…
I found some discrepancies between the code on the first post and the GH repo, there are also some error reported by VSC (even if I can run the server anyway) that perhaps can influence the result.
I’m also not completely sure if I need to load some other stuff to have it working other than the yaml in the first post.

That’s my actual configuration:

group:
  echos:
    name: Echo_List
    entities:
      - media_player.echo_flex_sala2
      - media_player.echo_flex_suite
      - media_player.echo_dot_coz
      - media_player.echo_show_sala1
      - media_player.fire_tv_suite
      - media_player.fire_tv_qtlor
      - media_player.fire_tv_qtcam

sensor:
  - platform: template
    sensors:
      last_alexa:
        value_template: >
          {{ expand(states.group.echos) | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}

light:
  - platform: template
    lights:
      alexa_virtual:
        friendly_name: "Alexa Dummy Light"
        turn_on:
        turn_off:
        set_level:

input_select:
  entity_list:
    name: Entity List
    options:
      - sensor.suite2_am2301_temperature

  speak_list:
    name: Speak List
    options:
      - do not use
      - The current time is (tt)
      - The current date is (td)
      - The current temperature of (e00f) is (e00s)

Please note VSC is returning a non blocking error on light template turn_on, turn_off and set_level (Incorrect type. Expected “object”.)
Automations:

- alias: Item Select to speak
  description: Trigger Alexa from Item Select
  trigger:
    entity_id: input_select.speak_list
    platform: state
  variables:
    opt: >
      {% set sp = states.input_select.speak_list.state %}
      {% set no = sp.find("(c")+2 %}
      {{sp[no:no+2]|int}}
  condition:
    - condition: template
      value_template: '{{states.input_select.speak_list.state != "do not use"  }}'
  action:
    - service: >
          {% set name = states('sensor.last_alexa').split('.') %}
          notify.alexa_media_{{name[-1]}}
      data_template:
        data:
          type: tts

Please note the service_template will return a non blocking error on VSC (String does not match the pattern of “DEPRECATED^” because service_template: must be replaced with service: since 0.115) and is also not present on GH anymore, I copied the one in the first post hoping is fine but I also tested another one called Alexa Speak on your GH.

Then the second automation:

- alias: Dummy light to input select
  description: Trigger input select from dummy light
  trigger:
    entity_id: light.alexa_virtual
    platform: state
    from: 'off'
    to: 'on'
  action:
    - service: input_select.select_option
      data_template:  
        entity_id: input_select.speak_list
        option: >
          {% set slist = state_attr('input_select.speak_list','options') %}
          {% set opt = state_attr('light.alexa_virtual','brightness') %}
          {% set opt = (opt | float / 255  * 100+0.5)|int %}
          {% if opt|int > slist|length %}
            {% set opt = 0 %}
          {% endif %}
          {{slist[opt]}}
    - service: light.turn_off
      data:
        entity_id: light.alexa_virtual

With this configuration I don’t have any error on logs, it simply doesn’t work, and the automation are not triggered (even if I trigger them manually not output at all).
TTS works with a simpler script:

alexa_tts:
  sequence:
    - service: script.turn_on
      entity_id: script.alexa_set_volume
    - delay: "00:00:01"
    - service: notify.alexa_media
      data_template:
        target: "{{ states.sensor.last_alexa.state }}"
        message: "Teste de reprodução"
        data:
          type: "tts"

Do you see something missing/wrong?
Thanks for your time.

EDIT: Using the yaml from the second post I can have it working.
So what should I use since you stated to use just the code on the first post?

Opps sorry :slight_smile: managed to forget to copy some files back on my last update Latest files should be back on github . Thanks for spotting

You’re very welcome.

Thanks for sharing this project and all of the related info! I have it all set up with no issues, now Alexa tells me how cold my beer is and where all my family members are. Thanks for the hard work and support.

Only issue I had is in your automation service_template was depricated, had to cut it down to just service and it all worked for me.

1 Like

Hi everyone,
I managed to configure this feature thanks to your comments and feedbacks, but I have a problem at the end.
The automation ‘Input Select to speak’ won’t trigger. I can play with the brightness of the dummy light in Lovelace but that’s it…
when I’m triggering by Alexa, nothing happens.
Here some logs :

Logger: homeassistant.components.automation.input_select_to_speak
Source: components/automation/__init__.py:470
Integration: Automatisation (documentation, issues)
First occurred: 17:42:20 (26 occurrences)
Last logged: 18:17:32

Error rendering variables: ValueError: Template error: int got invalid input 'e ' when rendering template '{% set sp = states.input_select.speak_list.state %} {% set no = sp.find("(c")+2 %} {{sp[no:no+2]|int}}' but no default was specified
Error rendering variables: ValueError: Template error: int got invalid input 'he' when rendering template '{% set sp = states.input_select.speak_list.state %} {% set no = sp.find("(c")+2 %} {{sp[no:no+2]|int}}' but no default was specified
Error rendering variables: ValueError: Template error: int got invalid input 'o ' when rendering template '{% set sp = states.input_select.speak_list.state %} {% set no = sp.find("(c")+2 %} {{sp[no:no+2]|int}}' but no default was specified
Error rendering variables: ValueError: Template error: int got invalid input 'e ' when rendering template '{% set sp = states.input_select.speak_list.state %} {% set no = sp.find("(c")+2 %} {{sp[no:no+2]|int}}' but no default was specified
Error rendering variables: ValueError: Template error: int got invalid input 'e ' when rendering template ''{% set sp = states.input_select.speak_list.state %} {% set no = sp.find("(c")+2 %} {{sp[no:no+2]|int}}'' but no default was specified

What am I getting wrong ?

Thanks a lots in advance.

I’m replying to myself : by using the automation in the second post, it works ! :slight_smile:

I’m wondering, is it possible to parse ‘input_boolean’ or ‘input_datetime’ with this feature ?

Thanks for your kind words . I’m trying to rewrite this as a blueprint , but there still to many limitations on the blueprint inputs and my “slow is brain” :slight_smile: So i haven’t looked at this code for a while , but it still seems to work.

Can so no reason why input_boolean or input_datetime wont work the parse might be interesting with input_datetime , do you get any errors or is the output garbage

1 Like

Hi :slight_smile:
Thanks taking time to reply to me ! In fact, I’m a noob and I don’t know how to parse input_datetime. I’ll give it a try this afternoon.

Well, today, it doesn’t want to work at all. Alexa is spelling (e00$) and not the corresponding entity… :frowning:

It seems that Alexa is not parsing the entity with the ‘$’ in the (eXX$).

with the parsing problem with ‘$’, sadly, that is inconvenient for people who doesn’t speak English. Because Alexa will tell the uom in English… :frowning:
Is there a way to translate uom somehow ?

Thanks again !