home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.72k stars 30.45k forks source link

Sonos integration intermittently times out when using Media player: Play media service #102535

Closed zack-kimble closed 7 months ago

zack-kimble commented 1 year ago

The problem

I have two Sonos devices that I play media on either from the media mount on my HA server or via Spotify. In the past few weeks they've started to have an intermittent timeout error.

The error only happens for the actual play service command. Pause playback and volume setting are working without error. Also, while there's a timeout in the traceback, the track for the Sonos is actually changed to the correct track, just not started.

When I try again hours later, the integration works.

What version of Home Assistant Core has the issue?

System Information version | core-2023.8.2 -- | -- installation_type | Home Assistant Container dev | false hassio | false docker | true user | root virtualenv | false python_version | 3.11.4 os_name | Linux os_version | 5.15.0-1038-raspi arch | aarch64 timezone | America/New_York config_dir | /config
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 1 -- | -- resources | 0 mode | auto-gen
Recorder oldest_recorder_run | October 14, 2023 at 8:15 PM -- | -- current_recorder_run | October 14, 2023 at 4:15 PM estimated_db_size | 2.64 MiB database_engine | sqlite database_version | 3.41.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

sonos

Link to integration documentation on our website

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

Diagnostics information

I'm unable to retrieve the diagnostics. When attempting to download from the integration settings, Chrome reports "Failed - Unknown server error. Please try again, or contact the server administrator."

I'm able to successfully download other integrations diagnostics (Zigby and Lutron).

I turned on debug logs in the Sonos integration and copied the log during a timeout event. Removed auths. File attached sonos_error_logs.txt

Example YAML snippet

alias: Play brown noise
description: ""
trigger:
  - device_id: 7acdbcfe66f5a1f9b6f89b4a023d0ca0
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: remote_button_short_press
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.35
    target:
      entity_id: media_player.symfonisk
  - service: media_player.play_media
    data:
      media_content_id: /media/local/pink_noise_200hz.mp3
      media_content_type: music
    target:
      entity_id: media_player.symfonisk
  - service: media_player.repeat_set
    data:
      repeat: all
    target:
      entity_id: media_player.symfonisk
mode: single

Anything in the logs that might be useful for us?

Fuller logs attached above. Here's the main error

2023-10-22 09:50:05.114 ERROR (MainThread) [homeassistant.components.automation.play_brown_noise] Play brown noise: Error executing script. Error for call_service at pos 2: Error calling SonosMediaPlayerEntity._play_media on media_player.symfonisk: HTTPConnectionPool(host='192.168.1.6', port=1400): Read timed out. (read timeout=9.5)

Additional information

After reloading the integration, I got the following warning (and an error in the web app about polling).

2023-10-22 10:44:21.112 WARNING (MainThread) [homeassistant.components.sonos] Subscription to 192.168.1.6 failed, attempting to poll directly

I updated ufw on the host and reloaded and no longer get this warning/error. Same timeout issue, however.

Restarting the host resolves the issue for a few weeks.

home-assistant[bot] commented 1 year ago

Hey there @jjlawren, mind taking a look at this issue as it has been labeled with an integration (sonos) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `sonos` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign sonos` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


sonos documentation sonos source (message by IssueLinks)

rob12git commented 12 months ago

I have the same problem, at the moment the connection read timeout errors with my Sonos speakers are increasing: Error calling SonosMediaPlayerEntity.select_source on media_player.sonos_buro: HTTPConnectionPool(host='192.168.1.26', port=1400): Read timed out. (read timeout=9.5) If the affected speaker is activated via the Sonos Android App (e.g. music is played), the control via Homeassistant also works again. Homeassistant Version 2023.10.5 (Docker Container)

fontainechristophe commented 12 months ago

I have the same issue. [281472611310912] Error calling SonosMediaPlayerEntity._play_media on media_player.cuisine_2: HTTPConnectionPool(host='192.168.1.57', port=1400): Read timed out. (read timeout=9.5) Sometimes, the media is played but the image of the media is not retrieved from Sonos.

jeremywillans commented 11 months ago

I am also seeing this issue intermittently across multiple sonos service calls.

@jjlawren is is possible to extend the timeout for some of these options like you did in PR #73803?

(some examples which intermittently occurred at different times)


Call-service error. Error calling SonosMediaPlayerEntity.media_pause on media_player.lounge: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)
Call-service error. Error calling SonosSwitchEntity.send_command on switch.lounge_crossfade: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)
Call-service error. Error calling SonosMediaPlayerEntity.set_repeat on media_player.lounge: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)
Call-service error. Error calling SonosSpeaker.join on Girls: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)
jjlawren commented 11 months ago

I am also seeing this issue intermittently across multiple sonos service calls.

@jjlawren is is possible to extend the timeout for some of these options like you did in PR #73803?

(some examples which intermittently occurred at different times)



Call-service error. Error calling SonosMediaPlayerEntity.media_pause on media_player.lounge: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)

Call-service error. Error calling SonosSwitchEntity.send_command on switch.lounge_crossfade: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)

Call-service error. Error calling SonosMediaPlayerEntity.set_repeat on media_player.lounge: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)

Call-service error. Error calling SonosSpeaker.join on Girls: HTTPConnectionPool(host='172.x.x.x', port=1400): Read timed out. (read timeout=9.5)

The timeouts added in the linked PR were for operations which are known to take a long time as they're waiting for an external service to respond. The types of actions you're taking should be instantaneous and extending timeouts would not help. They imply there are connectivity/networking problems or the speaker has failed to respond for some unknown reason.

issue-triage-workflows[bot] commented 8 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.