alexa_media_player: Setting Volume error

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

Describe the bug

When setting Volume Home assistant stops the Script with error ‘volume’ although IT Changes the volume

To Reproduce

Call Action media_player.volume_set within a Script.

Expected behavior

The Script Changes Volume and Carries on without errors

Screenshots

Image

System details

  • Home Assistant version: 2025.3.3
  • alexa_media version (from const.py or HA startup log): 5.6.0
  • alexapy version (from pip show alexapy in homeasssistant container or HA startup log): 1.29.5
  • Is Amazon 2FA/2SV enabled <!—We will not debug login issues if unanswered—> (y/n): n
  • Amazon Domain: amazon.de

Debug Logs (alexa_media & alexapy) Please provide logs.


Logger: homeassistant.components.script.alexa_wecker_langsam_lauter
Quelle: helpers/script.py:524
Integration: Skript (Dokumentation, Probleme)
Erstmals aufgetreten: 07:06:17 (5 Vorkommnisse)
Zuletzt protokolliert: 07:26:34

Alexa Wecker Langsam Lauter: Sequence action at step 1: Repeat at step 4: Error executing script. Unexpected error for call_service at pos 1: 'volume'
Alexa Wecker Langsam Lauter: Sequence action at step 1: Error executing script. Unexpected error for repeat at pos 4: 'volume'
Alexa Wecker Langsam Lauter: Error executing script. Unexpected error for sequence at pos 1: 'volume'
Alexa Wecker Langsam Lauter: Sequence action at step 1: Error executing script. Unexpected error for call_service at pos 1: 'volume'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 524, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1009, in _async_step_call_service
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<9 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 624, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2794, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2837, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
        hass, entity, func, data, call.context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/alexa_media/helpers.py", line 158, in _catch_login_errors
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/media_player.py", line 1254, in async_set_volume_level
    await self.async_update()
  File "/config/custom_components/alexa_media/helpers.py", line 158, in _catch_login_errors
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/media_player.py", line 1059, in async_update
    await self.refresh(device, no_throttle=True)
  File "/config/custom_components/alexa_media/helpers.py", line 158, in _catch_login_errors
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/media_player.py", line 726, in refresh
    else session["volume"]
         ~~~~~~~^^^^^^^^^^
KeyError: 'volume'

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I have updated to the new branch and will test over the next few days. Sometimes the issue was inconsistent for me but should be able to tell after a day or two if its working.

I have echo dot and echo show 5 and their volume settings are fine. However, I don’t understand playing_parents. In what environment is it used?

I believe playing_parents is where you have an echo_dot which is comprised of multiple echo dots, i.e. speaker pairs, etc. echo_dot_living_room is the “parent” for echo_dot_living_room_left and echo_dot_living_room_right I think it also applies when you have echo_dot_main_floor whose children are echo_dot_kitchen + echo_dot_dining_room + echo_dot_living_room, etc. In this case, echo_dot_main_floor would be like a grandparent for echo_dot_living_room_left and echo_dot_living_room_right whose parent is echo_dot_living_room whose parent is echo_dot_main_floor.

@nao-pon Thanks for your response. "I am not exactly sure what you mean by “environment.” If you are referring to the type of Alexa device I am using, I have two Echo (4th Gen) devices. In the automation, I use the player ‘media_player.bathroom_stereo’ group, which consists of the units ‘media_player.echo_bathroom_l’ and 'media_player.echo_bathroom_r, all units (together with the other 29) are part of the “Alexa media_player” integration. Now that I use media_player.turn_off at the end, the issue has been avoided. The intermediate volume change to 0.01 is used to diminish the volume of the “Welcome to TuneIn” announcement, but it is not always successful. Reload_config_entry at the end is needed, because media player state sometimes stucks in “playing state”, although it’s previously turned off (probably an already reported bug). I am enclosing an action part of my automation below just in case:


      - data:
          entity_id:
            - media_player.bathroom_stereo
        action: media_player.turn_on			
      - data:
          volume_level: >-
            {{ 0.12 if now().hour >= 22 and now().minute >= 30 else (0.19 if
            (now().hour >= 21) or now().hour < 6 else 0.24) }}
        target:
          entity_id:
            - media_player.bathroom_stereo
        action: media_player.volume_set			
      - data:
          target:
            - media_player.echo_bathroom_r
          message: |
            <speak>
              <prosody volume="{{ ['x-loud', 'loud'] | random }}"
                       pitch="{{ ['low', 'medium', 'high', '+10%', '-10%'] | random }}"
                       rate="{{ ['medium', 'fast', '120%', '80%'] | random }}">
                <emphasis level="{{ ['moderate'] | random }}">
                  <amazon:emotion name="{{ ['excited'] | random }}">
                    {{ states('input_text.alexa_random_choosen_bathroom_radio_station') }} playing.
                  </amazon:emotion>
                </emphasis>
              </prosody>
            </speak>
          data:
            type: tts
            method: all
        action: notify.alexa_media			
      - data:
          volume_level: 0.01
        target:
          entity_id:
            - media_player.bathroom_stereo
        action: media_player.volume_set
      - target:
          entity_id: media_player.echo_bathroom_l
        data:
          media_content_id: >-
            {{ states('input_text.alexa_random_choosen_bathroom_radio_station')
            }}
          media_content_type: TUNEIN
        action: media_player.play_media
        enabled: false
      - data:
          entity_id: media_player.echo_bathroom_l
          media_content_id: >
            "Alexa, play {{
            states('input_text.alexa_random_choosen_bathroom_radio_station') }}
            on the Bathroom Stereo "
          media_content_type: custom
        action: media_player.play_media
        enabled: true
      - delay: "00:00:05"
      - data:
          volume_level: >-
            {{ 0.12 if now().hour >= 22 and now().minute >= 30 else (0.19 if
            (now().hour >= 21) or now().hour < 6 else 0.24) }}
        target:
          entity_id:
            - media_player.echo_bathroom_r
        action: media_player.volume_set
      - wait_for_trigger:
          entity_id: binary_sensor.philips_bathroom_huemotion_occupancy
          from: "on"
          to: "off"
          trigger: state
        timeout: "00:00:40"
        continue_on_timeout: true
      - delay: "00:00:18"
      - condition: state
        entity_id: binary_sensor.philips_bathroom_huemotion_occupancy
        state: "off"
      - target:
          entity_id: script.alexa_bathroom_random_station
        data: {}
        action: script.turn_on
      - data:
          entity_id: media_player.echo_bathroom_r
          media_content_id: stop radio on Bathroom Stereo
          media_content_type: custom
        action: media_player.play_media
      - delay: "00:00:02"
      - target:
          entity_id:
            - media_player.bathroom_stereo
        action: media_player.media_stop
        data: {}
      - delay: "00:00:02"
      - target:
          entity_id:
            - media_player.bathroom_stereo
        action: media_player.turn_off
        data: {}
      - delay: "00:00:06"
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ is_state('media_player.bathroom_stereo', 'playing') }}"
            sequence:
              - data:
                  entry_id: 01JP0FBSNNQFE69X6QSJ7EQAWF
                target: {}
                action: homeassistant.reload_config_entry
              - delay: "00:00:15"
        default: null
trace:
  stored_traces: 20
mode: restart		







@RobusX I agree that this needs a fix, but for now I worked around the issue by downgrading to v5.5.1 of Alexa Media Player.