Sonos Automation - Scenes (Multiple State Adjustments)

Dear All

A new user here, pleased to meet you! I’ve been playing around a bit with Home Assistant now for a while but still trying to master it as much as possible. Having a good code editor helps luckily.

I’m currently a bit stuck with an automation that I’m trying to set-up; or rather tidy up as I like to keep my automations as small as possible. This is why I was looking into scenes. At the moment I have a rather simple automation that will open up the blinds in the living room and the kitchen and in turn will also start playing the Sonos in the kitchen. The automation for now is as follows:

- id: morning_routine_winter_weekdays
  alias: Morning Routines for Winter Weekdays.
  trigger:
  - at: "07:30:00"
    platform: time
  action:
  - data:
      entity_id:
      - cover.living__groot_raam
      - cover.living__klein_raam
      - cover.keuken__groot_raam
    service: cover.open_cover 
  - service: media_player.select_source
    data:
      entity_id: media_player.keuken
      source: "Joe"
  - service: media_player.volume_set
    data:
      entity_id: media_player.keuken
      volume_level: 0.07      
  - service: media_player.turn_on
    data:
      entity_id: media_player.keuken

What I am trying to achieve now is to change this code towards something as follows:

- id: morning_routine_winter_weekdays
  alias: Morning Routines for Winter Weekdays.
  trigger:
  - at: "07:30:00"
    platform: time
  action:
  - data:
      entity_id:
      - cover.living__groot_raam
      - cover.living__klein_raam
      - cover.keuken__groot_raam
    service: cover.open_cover 
  - service: scene.turn_on
    data:
      entity_id: scene.scene_morning_winter

My scenes file looks as follows:

- name: scene_morning_winter
  entities:
    light.huiskamer:
      state: on
      xy_color: [0.504, 0.412]
      brightness: 254
    media_player.keuken:
      state: playing
      volume_level: 0.07
      source: "Joe"

Interestingly enough my Sonos does start playing at the correct time; however my volume does not get set and the Sonos Favorite does not get selected. It seems that in a scene I’m only able to change the state of 1 item for a media_player component.

Does anyone have any idea what could cause this and if it’s even possible to control the Sonos in a scenes file? I’ve looked around on the community but haven’t really seen an answer towards this question before.

Thanks a lot for the help!

Kind Regards

Bryan

I don’t use scene but script instead.

@EGO01

Thanks for your input. I’ve just had a look at scripts in Home Assistant and indeed. Very powerful functionality which actually made it possible for me to tidy up my automations a lot. I basically changed it to the following now (Thought I’d share):

Automations File

 - id: automation_morning_weekdays_winter
  alias: Automation - Morning Weekdays - Winter
  trigger:
  - at: "07:30:00"
    platform: time
  action:
  - service: script.turn_on
    data:
      entity_id:
      - script.script_open_all_covers
      - script.script_sonos_morning_joe
      - script.script_livingroom_bright

Script File

script_open_all_covers:
  sequence:
    - service: cover.open_cover
      data:
        entity_id:
        - cover.living__groot_raam
        - cover.living__klein_raam
        - cover.keuken__groot_raam
script_sonos_morning_joe:
  sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.keuken
        source: "Joe"
    - service: media_player.volume_set
      data:
        entity_id: media_player.keuken
        volume_level: 0.05
    - service: media_player.turn_on
      data:
        entity_id: media_player.keuken
script_livingroom_bright:
  sequence:
    - service: scene.turn_on
      data:
        entity_id: scene.scene_livingroom_bright

Scenes File

- name: scene_livingroom_bright
  entities:
    light.huiskamer:
      state: on
      xy_color: [0.504, 0.412]
      brightness: 254

Thanks a lot!