Alexa TTS volume_set no effect while media_player in standby state

Is there a way to set media_player volume while in standby state and there is even no volume_level attribute for media_player entity?

I have writen following script to make Alexa speak in certain volume:

alexa_speak:
  sequence:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.alexa_volume_holder
        value: "{{ states.media_player.alexa.attributes.volume_level | default(0.4) }}"
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.alexa
        volume_level: "{{ volume | float }}"
    - service: media_player.alexa_tts
      data_template:
        entity_id: media_player.alexa
        message: "{{ message }}"
    - delay:
        seconds: 10
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.alexa
        volume_level: "{{ states.input_number.alexa_volume_holder.state | float }}"

which can be used in automation action a la:

  action:
    - service: script.alexa_speak
      data_template:
        message: "Important notification!"
        volume: 0.7

It works flawlessly but only when media_player.alexa is in playing or paused state.
Problem is in standby state (active most of the time) - setting volume has no effect and text is spoken at the volume set previously which is usually too quiet.

2 Likes

Refering to this post

There needs to be an active queue (playing or not) for the volume controls to work. This is a limitation of the unofficial API that the Alexa website users.

apparently I will have to try to play some very short mp3 file to bring media player out of standby mode and only then adjust the volume.

UPDATE: No luck of bringing media player out of standby mode by playing some local audio file. Alexa just says Sorry, text to speech can only be called with media player alexa_tts service.

Still hoping anyone has some kind of solution.

I have (almost) fix the problem inverting the set volume with annunce, in the sequence i put first the annunce them the set voume, in some case the “bling blong” alexa annunce sound is cliped but the result in non bad.

# Messaggi Alexa
alexa_parla:
  sequence:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.alexa_volume_holder
        value: "{{ states.media_player.alexa_cucina.attributes.volume_level | default(0.4) }}"
    - service: notify.alexa_media_alexa_cucina
      data_template:
        target: media_player.alexa
        data:
          type: announce
          method: speak
        message: "{{ message }}"
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.alexa_cucina
        volume_level: "{{ states('input_number.volume_messaggi') | float}}"
    - delay:
        seconds: 3
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.alexa_cucina
        volume_level: "{{ states.input_number.alexa_volume_holder.state | float }}"

now I have a new problem to fix.
annunce is asynchronous, sequence do not wait until the text to speech is done
probably the only solution is find and set one appropriate waiting time (in the example 3 seconds), not very easy with data_template text without prdefinited time.

if enybody have a suggestion…

MArco