Alexa tts volume

yes, the script above does that

No matter what the initial volume is, mine always returns to level 2 after the message.

alias: Test Announcement
description: ""
trigger:
  - platform: state
    entity_id:
      - automation.office_plug
action:
  - service: script.contact_sensor_announcement
    data:
      alexa_device: media_player.office
      alexa_volume: "{{ state_attr('media_player.office', 'volume_level') }}"
      alexa_message: "Things go here"
mode: single

Here is the script:

alias: Contact Sensor Announcement
sequence:
  - service: media_player.volume_set
    data:
      entity_id: "{{ alexa_device }}"
      volume_level: 0.5
  - service: notify.alexa_media
    data:
      target: "{{ alexa_device }}"
      message: "{{ alexa_message }}"
      data:
        Data: TTS
  - service: media_player.volume_set
    data:
      entity_id: "{{ alexa_device }}"
      volume_level: "{{ alexa_volume }}"
    enabled: true

I’ve got to be doing something wrong somewhere. I’ve also tried a few other variations that supposedly do the same thing. Those all also return it to level 2 no matter what.

Nope, I would assume this is just a limitation of the input that alexa media player accepts. the value may be dancing on the line between 2 and 3, when being read it’s 2, when you provide the value as an input it’s 3.

Ah, so it may be at something like .26 but round up or down when setting it back? That’s lame.

ty.

Yep, pretty much

So I did some more testing and I just don’t think it’s saving the current volume each time. If I set the device to volume 8 and then run the automation, it will change it to 5 like the script says, and then when it changes to the ā€˜old volume’, it’s 2. So definitely not a rounding error. I’ll just live with it always setting back to 2 and me having to change it manually when I want.

I’ve tested your automation and script with my entities and it is working as expected.

Is your Alexa Media Player integration up-to-date, the current version is 4.7.6. Any version prior to 4.7.4 is likely to have issues getting an accurate value for the volume during the service call for the script.

I think it was the version. I didn’t realize I was on a previous version. :man_facepalming: Updated and it seems to be working.

1 Like

I am using this version and it was working reliable since the alexa media player notification issues (which was solved) and reauth issues popped up:

See next post for script code

Currently alexa media player has issues with reauth, so i have disabled the last step (which waits for the volume to reset as it was before) and made an simple delay. So it does’nt wait forever.

So here is my adapted except with an timeout of 10 seconds. Use the new 4.7.7 Alexa media player released today.

alias: Alexa say something
description: Say something with an Alexa device (tts or announce)
variables:
  pause: "{{ 1.7 if type == 'tts' else 0.0 | float }}"
  gong: "{{ 1.7 if type == 'announce' else 0.0 | float }}"
  reset: "{{ state_attr(target, 'volume_level') | default(0.5, true) | float }}"
  dur: "{{ duration | default(7, true) | float }}"
fields:
  message:
    description: the message (SSML)
    example: <amazon:effect name="whispered">Please close the door.</amazon:effect>
    required: true
  type:
    description: tts or announce
    example: tts
    required: true
  target:
    description: the target devise as a string
    example: media_player.kuche
    required: true
  volume:
    description: the volume of the speach
    example: 0.7
    required: true
  duration:
    description: the length of the speach in seconds
    example: 3.3
    required: true
sequence:
  - service: notify.alexa_media
    data:
      target: "{{ target }}"
      message: >-
        <break time='{{ pause + 0.2 | float }}s'/> {{ message }} <break
        time='1s'/>
      data:
        type: "{{ type }}"
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: "{{ pause | float }}"
      milliseconds: 0
    enabled: true
  - service: media_player.volume_set
    data:
      volume_level: "{{ volume }}"
    target:
      entity_id: "{{ target }}"
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: "{{ (gong + dur) | float }}"
      milliseconds: 0
    enabled: true
  - service: media_player.volume_set
    data:
      volume_level: "{{ reset | float }}"
    target:
      entity_id: "{{ target }}"
    enabled: true
  - repeat:
      sequence:
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
      until:
        - condition: template
          value_template: >-
            {{ (reset | default(1, true) | float) == (state_attr(target,
            'volume_level') | default(2, true) | float)  or (repeat.index ==
            10)}}
    enabled: true
mode: queued
max: 5
icon: mdi:bullhorn

to use it:

service: script.alexa_say_something
data:
  type: announce
  message: "Hallo, das ist ein Test!"
  target: media_player.echo_show
  volume: 0.35
  duration: 4

Works great here

Have fun
pOpY

2 Likes

Thanks a lot, is the script also possible with the type: sequence I am struggling to get it working for example with alexa.weather.play
Do you have any example how i get it working?

The script is made for tts to reset volume afterwards to it’s previous value.

I personally don’t use sequences.

Here in the readme you can find Infos: Home Ā· alandtse/alexa_media_player Wiki Ā· GitHub