alexa_media_player
alexa_media_player copied to clipboard
Set volume for notifications
Is your feature request related to a problem? Please describe. Enable volume_level in short play_media notifications, like:
- service: media_player.play_media
target:
entity_id: media_player.echo_bedroom
data:
media_content_id: amzn_sfx_doorbell_chime_01
media_content_type: sound
volume_level: 1
metadata: {}
Currently, it doesn't work, volume_level is not supported.
Describe the solution you'd like One way to implement it would be to record the current volume, play the notification, then set back the volume. Consider I have 3 devices, doing it manually is complicated...
Describe alternatives you've considered I set the volume to maximum on the 3 devices, play my doorbell chime, then set it back to 0.5. But depending on the room it's too much or not enough...
@tbarbette Not sure if this is helpful or not, but I created an AppDaemon script awhile back to do exactly this (as well as some other things). You may have to fiddle with the delay a bit for your environment to give the echo time to respond to the set_volume request. You can call it via an event as follows...
event: speech_manager.announce_phrase_to_target
event_data:
target: media_player.kitchen_echo
phrases:
- There is someone at the door.
- >-
Nobody told me we were expecting guests, but someone is at the door.
- Someone is at the door, should I send them away?
Thanks but it's not what I'm looking for :)
If I understood your issue right then I faced this problem too. I wrote a script (maybe not the best way) for that:
script:
kla_alexa_play:
alias: Alexa Play
icon: mdi:play
mode: queued
max: 10
description:
Falls Alexa sprechen darf (bestimmte Zeiten etc.), liest die dafür
definierte Gruppe die als Parameter übergebene Nachricht vor
fields:
message:
description: Nachricht, welche Alexa vorlesen soll
example: Was darf ich für dich tun?
alexa:
description:
Alexa, welche sprechen soll (optional,
es spricht der zuletzt aktive Echo)
example: echo_show8
type:
description: Alexa Ausgabetyp [TTS/command/sequence] (optional)
example: tts
volume_level:
description:
Lautstärke in der die Nachricht vorgelesen werden soll [0-30]
(optional, ursprüngliche Lautstärke wird wieder zurückgesetzt)
example: "1"
force:
description: Überspringe die Prüfungen, ob Alexa reden darf (optional)
example: "true"
sequence:
- condition: or
conditions:
- condition: template
value_template: >
{{ force is defined and force }}
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.kla_alexa_is_allowed_to_speak
state: "on"
- condition: state
entity_id: binary_sensor.kla_anyone_home
state: "on"
- choose:
- conditions:
- condition: template
value_template: >
{{ alexa is defined and alexa != ''
and states('media_player.' + alexa) not in ['None', 'unknown', 'unavailable']
and volume_level is defined
and (0 <= (volume_level | int(0)) <= 30) }}
sequence:
- service: input_number.set_value
data_template:
value: >
{% set alexa_media = 'media_player.' + alexa %}
{% if (state_attr(alexa_media, 'volume_level') | float(0.33)) > 0 %}
{{ state_attr(alexa_media, 'volume_level') | float(0.33) }}
{% else %}
{{ ((volume_level | int(0)) / 30 | float(0.33)) | round(2) }}
{% endif %}
entity_id: input_number.kla_alexa_volume_tmp
- condition: template
value_template: >
{{ (state_attr('media_player.' + alexa, 'volume_level') | float(0.33)) !=
((volume_level | int(0)) / 30 | float(0.33)) | round(2) }}
- service: media_player.volume_set
data_template:
entity_id: media_player.{{ alexa }}
volume_level: >
{{ ((volume_level | int(0)) / 30 | float(0.03)) | round(2) }}
default: []
- choose:
- conditions:
- condition: template
value_template: >
{{ type is not defined or (type is defined and type == "tts") }}
sequence:
- service: >
{% if alexa is defined and alexa != '' -%}
notify.alexa_media_{{ alexa }}
{%- elif states(states('sensor.kla_alexa_last_active')) not in ['None', 'unknown', 'unavailable'] -%}
notify.alexa_media_{{ states('sensor.kla_alexa_last_active').split('.')[1]}}
{% endif %}
data_template:
data:
type: tts
message: "{{ message }}"
- conditions:
- condition: template
value_template: >
{{ type is defined and type == "command" }}
sequence:
- service: media_player.play_media
data_template:
entity_id: >
{% if alexa is defined and alexa != '' -%}
media_player.{{ alexa }}
{%- elif states(states('sensor.kla_alexa_last_active'))
not in ['None', 'unknown', 'unavailable'] -%}
{{ states('sensor.kla_alexa_last_active') }}{% endif %}
media_content_id: "{{ message }}"
media_content_type: custom
- conditions:
- condition: template
value_template: >
{{ type is defined and type == "sequence" }}
sequence:
- service: media_player.play_media
data_template:
entity_id: >
{% if alexa is defined and alexa != '' -%}
media_player.{{ alexa }}
{%- elif states(states('sensor.kla_alexa_last_active'))
not in ['None', 'unknown', 'unavailable'] -%}
{{ states('sensor.kla_alexa_last_active') }}{% endif %}
media_content_id: "{{ message }}"
media_content_type: sequence
default: []
- choose:
- conditions:
- condition: template
value_template: >
{{ alexa is defined and alexa != ''
and states('media_player.' + alexa) not in ['None', 'unknown', 'unavailable']
and volume_level is defined
and (0 <= (volume_level | int(0)) <= 30)
and state_attr('media_player.' + alexa, 'volume_level') !=
states('input_number.kla_alexa_volume_tmp') }}
sequence:
- service: media_player.volume_set
data_template:
entity_id: >
{{ 'media_player.' + alexa }}
volume_level: >
{{ states('input_number.kla_alexa_volume_tmp') | float(0.33) }}
default: []
The temporary input to remember the volume is a nice hack, but with multiple devices I have to make 3 of them, it would deserve a built-in feature :)
I absolutely agree. I set the mode to queued to avoid this problem as a tradeoff only to play one device simultaneously.
The issue has received no activity for 60 days and will be closed in a week.
Nooo :) We want that feature ! :p
The issue has received no activity for 60 days and will be closed in a week.
Nope, still want the feature ! :)
The issue has received no activity for 60 days and will be closed in a week.
Still not solved and no easy way to solve :)
This would be super useful!
Since volume_level
is not supported, why not save the current volume levels automatically using snarky-snark/home-assistant-variables integration which I configure to update whenever Alexa Media Player: Update Last Called Sensor [service: alexa_media.update_last_called
] is run which updates sensor.last_alexa
.
Then simply set the new volume level in your script/automation, play the media and then set the volume back to the saved volume level from the var:
var:
last_alexa:
friendly_name: Last Alexa
unique_id: last_alexa
value_template: "{{ states('sensor.last_alexa') }}"
tracked_entity_id: sensor.last_alexa
attributes:
media_player.garage_echo_dot: "{{ state_attr('media_player.garage_echo_dot','volume_level') }}"
media_player.office_echo_dot_left: "{{ state_attr('media_player.office_echo_dot_left','volume_level') }}"
media_player.office_echo_dot_right: "{{ state_attr('media_player.office_echo_dot_right','volume_level') }}"
media_player.kitchen_echo_dot: "{{ state_attr('media_player.kitchen_echo_dot','volume_level') }}"
media_player.living_room_echo_dot_left: "{{ state_attr('media_player.living_room_echo_dot_left','volume_level') }}"
media_player.living_room_echo_dot_right: "{{ state_attr('media_player.living_room_echo_dot_right','volume_level') }}"
media_player.bedroom_echo_dot_left: "{{ state_attr('media_player.bedroom_echo_dot_left','volume_level') }}"
media_player.bedroom_echo_dot_right: "{{ state_attr('media_player.bedroom_echo_dot_right','volume_level') }}"
media_player.daniel_s_echo: "{{ state_attr('media_player.daniel_s_echo','volume_level') }}"
media_player.daniel_s_echo_auto: "{{ state_attr('media_player.daniel_s_echo_auto','volume_level') }}"
media_player.daniel_s_echo_show_8_2nd_gen: "{{ state_attr('media_player.daniel_s_echo_show_8_2nd_gen','volume_level') }}"
restore: true
Sequence to change volume & restore.to previous volume:
service: media_player.volume_set
data:
volume_level: 0.5
target:
entity_id: media_player.bedroom_echo_dot_left
service: media_player.play_media
target:
entity_id: media_player.bedroom_echo_dot_left
data:
media_content_id: amzn_sfx_doorbell_chime_01
media_content_type: sound
metadata: {}
service: media_player.volume_set
data:
volume_level: "{{ state_attr('var.last_alexa','media_player.bedroom_echo_dot_left') }}"
target:
entity_id: media_player.bedroom_echo_dot_left
I have found often times volume_level is not set for a device so you can't retrieve it to save and restore.
Up! We still need it!
I have found often times volume_level is not set for a device so you can't retrieve it to save and restore.
If the volume_level
is not even set then how do you expect the integration to know what to do??? That sounds like a totally different issue...
Up! We still need it!
Then propose a workable solution!
All of my echo volume_level
attributes are set...
I absolutely agree. I set the mode to queued to avoid this problem as a tradeoff only to play one device simultaneously.
how did you do that? I see, that this is the only way for me to do this, because the volume level increases after door_chime_sound, even if the logic is used to do before it
The issue has received no activity for 60 days and will be closed in a week.
Updoot
That's Possible?
That's Possible?
What?
There is another way arround this issue:
You can let the volume where it is and play with the message itself using ssml tag as described here: https://docs.aws.amazon.com/polly/latest/dg/supportedtags.html#prosody-tag
I personaly often use the whispering tag for notification at night, and the prosody to increase the volume of some notification above the normal speach volume.
This removes the need to memorize and reset the volume, but is not as effective if the volume as been set to extreme level...
Thanks @BBESINET for this workaround. How do you concretely use the tags in HA though?
@danielbrunt57 this seems like a possible workaround indeed. I think having the ability to simply set the volume_level in play_media would be much simpler.
an exemple for the whisper:
service: notify.alexa_media
data:
message: >-
<amazon:effect name="whispered">The washing machine is finished</amazon:effect>
target:
- media_player.echo_1
- media_player.echo_2
data:
type: tts
title: Washing machine cycle finished
another one for an Alexa doorbell using the prosody:
service: notify.alexa_media
data:
title: "Doorbell"
message: <prosody volume="loud">Somebody is at the front door</prosody>
data:
method: speak
type: announce
target:
- media_player.echo_1
as shown in the link of all supported ssml tags you can apply the tag to only a portion of the text if needed:
service: notify.alexa_media
data:
message: >-
<prosody volume="loud">Attention please </prosody> Somebody is at the front door
target:
- media_player.echo_1
data:
type: tts
title: Test
The issue has received no activity for 60 days and will be closed in a week.
Up! We still need it!
July 2024 and still haven't this feature :( It's too bad that a "simple" feature like that isn't avalable yet
And tomorrow it'll be August! It seems so far to really only be me working hard on this integration and I'm new to the game. I'm still learning the ropes, plus I (like most people) have bills to pay and do not have endless free time.
Everyone thinks it's such a simple feature to implement. Stick your head inside the code and tell me how to do it...