Turn on radio on Sonos in morning when I come downstairs

I have the HACs Sonos card addon and a bunch of Sonos speakers broken into three groups, upstairs downstairs and all.

I have TuneIn on Sonos. I have CBC Toronto radio as a Sonos favorite which I like to listen to with my coffee in the morning.

So the plan is, if it’s after 6:30 am, the night-time Boolean switch is off and I break the hall sensor, to then turn on that favorite on the downstairs speaker group at the proper volume. Of course I would turn on the kitchen lights as well.

The conditions are pretty straightforward, but I’m not sure how to use the Sonos integration to start a specific song or playlist or favorite from an automation. Is this doable?

Thank you

Easy. From the UI under action use the “Play Media”, select your Sonos group as target and the Sonos Favorite to play.

What will happen using the automation below if the Ecobee presence sensor no longer senses presence? Will the music stay on?

alias: Play Music in Morning
description: Play Music Favourite in Morning on downstairs Sonos
trigger:
  - platform: state
    entity_id:
      - binary_sensor.main_floor_occupancy
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 10
condition:
  - condition: time
    after: "06:30:00"
  - condition: time
    before: "07:30:00"
  - condition: state
    entity_id: input_boolean.day_night_mode
    state: "off"
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.sonos_downstairs
    data:
      media_content_id: FV:2/1
      media_content_type: favorite_item_id
    metadata:
      title: JAZZ.FM91
      thumbnail: http://cdn-radiotime-logos.tunein.com/s31229q.png
      media_class: genre
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: favorites
          media_content_id: ""
        - media_content_type: favorites_folder
          media_content_id: object.item.audioItem.audioBroadcast
mode: single

Yes, when it is triggered it will start to play until you stop it. If you want it to stop when no motion is detected then just make a separate automation that triggers when the sensor goes from “on” to “off” and then call service media-stop.

Can anyone suggest why this is not working, running from a script to be called from an automation?

I checked, the Sonos Favorites entity is enabled. When I click RUN, I get no errors, it runs the script, but the music does not turn on.

alias: Music_morning
sequence:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.sonos_downstairs
      volume_level: 0.3
  - service: media_player.play_media
    target:
      entity_id: media_player.sonos_downstairs
    data:
      media_content_id: FV:2/1
      media_content_type: favorite_item_id
    metadata:
      title: JAZZ.FM91
      thumbnail: http://cdn-radiotime-logos.tunein.com/s31229q.png
      media_class: genre
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: favorites
          media_content_id: ""
        - media_content_type: favorites_folder
          media_content_id: object.item.audioItem.audioBroadcast
mode: single