Sync Sonos Connect, Amp or Port volume and source with your receiver

If you have a Sonos Connect (or Amp, or Port) like me, and you connect it to your home theater receiver, you might’ve run into the issue that it’s not really plug and play. You can start music with the Sonos app, but it will not power most receivers automatically, especially when you connect it through an optical cable for example.

Sonos has a nice feature in their apps as well where you can set the volume of the Connect to passthrough, which means it will not actually set the output volume of the Connect, but we can still read that volume from the Sonos API.

That’s why I’ve made a blueprint that does the following:

  • Switches a media_player entity, like your receiver, to the right source when you start playing.
  • Turns off your receiver if it’s still set to the Sonos source after you stop playing music.
  • Pauses Sonos playback if you turn off your receiver or switch it to another source.
  • Synchronises the volume you adjust in Sonos with that same media_player.
  • Synchronises the volume setting of the media_player back to the Sonos, for example when you twist the volume knob.

Works great between my Sonos Connect (gen 2) and Denon AVR-X1600H. Not tested with anything else, please let me know how well it works for your setup!

There’s a configurable buffer delay for the volume synchronisation so they don’t keep adjusting each other. 1 second works for me, but you might want to put in a higher value if you notice weird behaviour with the volume. Or you can just turn it off if you don’t need it, or like the output adjustment of the Connect itself. (Which I don’t recommend, because it reduces audio quality.)

Check out the source right here: sonos_connect_sync.yaml · GitHub

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

3 Likes

great work!
Tried the blueprint with sonos connect(v2) and Marantz Mcr603.
What worked:
switch on the receiver when playing music over sonos.
there is a one-time-sync between volume of sonos connect and marantz. Any further changes of volume on either device doesnt do anything.
any idea?
sonos connect is in volume pass-through mode
sonos devices are connected via sonos net
what im doing wrong?
==update==
got it working

1 Like

Thank you so much for this! I’ve been wanting to do this, and you helped me out tremendously!

1 Like

Hi there!

Thanks for creating this. I am using a Sonos Port with Marantz receiver. I created a few automations myself, but yours seems cleaner. There are only two things that don’t seem to be working with yours that do with mine…

  1. Powering on the AVR when I start playing Sonos in the zone that is plugged into the AVR.

  2. Setting a max volume on the AVR. Your sync volume implementation is much better than mine, but it makes the assumption that I actually want to go to 100% on my AVR. My AVR gets loud for the room it’s in, and it would be great to add an option to cap the volume. I.E. 100% in Sonos is only 70% of my AVR, and then we just scale the volume.

I’m new to using Github… I’m new to Home assistant… I did get a YAML working, though. Should I try to push changes to yours? Thanks!

Thanks for the suggestions! I actually had a volume scaling functionality in there, but it turned out to be a bad idea as I ran into multiple issues:

  • It’s very hard to sync properly due to calculation differences with floating points.
  • How would you handle a volume set higher on either source outside of the scale?
  • What if the scale doesn’t translate 1 to 1? For the volume property of a media_player this is always the case as the implementation should cover it.

Trying to fix those things meant a lot of jumping around in volume, and there is a better way! I currently solve this by setting a volume limit in the SONOS app itself, which I think is a much cleaner solution anyway. :slight_smile:

I don’t use multiple zones myself, so I’m not entirely sure how that would work properly, and won’t be able to test it. As for pushing your changes, it’s a gist on GitHub so it’s not really built for collaboration, but I could setup a repository if there’s enough interest!

This is really great and works well with my AVR-X4400H. Is there any way to add wakeup when the source is selected in Sonos?

Haha! Yes! I set the volume limit in the Sonos app. Wow I didn’t realize you could do this with a Sonos port. That’s amazing!

Fixed!

One remaining issue - it does not turn my Marantz receiver on / off. Any ideas how to troubleshoot that? Volume sync works great so I know it’s communicating properly w/ the device.

Odd this was working great with my Denon AVR-S960H, and it used to power on automatically, not it doesn’t do it at all. Any tips on how to debug this? Thank you!

1 Like

Would it theoretically be possible to add media_player.turn_on when the Sonos is playing and the Receiver is turned off? I tried to do this, but I’m a total noob regarding blueprints and yaml scripts in general :sweat_smile:

This is my experience as well. This integration doesn’t seem to be fully functional at the moment.

I made some updates to the gist which should make it work again!
Sorry for the lack of updates, but I didn’t receive any notifications, and wasn’t aware people were still using this. :slight_smile:

2 Likes

@Qonstrukt , THANK YOU for the update! It now turns on my AVR as expected. Follow up question re: volume control.

Why is 500ms the lowest I can select? It’s laggy. In my other room, I have it set up with the following YAML. Possible to implement something like that in yours? Great work!

alias: Sonos Playroom - Denon AVR Volume Integration
description: ""
trigger:
  - platform: state
    attribute: volume_level
    entity_id: media_player.playroom_2
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0"
            below: "0.051"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.051"
            below: "0.101"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.05
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.101"
            below: "0.151"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.1
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.151"
            below: "0.201"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.15
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.201"
            below: "0.251"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.2
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.251"
            below: "0.301"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.25
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.301"
            below: "0.351"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.3
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.351"
            below: "0.401"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.35
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.401"
            below: "0.451"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.4
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.451"
            below: "0.501"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.45
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.501"
            below: "0.551"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.5
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.551"
            below: "0.601"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.55
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.601"
            below: "0.651"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.6
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.651"
            below: "0.701"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.65
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.701"
            below: "0.751"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.7
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.751"
            below: "0.801"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.75
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.801"
            below: "0.851"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.8
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.85"
            below: "0.9"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.85
      - conditions:
          - condition: numeric_state
            entity_id: media_player.playroom_2
            attribute: volume_level
            above: "0.9"
            below: "0.95"
        sequence:
          - service: media_player.volume_set
            target:
              device_id: aacf8967955047d429e6598f0c6971b0
            data:
              volume_level: 0.9
    default: []
mode: single

@Qonstrukt Thank you so much for updating and fixing this, greatly appreciated!!!

Hello,

Thank you for the automation. But I have the problem when the Sonos is playing and the receiver is switched on, the volume jumps to 0. If I disable the automation, I don’t have the problem.

@Qonstrukt I can’t for the life of me get this to work. I can control both my AVR and my Connect individually through home assistant, just no automatically with your automation. Are there any updates to this?