Alexa Speak entity attributes. A Speech Engine

I’ve added the new code. How to chain 2 speak lines (cNN) in the input_select.yaml file?

I have tried this

— (c04) (c05)

but it only speak line in (04) and not (05).

That is correct only 1 chain can be used per speak line . The idea was you were not restricted to 255 chars. You can multi chain so (c04) to (c05) to (c06) . You can also loop ! so be careful.

Ok. I think I got it. So (cNN) needs to go first then your second line.

Working:

– (c04) The (e02f) is turned (e02s)

Not Working:

– The (e02f) is turned (e02s) (c04)

Try using {% set state = states(ent)|round(1) %}. The state result does not have to be a number but could be a string, your code would restrict all states lengths… Round() does not apper to have any effect on a string value . It will also give a correct rounded result .

Could you tell me which part of the code to add the rount(1)? The code has changed quite a bit.

The (cNN) is a chain it just joins the speak lines together, and calls the media-player again, hence you can get your pause by delaying the second call

The (cNN) will work best at the end of line . All (cNN) does is calls the routine again by triggering the bulb . If you put (cNN) in the middle , you are in danger of cutting off the first message by the second.

st is the variable for state. The regex search checks for s and $ and then applies any device types (dt) via the list dy and uom (.state_with_unit)

{% elif tn|regex_search('\(e..[s$]\)') %}
  {% if tn[4:5] == "$" %}
    {% set st = states(et) %}
  {% else %}
    {% set st = states[et].state_with_unit %}
    {% set dt = state_attr(et,"device_class")|string %}
    {% if (dt != "None") and (st =='off' or st == 'on')  %} 
      {% set st = dy[dt][st|int] %}
    {% endif %}   
       <========== make changes here
    {% set rp = st %}           
{% endif %}

Make any changes to st after all the tests and before it it gets copied into rp (replace string ). say set st = st|round(1)

If added the round code here, but it is not working. No change.

            {% elif tn|regex_search('\(e..[s$]\)') %}
              {% if tn[4:5] == "$" %}
                {% set st = states(et) %}
              {% else %}
                {% set st = states[et].state_with_unit %}
                {% set dt = state_attr(et,"device_class")|string %}
                  {% if (dt != "None") and (st =='off' or st == 'on')  %} 
                    {% set st = dy[dt][st|int] %}
                  {% endif %}
              
              {% set st = st|round(1) %}
              {% set rp = st %}
              {% endif %}

yep not thinking sorry ! st is a string . round has no effect on strings ! You need to convert to a number , round it then convert it back to a string . Not sure what effect float has on real string not string numbers . This is probably why I left it alone :slight_smile:

Have a play in developers tools template. I will see if I can accept Jinja2 code in the speak string . The simplest change is always the most difficult

@duceduc

Updated code again . Will now accept JInja2 blocks , so rounding is possible . Fixed a bug with the chain feature and made time and date sound better (1st , 2nd , 3rd , etc)

Updated documentation on the first post with examples.

The updated code fixed my earlier issue where (cNN) only plays if placed in the beginning of the speak line. It is working now when place at the end.

  - The (e02f) is turned (e02s) (c04)

Will now accept JInja2 blocks , so rounding is possible.

It works if use only with $ with round. Does not if use s with round.
working:

– The current (e04f) is {{(e04$)|round(1)}} degrees and the humidity is {{(e07$)|round(1)}} percent

Not working:

– The current (e04f) is {{(e04s)|round(1)}} degrees and the humidity is {{(e07s)|round(1)}} percent

This is as coded . Will updates the docs. (eNNs) include the uom . The Jinja2 block does not get evaluated by my code but is passed to the the data string of the notify.alexa_media service. So this could result in your code with s postscript giving –

The current living room temperature is {{21.45 °C|round(1)}} degrees and the humidity is {{78.45 %|round(1)}} percent

Working on the rounding issues with @duceduc . I quite like Alexa speaking with 1 decimal place , it more concise and sounds better . So I have added the S option . This will round to 1 place and still add any uom .

The added S works beautifully. This sensor outputs 27.34, but speaks with 1 decimal now.

The current (e04f) is (e04S) and the humidity is (e07S)
“The current living room temperature is 27.3 celsius and the humidity is 53.2 %”

I quite like Alexa speaking with 1 decimal place , it more concise and sounds better.

It does sound better.

1 Like

After studying this, and no disrespect to your amazing work, I’ve settled on doing a cut down version where I put the finished message in input_select rather than use the auto correction, just so I can understand exactly what is going on. As no need for entities, the first couple of examples leaves me with just this…

speak_list:
  name: Speak List
  options:
    - do not use
    - This week is {{ state_attr('calendar.school', 'message') }} 
    - The next collection is the {{ state_attr('calendar.bins', 'message')|replace('collection','') }}

The dummy light and last alexa bits work fine and the dummy light to input select looks like it needs no changes.

Where I’m lost is what to use to call the results of dummy light to input select in the message section of item select to speak automation instead of the huge hunk of cleverness you wrote?

The idea is it not meant to be complicated :slight_smile: You are almost there !

To complete what you need is this

entity_list:
    name : Entity List
    options:
      -  calendar.school
      -  calendar.bins

So calendar.school is entity 0 (e00) and calendar.bins is entity 1 (e01)

speak_list:
  name: Speak List
  options:
    - do not use
    - test message
    - This week is  (e000)
    - The next collection is the {{ (e010)|replace('collection','') }}

So (e000} is entity 0 and attribute 0 ( I assume message: is the 1st attribute of calendar.school) and (e010) is calendar.bins attribute 0

(e00f) would return the friendly name and (e00s) would return the state

Check this works by triggering the input select via the developers tools states list. if all works OK Alexa should speak. If your messages do not work try the test message. After every change of the input select you need to reload the input select via the Configuration, Server controls menu.

Your current speak list should work without correction or adding any () entries . You will still need an entity list with at least one valid entity or my code will fail.

If you really don’t want to use an entity list or use the () syntax change

data_template:
      data:
        type: tts
        message: '{{states.input_select.speak_list.state}}'

Remove the following

variables:
  opt: >
    {% set sp = states.input_select.speak_list.state %}
    {% set no = sp.find("(c")+2 %}
    {{sp[no:no+2]|int}}
- delay:
      seconds: 2
  - service: light.turn_on
    data:
      entity_id: light.alexa_virtual
      brightness_pct: "{{opt}}"

Then you are back to my 1st automation. :slight_smile:

I understand that and it does work but what I’m trying to understand is, ignoring all the replaces etc, how the message gets from ‘dummy light to input select’ to ‘item select to speak’. I know it’s just this bit in the latter but don’t get what that actually does in layman’s terms…

        message: >
          {% set ns=namespace(speak = "") %}
          {% set ns.speak = states.input_select.speak_list.state %}
          {{ns.speak}}

Edit, started replying before you added your edits :slight_smile:

I had it working but wasn’t sure how I got there, more by luck than judgement I think. Makes sense now thanks other than what do those two chunks you said to remove do, it worked fine with them in?

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.