Help with SONOS Automation

Hi

Need some help with my Sonos automation. I have it playing Music at night, but I am trying to add a condition that if the “Bedroom.Sonos” is playing TV, then don’t execute. however it seems to be ignoring the condition?

Any help would be greatly appreciated

alias: Bedoom Sonos Goodnight
description: ""
trigger:
  - platform: time
    at: "23:00:00"
    enabled: true
  - platform: state
    entity_id: media_player.bedroom_sonos
    enabled: false
condition:
  - condition: template
    value_template: "{{ not is_state('media_player.bedroom_sonos', 'TV') }}"
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.bedroom_sonos
    data:
      media_content_id: FV:2/44
      media_content_type: favorite_item_id
    metadata:
      title: Sleep Sounds
      thumbnail: >-
        https://is4-ssl.mzstatic.com/image/thumb/Features122/v4/a7/58/56/a75856c0-d2b4-352d-b212-5f64070ae9af/8195237e-e0f5-4788-a441-d70c0f5d55ce.png/400x400SC.DN01.jpeg?l=en-GB
      media_class: playlist
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: favorites
          media_content_id: ""
        - media_content_type: favorites_folder
          media_content_id: object.container.playlistContainer
  - service: media_player.volume_set
    data:
      volume_level: 0.07
    target:
      entity_id: media_player.bedroom_sonos
  - service: media_player.volume_set
    data:
      volume_level: 0.15
    target:
      entity_id: media_player.bathroom_sonos
  - service: media_player.volume_set
    data:
      volume_level: 0.07
    target:
      entity_id: media_player.bedroom_2_2
  - service: sonos.set_sleep_timer
    data:
      sleep_time: 1800
    target:
      device_id:
        - 8ff1053860d8c5145e489ac86b9f3bfc
        - 1af2bef85039de3ac526866a81692b18
        - bc2c3a5bd688068432a0cd643a1da8e4
      entity_id: media_player.bedroom_2_2
mode: single

Are you sure the state is TV?
Normally a media player would have a state of Playing when it is playing something and then source or some other attribute set to TV.
Check the HA developer tools under the States tab.

These are the “Attributes” under states when I set the source to TV
The State is “Playing”
Ok, so that’s why its not working. is there a way to set a condition based on Attributes? or a better way to do this?

group_members: media_player.bedroom_sonos
volume_level: 0.04
is_volume_muted: false
media_content_id: x-sonos-htastream:RINCON_B8E93770789E01400:spdif
media_content_type: music
media_title: TV
shuffle: false
repeat: off
queue_size: 1
device_class: speaker
friendly_name: Bedroom Sonos
supported_features: 4127295
source_list: TV
source: TV

Try

state_attr('media_player.bedroom_sonos', 'media_title')!='TV'

Thanks, but that didn’t work

I tested it by disabling the time trigger (I also removed the other disabled trigger) and running the automation. I had the SONOS set to TV, but it still played Music.

alias: Bedoom Sonos Goodnight
description: ""
trigger:
  - platform: time
    at: "23:00:00"
    enabled: false
condition:
  - condition: template
    value_template: state_attr('media_player.bedroom_sonos', 'media_title')!='TV'
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.bedroom_sonos
    data:
      media_content_id: FV:2/44
      media_content_type: favorite_item_id
    metadata:
      title: Sleep Sounds
      thumbnail: >-
        https://is4-ssl.mzstatic.com/image/thumb/Features122/v4/a7/58/56/a75856c0-d2b4-352d-b212-5f64070ae9af/8195237e-e0f5-4788-a441-d70c0f5d55ce.png/400x400SC.DN01.jpeg?l=en-GB
      media_class: playlist
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: favorites
          media_content_id: ""
        - media_content_type: favorites_folder
          media_content_id: object.container.playlistContainer
  - service: media_player.volume_set
    data:
      volume_level: 0.07
    target:
      entity_id: media_player.bedroom_sonos
  - service: media_player.volume_set
    data:
      volume_level: 0.15
    target:
      entity_id: media_player.bathroom_sonos
  - service: media_player.volume_set
    data:
      volume_level: 0.07
    target:
      entity_id: media_player.bedroom_2_2
  - service: sonos.set_sleep_timer
    data:
      sleep_time: 1800
    target:
      device_id:
        - 8ff1053860d8c5145e489ac86b9f3bfc
        - 1af2bef85039de3ac526866a81692b18
        - bc2c3a5bd688068432a0cd643a1da8e4
      entity_id: media_player.bedroom_2_2
mode: single

You might need {{ and }} still

I think you worded that a bit to nicely. Sorry, I was not paying attention to what I was doing. looks like its working now. THANK YOU