Hi. Very happy to have discovered the variable custom component by @rogro82
But I am having a small problem on it’s use. I basically have a Google Home that is also my doorbell speaker. It’s volume is usually under 50%, but when the doorbell rings I want to bump it up to 80%, then back to whatever it was previously set to. I’m sure variable can help me do this.
This is my basic declaration:
variable:
mario_volume:
value: '0.3'
So, do I capture the current volume with something like this? Or does value_template need to be done from an automation?
And presuming I can this working and I have rung the doorbell at 80%. Do I restore the media player’s volume with something like this in an automation or script?
This great custom-component was able to do this. I worked it out and thought I’d post my method in case somebody needs a similar solution one day. My first post’s code is messy - please ignore.
configuration.yaml
variable:
mario_volume:
value: '0.4'
script.yaml
mario_vol_read:
alias: Mario Volume Read
sequence:
- data:
entity_id: media_player.mario
service: media_player.turn_on
- delay:
seconds: 0.5 # ensure the Google Home device is 'awake', after being turned on
- data:
value_template: >
{% if is_state('media_player.mario', 'idle') %}
{{ states.media_player.mario.attributes.volume_level }}
{% elif is_state('media_player.mario', 'playing') %}
{{ states.media_player.mario.attributes.volume_level }}
{% else %}
0.4
{% endif %}
variable: mario_volume
service: variable.set_variable
mario_vol_write:
alias: Mario Volume Write
sequence:
- delay: 00:00:15 # ensures that my mp3 has had time to fully play before lowering the volume
- service: media_player.volume_set
data_template:
entity_id: media_player.mario
volume_level: '{{ states.variable.mario_volume.state }}'
doorbell:
alias: Doorbell
sequence:
- data:
entity_id: media_player.mario
volume_level: '0.8'
service: media_player.volume_set
- data:
entity_id: media_player.mario
media_content_id: https://domain.duckdns.org/local/audio/big_ben_doorbell.mp3
media_content_type: audio/mp3
service: media_player.play_media