Set Sonos Sleep Timer

Hey!
I want to create a script which starts a sonos player, set the volume and set the sleeptimer.

Here is my 22343 try: :slight_smile:

sonos_schlafen:
  sequence:
    - service: media_player.play_media
      data_template:
        entity_id: media_player.schlafzimmer
        media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
        media_content_type: music
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.schlafzimmer
        volume_level: 0.02
    - service: media_player.sonos_set_sleep_timer
      data_template:
        entity_id: media_player.schlafzimmer
        sleep_time: 1800

When I activate the script, the music plays, the volume is set, but the sleeptimer is unset. I get this error in the log:

17-04-25 18:03:26 ERROR (Thread-10) [homeassistant.core] Error doing job: Future exception was never retrieved Traceback (most recent call last): File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run result = self.fn(*self.args, **self.kwargs) File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 1020, in execute_service service_handler.func(service_call) File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/sonos.py”, line 166, in service_handle device.set_timer(service.data[ATTR_SLEEP_TIME]) AttributeError: ‘SonosDevice’ object has no attribute ‘set_timer’

Can someone help me?
Thank you!!

No Idea? Thank you

If you look at your services dev tool, do you see a sonos_set_sleep_timer service for the domain media_player?

If you do, what happens when you activate the sleep timer service from there?

Your service data will be something like:
{"entity_id":"media_player.schlafzimmer","sleep_time":"1800"}

Also - since you’re not using a data template, try just using “data:”

Yes I see the service for the domain media_player.
This happens:

17-04-27 16:59:23 ERROR (Recorder) [homeassistant.core] Error doing job: Future exception was never retrieved Traceback (most recent call last): File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run result = self.fn(*self.args, **self.kwargs) File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 1020, in execute_service service_handler.func(service_call) File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/sonos.py”, line 166, in service_handle device.set_timer(service.data[ATTR_SLEEP_TIME]) AttributeError: ‘SonosDevice’ object has no attribute ‘set_timer’

same error if I use the “data:”

Sorry - I don’t use Sonos, so I’m not able to help further.

Do the other Sonos services work?

Yes the other services are working well.

I have been stuck with this issue as well. I believe it is a bug.

Looks like someone already opened an issue on GitHub. Generally, it’s a good idea to check there.