Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonos Component fails to restore if join group is the same as was already playing... #20861

Closed
Swiftnesses opened this issue Feb 8, 2019 · 7 comments · Fixed by #21411
Closed
Assignees

Comments

@Swiftnesses
Copy link

Swiftnesses commented Feb 8, 2019

After a whole day of testing, I can confirm that Sonos component fails to restore the correct state (tested via scripts and Node Red!) if the original group is the same as the one specified in the script.

Examples:

If speaker 1, 2 and 3 are already playing, this fails:

sonos_say:
  sequence:
    - service: media_player.sonos_snapshot
    - service: media_player.sonos_unjoin
    - service: media_player.sonos_join
      data_template:
        master: "speaker_1"
        entity_id: "speaker_1,speaker_2,speaker_3"
    - service: tts.google_say
      data_template:
        entity_id: "speaker_1,speaker_2,speaker_3"
        message: "{{ what }}"
    - delay:
        seconds: 5
    - service: media_player.sonos_restore

If any other combination is playing before the script fires, it restores correctly, i.e.

speaker 1 and 2 are playing: works.
speaker 1 and 3 are playing: works.
speaker 1, 2 and 3 are playing: fails! (restores with random track, or fails to restore).

@Swiftnesses
Copy link
Author

Swiftnesses commented Feb 8, 2019

Oh man, literally hours spent trying to work this out, finally, I solved an issue of this not being fully reproducible! It's very odd indeed.

SO.

If i use the above configuration, this works (restores 100%)

screenshot 2019-02-08 at 11 28 40

This does not (100%)

screenshot 2019-02-08 at 11 25 43

I have no idea, but something breaks when the speakers are in a specific order!

@Swiftnesses
Copy link
Author

GOT IT, finally after nearly 2 days!

Basically, if the Master you set in join, is already master (i.e. top of the group in the Sonos app), it will not restore correctly. Now, how to fix this?

@Swiftnesses
Copy link
Author

For now, I've solved it via Node Red.

Basically I check player attributes (sonos_group), I make sure my intended master isn't already master, if it is, I pick another before sending to my script.

@Swiftnesses
Copy link
Author

FYI, sometimes it still fails and I see this in the logs:

Error handling message: {'type': 'call_service', 'domain': 'media_player', 'service': 'sonos_restore', 'service_data': {}, 'id': 13}
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/websocket_api/decorators.py", line 17, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/websocket_api/commands.py", line 148, in handle_call_service
    connection.context(msg))
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1130, in async_call
    self._execute_service(handler, service_call))
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1154, in _execute_service
    await self._hass.async_add_executor_job(handler.func, service_call)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/sonos.py", line 218, in service_handle
    device.restore(service.data[ATTR_WITH_GROUP])
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/sonos.py", line 293, in wrapper
    return funct(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/sonos.py", line 1016, in restore
    self._coordinator.restore(False)
AttributeError: 'NoneType' object has no attribute 'restore'

@Swiftnesses
Copy link
Author

Urgh, still fails on me too often, too much time wasted on this - will seek an alternative output.

@Swiftnesses
Copy link
Author

Okay, I have a working fix with Node Red.

Using the attributes of all the Sonos players, find the current master and ONLY save / restore the snapshot of it (no other speakers!).

Seems to work perfectly. Note: If a speaker isn't part of the group but has the attribute of 'playing', I also include that entity in the TTS output (as we can assume it's not near other speakers or it would be grouped!).

Hope this helps others.

@amelchio
Copy link
Contributor

I think there is no easy way to fix this. Everybody wants to do different things and restore tries to be too smart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants