Sonos
Integration of smart speakers from Sonos brings the ability to play music and control Sonos products directly from HA.
Sonos, founded in 2002, is one of the top manufacturers of smart speakers and sound systems, offering high-quality sound and wireless streaming with smart device integration.
I tested the entire integration process with the Sonos Era 300 product, which I can definitely recommend.
Sonos Era 300
- Sound: Dolby Atmos (Apple Music, Amazon Music), Trueplay
- Wireless connectivity: Bluetooth 5.0, WiFi 6, Multiroom, Apple AirPlay 2
- Voice assistant: Sonos Voice Control, Amazon Alexa
- CPU: Quad Core 4xA55 1.9GHz
- RAM / Storage: 2 GB DDR4, 8 GB eMMC
- Dimensions: 160x260x185 mm
- Weight: 4.47 kg
Sonos App
Not only for integration into HA but also for usage, you will need to install the Sonos app on your mobile phone.
Integrating Sonos into HA
-
Adding the Sonos Integration:
-
Automatically - if the Sonos device is on the same network as Home Assistant, it should be found automatically using the auto-discovery feature and you will find it in the Integrations section under Discovered:
-
Manually:
- Go to the Settings -> Devices & Services menu and make sure you are on the Integrations tab.
- Click on Add Integration and search for Sonos.
or click on:
-
-
Setting up Sonos: Click on the setup button and if everything is fine, you should see the Success! screen, where you can also set the area where the device is located. The specific device type is also visible in the dialog.
-
New Entities:
You should now have several new entities available within one device. The most important one is of type
media_player
, which can be used, for example, in the media-control UI.Additionally, depending on the type of speaker, you can adjust bass and treble levels, enable/disable crossfade, and see the microphone's on/off status.
Services
Playing Music
Favorite Items
By adding a song or radio station to the favorites list - My Sonos, you can play it by calling the media_player.play_media
service.
Unfortunately, playlists from the My Sonos favorites list do not propagate, meaning they are not part of the sensor.sonos_favorites entity. To play a playlist, you need to find its address.
To specify a particular item, we will need the media_content_id
, which can be most easily found using the sensor.sonos_favorites
entity.
The Sonos favorites sensor (sensor.sonos_favorites
) is disabled by default. It can be found and enabled in the entities associated with the Sonos integration on the Devices & Services page.
For example, to play the Evropa 2 radio station from my favorites list, simply call the service:
# Playing from the favorites list
- service: media_player.play_media
target:
entity_id: media_player.living_room
data:
media_content_id: "FV:2/1"
media_content_type: "favorite_item_id"
It might be useful to play a randomly selected favorite item:
# Playing a random song from the favorites list
- service: media_player.select_source
target:
entity_id: media_player.living_room
data:
source: "{{ state_attr('sensor.sonos_favorites', 'items').values() | list | random }}"
Playlist from Apple Music
Plays a playlist from the Apple Music streaming service.
# Playing a playlist from Apple Music
- service: media_player.play_media
target:
entity_id: media_player.living_room
data:
media_content_type: "music"
media_content_id: "https://music.apple.com/cz/playlist/morning-coffee/pl.d8848ee60b8b4b1680fcf3645242691c"
How to get the playlist URL?
It's quite simple. On your mobile phone, switch to the Apple Music app, select a playlist, click on the three dots, share the playlist, and copy the link.
The Apple Music service needs to be already added and set up in the Sonos app.
Playlist from Spotify
Plays a playlist from the Spotify streaming service.
# Playing a playlist from Spotify
- service: media_player.play_media
target:
entity_id: media_player.living_room
data:
media_content_type: "music"
media_content_id: "https://open.spotify.com/playlist/37i9dQZF1DX1g0iEXLFycr?si=dsE0VTRSTfWOphpFxZoUIg&pi=e-Vm1YY7RbTdCa"
How to get the playlist URL?
It's quite simple. On your mobile phone, switch to the Spotify app, select a playlist, click on the share icon, and copy the link.
The Apple Music service needs to be already added and set up in the Sonos app.
Setting Volume
By calling the media_player.volume_set service
, you can set the volume in the range of 0 .. 1, where 0 is mute and 1 is maximum volume.
# Setting volume
- service: media_player.volume_set
target:
entity_id: media_player.living_room
data:
volume_level: 0.25 # setting volume to a quarter of the maximum
Stopping Playback
By calling the media_player.media_stop
service, you can immediately stop music playback.
# Stopping playback
- service: media_player.media_stop
target:
entity_id: media_player.living_room
Specific Services for Sonos
Stopping Playback After a Certain Time
By calling the sonos.set_sleep_timer
service, you can stop music playback after a specified time (in seconds).
# Stopping playback after a certain time (in seconds)
- service: sonos.set_sleep_timer
target:
entity_id: media_player.living_room
data:
sleep_time: 20
Canceling Stopping Playback After a Certain Time
By calling the sonos.clear_sleep_timer
service, you can cancel stopping music playback.
# Canceling stopping playback after a certain time (in seconds)
- service: sonos.clear_sleep_timer
target:
entity_id: media_player.living_room
UI Control in Lovelace
Mini Media Player
I recommend trying the Mini Media Player from the HACS store first.
It has many options, and you can add buttons for favorite items.
In the Lovelace UI settings, you need to switch to manual YAML, as only basic options are available in the UI. For the full range of options, check the repositáře.
# Example configuration for Sonos
type: custom:mini-media-player
entity: media_player.living_room
group: false
volume_stateless: false
artwork: material
sound_mode: full
source: full
shortcuts:
columns: 1
buttons:
- data:
entity_id: media_player.living_room
media_content_id: FV:2/2
media_content_type: favorite_item_id
id: media_player.play_media
name: Evropa 2
type: service
icon: mdi:radio
Sonos Card
If you don't mind a UI component that will only work with Sonos, then also check out the Sonos Card from the HACS store.
It has many more functionalities available right away, meaning you don't need to configure anything. For example, you have access to your favorite songs list and an overview of all your Sonos speakers with the ability to group and control them
Other Products from Sonos
Sonos Era 100
- Sound: Trueplay
- Wireless connectivity: Bluetooth 5.0, WiFi 6, Multiroom, Apple AirPlay 2
- Voice assistant: Sonos Voice Control, Amazon Alexa
- CPU: Quad Core 4xA55 1.4GHz
- RAM / Storage: 2 GB DDR4, 8 GB eMMC
- Dimensions: 182x120x130 mm
- Weight: 2.02 kg
Sonos Arc
- Sound: Dolby Atmos (Apple Music, Amazon Music), Trueplay
- Connectivity: Ethernet 100Mbit, WiFi 5, Multiroom, Apple AirPlay 2
- Voice assistant: Sonos Voice Control, Amazon Alexa
- CPU: Quad Core 4xA53 1.4GHz
- RAM / Storage: 1 GB SDRAM, 4 GB NV
- Dimensions: 87x1142x116 mm
- Weight: 6.25 kg
Comments