Sonos + Spotify

Hi,

I have Home Assistant running from a raspberry pi and I have also added my Sonos(Ikea) speakers and my Spotify premium account. For controlling this I have Aqara cube and I would like to see if there is any way of getting the Sonos speaker to start playing a fixed Spotify playlist using only the Aqara cube.

Is there anybody who has created a similar setup?

Yep, I’ve done this!

Here’s the code for the playlists only. I’ve got additional automations for pausing (shake) and volume (turn left/right):

alias: 'Cube: Playlist Change (Lounge Cube)'
description: ''
trigger:
  - platform: device
    domain: mqtt
    device_id: ***
    type: action
    subtype: flip90
    discovery_id: *** action_flip90
  - platform: device
    domain: mqtt
    device_id: ***
    type: action
    subtype: flip180
    discovery_id: *** action_flip180
  - platform: device
    domain: mqtt
    device_id: ***
    type: action
    subtype: tap
    discovery_id: *** action_tap
condition: []
action:
  - service: media_player.play_media
    data_template:
      entity_id: media_player.lounge_sonos
      media_content_id: >-
        {% if state_attr('sensor.lounge_cube_action', 'side') == 0 %}
        'https://open.spotify.com/playlist/3hsfVrAsZkA9RWGeMgpV7X' {% elif
        state_attr('sensor.lounge_cube_action', 'side') == 1 %}
        'https://open.spotify.com/playlist/6vQ12X0KSTV34CTB1p2zav' {% elif
        state_attr('sensor.lounge_cube_action', 'side') == 2 %}
        'https://open.spotify.com/playlist/6RxsseYlyxrkJOOmAOLQTM' {% elif
        state_attr('sensor.lounge_cube_action', 'side') == 3 %}
        'https://open.spotify.com/playlist/7aFb4Tv1bV3QTZ2jA7XFHF' {% elif
        state_attr('sensor.lounge_cube_action', 'side') == 4 %}
        'https://open.spotify.com/playlist/5QafFMGgQKGwqgV7k3qHy6' {% elif
        state_attr('sensor.lounge_cube_action', 'side') == 5 %}
        'https://open.spotify.com/playlist/37i9dQZF1DX7K31D69s4M1' {% endif %}
      media_content_type: music
mode: single
3 Likes