same as the top yaml, so as stupid as this might sound. My issue ended up being that I was trying to add the yaml to a new script within the ui and changed it to yaml mode. What i needed to do was go to the script.yaml file and add it there with the file browser.
@maplequasar - Thanks for the update on how you fixed this. I’m going to tackle this shortly. But I’m wondering if the Echo has to be ACTIVELY PLAYING (spotify, etc) in order for the script to access its current volume. Have you seen it work where, for example, an idle Echo set to vol 3, was put back to 3 after you made a tts at vol 8?
yes, and no it doesnt have to be playing for the attribute to be stored
Please can you post the complete and updated configuration? I can’t get it to work.
Thanks
#VARIABLE
var:
tts_echo_dot_sala_volume:
value: '0.5'
restore: true
Invalid config for [var]: [value] is an invalid option for [var]. Check: var->var->tts_echo_dot_sala_volume->value. (See /config/configuration.yaml, line 391).
Your first line looks incorrect.
You have var:
Should be variable:
Hoping to get some help here… try as I may, I cannot get this to work.
Always get the error - extra keys not allowed @ data['value_template']
Tried with input_numbers as well… same error.
Help!
Configuration.yaml
variable:
tts_echo_main_volume:
value: '0.5'
restore: true
tts_echo_flat_volume:
value: '0.5'
restore: true
Scripts.yaml
announce_save_main_echo_volume:
alias: Save Current Volume for Main Echo TTS
sequence:
- service: variable.set_variable
data:
variable: tts_echo_main_volume
value_template: '{{ state_attr(''media_player.main_echo_dot'', ''volume_level'')
}}'
tts_restore_main_dot_volume:
alias: Restore Previous Volume for Main Echo TTS
sequence:
- service: media_player.volume_set
data:
entity_id: media_player.main_echo_dot
volume_level: "{% if states('variable.tts_echo_main_volume') != 'None' %}\n
\ {{ states('variable.tts_echo_main_volume') }}\n{% else %}\n .5\n{% endif
%}\n"
announce_save_flat_echo_volume:
alias: Save Current Volume for Flat Echo TTS
sequence:
- service: variable.set_variable
data:
variable: tts_echo_flat_volume
value_template: '{{ state_attr(''media_player.flat_echo_dot'', ''volume_level'')
}}'
tts_restore_flat_dot_volume:
alias: Restore Previous Volume for flat Echo TTS
sequence:
- service: media_player.volume_set
data:
entity_id: media_player.flat_echo_dot
volume_level: "{% if states('variable.tts_echo_flat_volume') != 'None'
%}\n {{ states('variable.tts_echo_flat_volume') }}\n{% else %}\n .5\n
\ \n \n"
I believe I see the problem, and it’s the exact same one I had over a year ago above in this thread. In your 2 announce scripts, you need to change the “value_template” to “value”.
THANKYOU!! I compared those two scripts about 20 times where I saw you had an error, even tried value instead of value_template for the input_number version I tried to create.
getting closer - automation runs, all scripts run. Volume is successfully saved to variale. however Alexas are not restoring volume from variable
EDIT: got it, adjusted the lines so they were all green, set a delay in the automation, seems it is sometimes too quick to grab the variable so a 5-10sec delay works
Hello everyone!
Anyone can help here please… I use the below script to restore the volume
tts_restore_main_dot_volume:
alias: Restore Previous Volume for Main Echo TTS
sequence:
- service: media_player.volume_set
data:
entity_id: media_player.kitchen_alexa
volume_level: '{% if states(''variable.tts_echo_main_volume'') != "None" %}
{{ states(''variable.tts_echo_main_volume'') }}
{% else %}
.5
{% endif %}
'
The problem is that it give me this error when I`m try to run the script:
expected float for dictionary value @ data['volume_level']. Got None
The script for save the volume works ok!
Only difference in what I am using is that in your script above there are a couple of places where you have duplicated the single quotes. For example,
‘‘variable.tts_echo_main_volume’’
should be
‘variable.tts_echo_main_volume’
This happens in one other place as well.
all of a sudden this does not work, I cannot figure out if the volume variable in the echo itself is not updating in a timely manner, which I have observed, or if it is due to a change in the hass-variables hacs module?
this has worked fine for years, now suddenly not running. Unsure if it is due to an update for Alexa or the Var HACS modules. Think its the VAR module
service: media_player.volume_set
data:
entity_id: media_player.main_echo_dot
volume_level: |
{% if states('variable.tts_echo_main_volume') != 'None' %}
{{ states('variable.tts_echo_main_volume')}}
{% else %}
0.5
{% endif %}
Have same issue as @Dorcky -
Failed to call service script/tts_restore_main_dot_volume. expected float for dictionary value @ data['volume_level']
the variables custom integration was changed a while back and doesn’t use the “variable.” domain anymore. they are all changed to the “sensor.” domain (or binary_sensor depending how you have it configured).
so search your system for “sensor.tts_echo_main_volume” and use that instead if you have it.