No, you have to put them physically into idle or playing by making them play something then stopping them. You can’t do this from HA side.
I will try that but that really won’t work will it? What I mean is if you are trying to automate retrieving the current volume level before changing it to say something, then you won’t be able to retrieve it right?
Just check to see if it’s playing. Do you need the volume level if it’s not playing?
Of course. I’ll give you a usercase example:
- I want to be alerted to water my plant on Wednesday at 6:00PM
- I have an activity to trigger and tell Alexa to notify me.
- Before and after this trigger, Alexa is not active. In other words I do not play music all day and it will just interrupt for the announcement.
- Expect it would find out the current volume.
- Change the volume to 1 or 10 depending on how you look at it and send the announcement.
- Set the volume back to what it found in 4
Well just look at the device in the alexa app. I’m looking at one right now in standby and even it doesn’t list a volume. However the one that is playing does. This is probably a limitation of the device itself.
and just as my suspicions are confirmed. When the device goes into playing/idle the volume is reported in both HA and the alexa app (not HA). This most definitely is a limitation alexa has placed on the devices.
OK thanks so this won’t work. I know when I used OpenHAB I was able to do this so could this be a limitation of Alexa Media Player? I was even able to break down my Alexa devices to primary volume levels current and change to values, as well as a separate notification volume that apparently the devices support. I won’t point to it but looking at their control right now and they can manage:
General Volume
TexttoSpeech Volume TTS
notification Volume
Alarm Volume
And was able to retrieve the current level for each of these when it’s not doing anything. Not to compare but just want to share it looks like it’s there, just maybe it’s not accessible thru this plugin.
They must store the states when they detect changes. As I said in my other post the offical Amazon alexa app does not report a volume when the device is in standby. I confirmed this on my device here. You can see it by going into the device in devices and in the audio section you will notice that there isn’t a slider. This means it’s not reporting it. As soon as you play, a slider appears. Again this is in the official app, nothing to do with home assistant.
This must be all custom work. All possible, just not implemented here.
Just looked through their code. Yes, they track separate volumes when you execute commands. So, alexa only has 1 volume, they separate it for their users.
EDIT: technically there is 2 volumes. 1 for normal use and one for timers, alarms, and notifications.
anyways, you can always ask for this and maybe the dev will add it.
Thanks. There is no way to make some kind of binary_sensor that holds this information. Obviously until it plays at all it will be 0 though think if I read how they do it if it’s currently set to zero it defaults to 5 or something.
You can make an automation and store the volume in a input_number. Each time the volume changes, store the value of its a number. Then use that input number as the restore volume level
Any way to do this via one script/automation combo for multiple alexa devices?
Something along the lines of using a group and a for loop to pull out entities and run each through to independently store the volume level, send the message, and set each back…
You’d still need multiple automations, but you can have more than 1 trigger per automation. And you’d have to make the conditions and actions generic so that any device passed through it works.
Here is my approach of setting an “speak” volume, read announce message & set back to original volume.
to call the script:
service: script.alexa_announce
data_template:
alexa_device: media_player.wohnzimmer
alexa_service: notify.alexa_media_wohnzimmer
alexa_volume_speak: 0.2
alexa_message: "This is a test"
script:
alexa_announce:
alias: Alexa Ankündigung
sequence:
- variables:
old_volume: '{{ state_attr(alexa_device , ''volume_level'')|float }}'
- service: media_player.volume_set
data_template:
entity_id: '{{ alexa_device }}'
volume_level: '{{ alexa_volume_speak }}'
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: '{{ alexa_service }}'
data:
message: '{{ alexa_message }}'
data:
type: announce
method: all
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: media_player.volume_set
data_template:
entity_id: '{{ alexa_device }}'
volume_level: '{{ old_volume }}'
mode: parallel
Hope this helps someone.
PS.: if anyone can help to add “multidevice” feature, just let me know. I am struggling with setting old_volume_1, _2 . Not so deep in HA, just a few days.
pOpY
Thank you so much @pOpY for the starting point on saving the old volume. I have rewritten it to allow restoring the volume of multiple devices.
I apologize for all of the debugging aliases ahead of time. They were helpful in getting it all working.
Here’s the code:
################################################################
# Script / Alexa TTS
# Say something using text-to-speech on an Alexa media player(s).
#
# @file script/alexa_tts.yaml
# @see https://community.home-assistant.io/t/alexa-tts-volume/89894/34
#
# @example
# service: script.alexa_tts
# data:
# entity_id:
# - media_player.bathroom_echo
# - media_player.kitchen_echo_show
# message: And Bob is your uncle
# volume_level: 0.4
################################################################
alexa_tts:
alias: Alexa TTS
description: Say something using text-to-speech on an Alexa media player.
mode: parallel
fields:
entity_id:
name: Entity
description: Name(s) of Alexa media player entities.
required: true
example: media_player.kitchen_echo_show
selector:
entity:
integration: alexa_media
domain: media_player
message:
name: Message
description: Text to speak on devices.
required: true
example: My name is Bob and I am your uncle
selector:
text:
volume_level:
name: Volume Level
description: Volume level to set as float.
required: false
example: 0.5
selector:
number:
min: 0
max: 1
step: 0.01
sequence:
# Save the current volume for later.
- alias: SAVE_VOLUME
variables:
# Ensure that the entity_id variable is a list.
entity_id: "{{ [entity_id] if entity_id is string else entity_id }}"
# Iterate the entity_id list and try to get current volume from each.
saved_volumes: >-
{%- set saved_volumes_json -%}[
{%- set comma = joiner(', ') -%}
{%- for eid in entity_id -%}
{{- comma() -}}
{"entity_id": "{{ eid }}", "volume": {{ state_attr(eid, 'volume_level') | float(0) }}}
{%- endfor -%}
]{%- endset -%}
{{- saved_volumes_json | from_json -}}
# Set the temporary volume if specified.
- alias: MAYBE_SET_VOLUME
choose:
- alias: IF_VOLUME_DEFINED
conditions: "{{ volume_level is defined }}"
sequence:
- alias: SET_VOLUME
service: media_player.volume_set
target:
entity_id: "{{ entity_id }}"
data:
volume_level: "{{ volume_level }}"
# Wait to let the set_volume action start.
- alias: SET_VOLUME_SHORT_DELAY
delay:
seconds: 1
# Speak on the Alexa device.
- alias: SPEAK_TEXT
service: notify.alexa_media
data:
data:
type: tts
message: "{{ message }}"
target: "{{ entity_id }}"
# Wait to let the TTS action start.
- alias: SHORT_DELAY
delay:
seconds: 1
# Revert the volume back if necessary.
- alias: MAYBE_REVERT_VOLUME
choose:
- alias: IF_VOLUME_DEFINED
conditions: "{{ volume_level is defined }}"
sequence:
- alias: REVERT_VOLUMES_LOOP
repeat:
count: "{{ saved_volumes | length }}"
sequence:
- alias: MAYBE_REVERT_VOLUME_X
choose:
- alias: IF_SAVED_VOLUME_X
conditions: "{{ saved_volumes[repeat.index - 1].volume > 0 }}"
sequence:
- alias: REVERT_VOLUME_LOOP_X
service: media_player.volume_set
target:
entity_id: "{{ saved_volumes[repeat.index - 1].entity_id }}"
data:
volume_level: "{{ saved_volumes[repeat.index - 1].volume }}"
Your’e welcome.
Nice script!!
In my case i just run my script from another multiple times with the entity’s.
Would be so nice if this get’s integrated into alexa media player, to just call one notify with mutliple entities.
Nice work.
pOpY
Hi pOpY. Could you please elaborate on how you use with multiple entities please? I have got your code working nicely with one entity.
I would like three alexas to play a doorbell chime at a loud volume, then say ‘There’s someone at the door’. Then return alexas to original volume.
I also added a tweak to stop the alexas from beeping when volume changes…
Thank you in advance
alias: Alexa Announce (Hall)
sequence:
- variables:
old_volume: "{{ state_attr(alexa_device , 'volume_level')|float }}"
- service: media_player.volume_mute
data:
is_volume_muted: true
target:
entity_id: media_player.echo_dot_hall
- service: media_player.volume_set
data_template:
entity_id: "{{ alexa_device }}"
volume_level: "{{ alexa_volume_speak }}"
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: "{{ alexa_service }}"
data:
message: "{{ alexa_message }}"
data:
type: tts
method: all
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: media_player.volume_mute
data:
is_volume_muted: true
target:
entity_id: media_player.echo_dot_hall
- service: media_player.volume_set
data_template:
entity_id: "{{ alexa_device }}"
volume_level: "{{ old_volume }}"
mode: parallel
max: 10
PS - I am supposed to remove alexa_announce: from your code when pasting into a script?
I also had to remove alexa_tts: from Dale’s code. @dale3h I couldnt get you script to resume the original volume for multiple devices. I listed them like this… Apologies for noobness…
service: script.new_script
data:
entity_id:
- media_player.echo_dot_hall
- media_player.echo_dot_kitchen
message: bob
volume_level: 0.01
Yeah, sorry for my missleading post.
I have another script “Announce All” which checks various things (is light on in this room…) and run the single script multiple times. Here it is:
alias: Notify Devices (Alexas, TV, Mobiles, ...)
sequence:
- service: notify.all_devices
data:
message: "{{ speaktext }} {{ now().strftime('%H:%M:%S') }}"
data:
ttl: 0
priority: high
- choose:
- conditions:
- condition: state
entity_id: media_player.fernseher
state: "on"
sequence:
- service: notify.android_tv_wohnzimmer
data:
title: "{{ tvtext }}"
message: ""
data:
duration: 10
position: bottom-right
fontsize: large
transparency: 0%
color: grey
interrupt: 0
icon:
url: "{{ tvicon }}"
default: []
- choose:
- conditions:
- condition: state
entity_id: media_player.fernseher_2
state: "on"
sequence:
- service: notify.android_tv_schlafzimmer
data:
title: "{{ tvtext }}"
message: ""
data:
duration: 10
position: bottom-right
fontsize: large
transparency: 0%
color: grey
interrupt: 0
icon:
url: "{{ tvicon }}"
default: []
- service: script.turn_on
target:
entity_id: script.alexa_announce
data:
variables:
alexa_device: media_player.wohnzimmer
alexa_service: notify.alexa_media_wohnzimmer
alexa_volume_speak: "{{ speakvolume }}"
alexa_message: "{{ speaktext }}"
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: script.turn_on
target:
entity_id: script.alexa_announce
data:
variables:
alexa_device: media_player.kuche
alexa_service: notify.alexa_media_kuche
alexa_volume_speak: "{{ speakvolume }}"
alexa_message: "{{ speaktext }}"
- choose:
- conditions:
- condition: device
type: is_on
device_id: c8748498bc7901901dc9f210e142b163
entity_id: light.bad_decke
domain: light
sequence:
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: script.turn_on
target:
entity_id: script.alexa_announce
data:
variables:
alexa_device: media_player.badezimmer
alexa_service: notify.alexa_media_badezimmer
alexa_volume_speak: "{{ speakvolume }}"
alexa_message: "{{ speaktext }}"
default: []
- choose:
- conditions:
- condition: state
entity_id: input_boolean.presence_arbeitszimmer
state: "on"
sequence:
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: script.turn_on
target:
entity_id: script.alexa_announce
data:
variables:
alexa_device: media_player.buro
alexa_service: notify.alexa_media_buro
alexa_volume_speak: "{{ speakvolume }}"
alexa_message: "{{ speaktext }}"
default: []
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.bed_occupied
state: "off"
sequence:
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: script.turn_on
target:
entity_id: script.alexa_announce
data:
variables:
alexa_device: media_player.stefi_s_echo_show
alexa_service: notify.alexa_media_stefi_s_echo_show
alexa_volume_speak: "{{ speakvolume }}"
alexa_message: "{{ speaktext }}"
- service: script.turn_on
target:
entity_id: script.alexa_announce
data:
variables:
alexa_device: media_player.tobias_echo_show
alexa_service: notify.alexa_media_tobias_echo_show
alexa_volume_speak: "{{ speakvolume }}"
alexa_message: "{{ speaktext }}"
default: []
mode: parallel
max: 20
This is called from an automation like this:
service: script.turn_on
target:
entity_id: script.notify_devices
data:
variables:
speakvolume: 0.35
speaktext: Trockner ist fertig, bitte ausräumen!
tvtext: Trockner ist fertig, bitte ausräumen!
tvicon: http://192.168.0.8:8123/local/trockner.png
Hope this helps.
pOpY
All good, many thanks, will give this a go and report back 
I know this is an old thread, but I’ve been trying to get my devices to save and return to the original volume without success. I’ve found a few threads (including this one) with scripts/automations that partially work. They set the volume, speak the message, but then always return to volume 2 regardless of what they were set on when the automation was run. My expectation was that if the volume is on 3, it would return to that after the message.