core: Cast mp3 to Google Home Hub Fails

The problem

A script that has worked fine for a year suddenly fails when trying to cast a long MP3 file to Google Home Hub. Log states the following:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1731, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 717, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/cast/media_player.py", line 737, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/pychromecast/quick_play.py", line 77, in quick_play
    controller.quick_play(**data)
  File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/media.py", line 547, in quick_play
    raise PyChromecastError()
pychromecast.error.PyChromecastError

What version of Home Assistant Core has the issue?

2022.7.1

What was the last working version of Home Assistant Core?

2022.6.7

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Google Cast

Link to integration documentation on our website

No response

Diagnostics information

https://www.home-assistant.io/integrations/cast/

Example YAML snippet

alias: Read Harry Potter
sequence:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.hp_playing
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.bedroom_lights
  - service: media_player.turn_off
    data: {}
    target:
      entity_id: media_player.bedroom_tv
  - service: media_player.play_media
    target:
      entity_id: media_player.bedroom_hub
    data:
      media_content_id: >-
        media-source://media_source/local/{{ ('Harry Potter and the Sorcerers
        Stone, Book 1.mp3', 'Harry Potter and the Chamber of Secrets, Book
        2.mp3', 'Harry Potter and the Prisoner of Azkaban, Book 3.mp3', 'Harry
        Potter and the Goblet of Fire, Book 4.mp3', 'Harry Potter and the Order
        of the Phoenix, Book 5.mp3', 'Harry Potter and the Half-Blood Prince,
        Book 6.mp3', 'Harry Potter and the Deathly Hallows, Book 7.mp3') |
        random }}
      media_content_type: audio/mpeg
  - wait_template: '{{states(''media_player.bedroom_hub'') == ''playing''}}'
  - choose:
      - conditions:
          - condition: state
            entity_id: climate.bedroom_ac
            state: cool
        sequence:
          - service: media_player.volume_set
            data:
              volume_level: >-
                {{ 0.42 +
                (is_state('input_boolean.hp_volume_adjustment','on')|abs)*0.04
                }}
            target:
              entity_id: media_player.bedroom_hub
      - conditions:
          - condition: state
            entity_id: climate.bedroom_ac
            state: 'off'
          - condition: state
            entity_id: climate.living_room_ac
            state: cool
        sequence:
          - service: media_player.volume_set
            data:
              volume_level: >-
                {{ 0.3 +
                (is_state('input_boolean.hp_volume_adjustment','on')|abs)*0.02
                }}
            target:
              entity_id: media_player.bedroom_hub
      - conditions:
          - condition: state
            entity_id: climate.living_room_ac
            state: 'off'
          - condition: state
            entity_id: climate.bedroom_ac
            state: 'off'
        sequence:
          - service: media_player.volume_set
            data:
              volume_level: >-
                {{ 0.28 +
                (is_state('input_boolean.hp_volume_adjustment','on')|abs)*0.02
                }}
            target:
              entity_id: media_player.bedroom_hub
    default:
      - service: media_player.volume_set
        data:
          volume_level: >-
            {{ 0.28 +
            (is_state('input_boolean.hp_volume_adjustment','on')|abs)*0.02 }}
        target:
          entity_id: media_player.bedroom_hub
  - service: media_player.media_seek
    data:
      seek_position: >-
        {{range(1,state_attr('media_player.bedroom_hub','media_duration') |
        round)|random}}
    target:
      entity_id: media_player.bedroom_hub
mode: restart
icon: mdi:glasses

Anything in the logs that might be useful for us?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1731, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 717, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/cast/media_player.py", line 737, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/pychromecast/quick_play.py", line 77, in quick_play
    controller.quick_play(**data)
  File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/media.py", line 547, in quick_play
    raise PyChromecastError()
pychromecast.error.PyChromecastError

Additional information

This worked perfectly prior to 2022.6, and continued to work in 2022.6 although significantly more slowly. Now it doesn’t function at all

About this issue

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

Most upvoted comments

I’ve been debugging the issue together with @drakkather this afternoon, and in his case playing media works OK when using the Home Assistant media player but not with Google’s built-in media player.

It would be very helpful if you who also see this problem can verify that it works also for you, to do that follow these steps: 1. Prepare a local development environment for pychromecast (a working Python 3.8+ environment is needed):

cd <some_working_directory>
git clone https://github.com/home-assistant-libs/pychromecast pychromecast_test
cd pychromecast_test
python3 -m venv venv
source venv/bin/activate
export PYTHONPATH="."
pip3 install -r requirements.txt

Instead of python3, the executable may just be named python. The name of the venv activation script may differ if your environment is not Linux; if it’s some Windows version try source venv/Scripts/activate instead.

Try playing tts or other media using the already signed link shown in the error message (I’m using @drakkather’s link as example)

python3 examples/homeassistant_media_example.py --cast="<name of the cast device>" --show-debug --url "https://xxxxxxxx.duckdns.org:xxxx/local/presencia/04.mp3?authSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmNTA1NzYwMTBmNTY0YTdlODUxYmVhNGU3NDBlNmY3NyIsInBhdGgiOiIvbG9jYWwvcHJlc2VuY2lhLzA0Lm1wMyIsInBhcmFtcyI6e30sImlhdCI6MTY1OTM0NDc2OSwiZXhwIjoxNjU5NDMxMTY5fQ.OM5p0F70XHf-v-dnbKhZTYDZmnv1paJUnSEfsNECciA"

You need to replace <name of the cast device> with the friendly name shown in the Google Home app, so for example: --cast="Living Room"