添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

@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?

Please can you post the complete and updated configuration? I can’t get it to work.
Thanks

#VARIABLE
  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).

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"
              

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 %}
        {% 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.

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 %}
    {% 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.