Button to start Sonos Sleeptimer

Hi , i am quite new to HA and i would like to ask for help from the experts :slight_smile:

I would like to create a button which starts my Sonos speaker playing radio, with a selected volume and a sleeptimer for a amount of time.
So far so good, when i look at my automations there is a automation, but only when i press the “trigger” button it works. The slider doesn’t have any effect and doesn’t start anything.
Is it possible to create a button which starts my automation ? ( Maybe something with boolean ? )

I have used this script :

  alias: NPO Radio 2 sleeptimer 30 min
  trigger:
  - entity_id: media_player.boven
from: Paused
platform: state
to: Playing
  condition: []
  action:
  - service: media_player.media_play_pause
  - service: media_player.sonos_set_sleep_timer
data_template:
  entity_id: media_player.boven
  sleep_time: 1800
  - service: media_player.volume_set
data_template:
  entity_id: media_player.boven
  volume_level: 0.08   
  - service: media_player.select_source
data_template:
  entity_id: media_player.boven
  source: NPO Radio 2
1 Like

I used your automation as inspiration for a script.
I had to change a couple of things because every Sonos in the house started playing.
This shows up as an executable script in HomeAssistant and I use it in HAdashboard behind a button.

scripts.yaml

sleeptimer_joe:
  alias: "Sleeptimer 30 min JoeFM"
  sequence:
  - service: media_player.select_source
    data_template:
      entity_id: media_player.slaapkamer
      source: JoeFM
  - service: media_player.sonos_set_sleep_timer
    data_template:
      entity_id: media_player.slaapkamer
      sleep_time: 1800
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.slaapkamer
      volume_level: 0.04