Automation to turn off my receiver when Sonos Connect is paused for 10 minutes

So I’m trying to set up an automation that shuts off my audio receiver if my Sonos Connect that’s connected to it is paused for 10 minutes. I’ve been using the Hass UI to create automations, and it currently does not support time passing, only time of day. I also need a condition so it only does it if the receiver is on a specific input.

The action would be:

- action:
  - data:
      entity_id: media_player.pioneer
    service: media_player.turn_off
  alias: Receiver On for Sonos

I’m just not sure about trigger and conditions. Would it need a trigger? The action would need to be triggered by the Sonos being in paused state for 10 minutes. That sounds like a condition to me. Condition: Sonos is paused, and 10 minutes has passed, and source is CD

I’m unsure about that last one too, because it’s not a state of an entity… its a service data, right?

Really confused! Any help appreciated.

Here’s the automation I use to turn off the activity with my Harmony remote but you can modify it for your amp instead. Also you probably don’t need the conditions. I don’t use the editor so you may have to add an ID to it so it doesn’t mess your other editor automations up or add it to the automation old section.

- alias: "Basement Harmony Hub Powers Off When Music Stops"
  initial_state: on
  trigger:
    - platform: state
      entity_id: media_player.sonos_basement
      to: 'paused'
      for:
        seconds: 45
  condition:
    condition: or
    conditions:
      - condition: template
         value_template: '{{ is_state("sensor.basement_harmony_remote", "Listen To Music") }}'
      - condition: template
        value_template: '{{ is_state("input_select.basement_harmony", "Listen To Music") }}'
  action:
    - service: input_select.select_option
      entity_id: input_select.basement_harmony
      data:
         option: "PowerOff"

Ok, I’ve almost got it, but I don’t understand how to do the condition part for my receiver. This is what I have so far. This would be in my config.yaml file. Is the ‘automation old:’ line correct to keep the UI created automations intact?

automation old:
- action:
  - data:
      entity_id: media_player.pioneer
    service: media_player.turn_off
  alias: Receiver Off when Inactive
  condition:
  - condition: template
    value_template: ‘{{is_state(“????WHAT GOES HERE???") }}'
  id: '1513969364419'
  trigger:
  - entity_id: media_player.living_room
    from: 'playing '
    platform: state
    to: paused
    for:
      minutes: 10

The syntax I can find related to the receiver input is:

“entity_id”: “media_player.pioneer”,
“source”: “CD”

@Ted_Gore

The editor mixes things up for whatever reason, I personally hate it. It’s not as flexible either. When you use automation old, it’s the old manual automations before the editor was introduced. Now they won’t show up in the editor, but they also don’t get messed up on you. So my advice is to use the old section for anything you find in the forums. Give this a try, it should work:

 automation old:
   id: '1513969364419'
   alias: Receiver Off when Inactive
   trigger:
     - platform: state 
       entity_id: media_player.living_room
       from: 'playing'
       to: 'paused'
       for:
        minutes: 10
   condition:
     - condition: template
       value_template: '{{ is_state_attr("media_player.pioneer", "source", "CD") }}'
   action:
     - service: media_player.turn_off
       entity_id: media_player.pioneer

Thanks man! That worked! I appreciate it so much.

1 Like

You’re welcome!