Sonos Switch ON/OFF/Volume control

Hi there,

pretty new to Home Assistant :slight_smile: so please take it easy with me :slight_smile:

I have my entire Sonos System kind of running via Home Assistant. I would like to ad a physical “Switchbox” where I can push buttons and turn a knob.
Like this:
1 button switches entire system on/off
1 button mutes kitchen
1 button mutes living room
1 button switches local radiostation on
1 button switches favorite playlist
1 resistor controls volume in “active” area
Everything stowed in a 3D printed box and place in a easy accessable area in the house.
I was hoping to run it on an Arduino Wifi and connect to Home Assistant.

Any help would be highly appreciated.

Thanks :slight_smile:

Hi, I’m not sure why you would want to wire an external switch box rather than use a wireless remote as it seems like a lot more work for less flexibility. Another option would be to use the custom mini media player card on a phone or tablet as per the example below which includes buttons for different stations:

image

A wall mounted tablet with a custom dashboard for controlling your media might be a better option than a hardwired solution with buttons and switches. If you did want to do go down this route then you could probably do it with a microcontroller like a Wemos D1 Mini or NodeMCU. I remember that 4ative on Youtube did a demo recently https://www.youtube.com/watch?v=_2CSAVYUmnc where he had a potentiometer hooked up to a microcontroller with a small OLED display.

I actually have a simple 8-button remote that my partner uses for the following:

  • Bedroom light toggle
  • Sonos Pause/Resume
  • Sonos volume up/down
  • Sonos select Sleep playlist
  • Sonos Next/Prev track

I can share the code if you like but it is probably not what you are after from the sound of it.

Thank you for your reply.

I figured already that it sounded so easy in the beginning but turned out to be almost not possible. The idea was to kind of use it also for our kids to switch on/off (They do not have any mobile device, yet :wink: ) Like an oldschool kitchen radio device. Just 5 buttons and a volume knob… That was the idea :joy:

Since it sounds like too much of a hassle I would try the solution with an old iPad I still have lying around. So it would be awesome if you could share your code. Thank you ! :blush::+1:

This is my Lovace code which defines a 3-high vertical stack (1 for each of my Sonos players) using the HACS Mini Media Player card. Download the plugin from HACS then just paste the following into a new Manual card and edit it to reference your Sonos entities. Remember to also make sure that the buttons reference valid playlists which must exist in ‘My Sonos’ within the Sonos App:

cards:
  - artwork: cover
    entity: media_player.lounge
    hide: null
    speaker_group:
      entities:
        - entity_id: media_player.lounge
          name: Lounge - Sonos Connect Amp
        - entity_id: media_player.bedroom
          name: Bed 1 - Sonos Play 5
        - entity_id: media_player.Study
          name: Study - Sonos Play 3
      platform: sonos
      show_group_count: true
    tts:
      language: en-uk
      platform: sonos
      volume: 0.4
    type: 'custom:mini-media-player'
  - artwork: cover
    entity: media_player.bedroom
    shortcuts:
      buttons:
        - id: Absolute 80s
          name: Abs 80s
          type: source
        - id: .977 80's Hits
          name: 80s Hits
          type: source
        - id: KISS FM UK 100.0 (Top 40/Pop)
          name: Kiss
          type: source
        - id: Nation Radio
          name: Nation
          type: source
        - id: talkRADIO
          name: Talk
          type: source
        - id: Rock
          name: Rock
          type: source
        - id: Christmas
          name: Xmas
          type: source
        - id: Lynettes Favourites
          name: Lynette
          type: source
        - id: Steve's Favourites
          name: Steve
          type: source
        - id: Sleep Sounds
          name: Sleep
          type: source
      columns: 5
    tts:
      language: en-uk
      platform: sonos
      volume: 0.3
    type: 'custom:mini-media-player'
  - artwork: cover
    entity: media_player.study
    shortcuts:
      buttons:
        - id: Absolute 80s
          name: Abs 80s
          type: source
        - id: .977 80's Hits
          name: 80s Hits
          type: source
        - id: KISS FM UK 100.0 (Top 40/Pop)
          name: Kiss
          type: source
        - id: Nation Radio
          name: Nation
          type: source
        - id: talkRADIO
          name: Talk
          type: source
        - id: Rock
          name: Rock
          type: source
        - id: Christmas
          name: Xmas
          type: source
        - id: Lynettes Favourites
          name: Lynette
          type: source
        - id: Steve's Favourites
          name: Steve
          type: source
        - id: Sleep Sounds
          name: Sleep
          type: source
      columns: 5
    tts:
      language: en-uk
      platform: sonos
      volume: 0.3
    type: 'custom:mini-media-player'
type: vertical-stack

This is my automation for an RF remote that also controls the Bedroom Sonos player:

- id: '1595688076706'
  alias: Bed1 Remote
  description: Control Bedroom Sonos and Lights via Remote5
  trigger:
  - entity_id: sensor.remote5
    platform: state
  condition:
  - condition: template
    value_template: '{{ states(''sensor.remote5'') != ''unavailable'' }}'
  action:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 1'' }}'
      sequence:
      - entity_id: media_player.bedroom
        service: media_player.media_play_pause
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 2'' }}'
      sequence:
      - data:
          entity_id: media_player.bedroom
          source: Sleep Sounds
        service: media_player.select_source
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 3'' }}'
      sequence:
      - entity_id: media_player.bedroom
        service: media_player.volume_down
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 4'' }}'
      sequence:
      - entity_id: media_player.bedroom
        service: media_player.volume_up
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 5'' }}'
      sequence:
      - data: {}
        entity_id: media_player.bedroom
        service: media_player.media_previous_track
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 6'' }}'
      sequence:
      - data: {}
        entity_id: media_player.bedroom
        service: media_player.media_next_track
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 7'' }}'
      sequence:
      - entity_id: switch.sonoff06
        service: switch.toggle
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.state  == ''Button 8'' }}'
      sequence:
      - entity_id: switch.bed1_fan
        service: switch.toggle
  initial_state: 'on'
  mode: queued
  max: 3

Note that I use the rfbridge_demux python script to efficiently capture all my RF codes and you and read up on that here Sonoff RF Bridge. Strategies for receiving data. Essentially sensor.remote 5 is either “Button 1” thru “Button 8” if a button has just been pressed otherwise it is “unavailable”.

The cheap remote that I used is this one https://www.aliexpress.com/i/33035885811.html.

Cheers and hope that Helps!

Have you seen this project? https://github.com/adonno/tagreader

I was looking at this for months and I finally got around to building it. First time soldering and it was easier than I thought it would be. Now the kids can just scan an NFC card to start music.

I am also thinking of a tabletop volume control for Sonos speakers that is on the HA. It is been a while since I played with HA or ESP, so need some overview. If I simply want to put a button on a Esp32. What is the best way to issue a volume up on the table controller. Can I issue a node.is command from the esp32 using the Sonos api since I assume the Sonos add on for HA maybe has a node.js Sonos integration, or should I issue a command to the HA to initiate the volume change. And ideally I can eventually use the m5 paper that I have.

I apologize as my question is very vague as it is my basic level or recall right now. Basically looking for a macro view of how I should approach this project. Use the ESP to command the Sonos directly or should I use the table top esp to contact the HA then have it issue the command to Sonos? Which ways is easier? Thanks for pointing me in the general direction.