Created At
Feb 08, 2022
Created By Joep Verhaeg
Automatically control, group and ungroup your Sonos players
Created At
Feb 08, 2022
Last Update
Jan 20, 2023
Platforms
HC 3 Lite, Z-box Hub, Yubii Home Pro, Venture WISE, HC 3
Views
4676
Download
471
There are some Sonos Quick Apps already available for the Home Center 3, but none of them can group and ungroup Sonos speakers.
This Quick App that has little to no impact on your network because it doesn't use polling for status. It is made for use in Lua scenes or other Quick Apps and has a minimal GUI that can be refreshed manually.
From a Lua scene (or Quick App) you can:
Sonos stores playlists, InTunes stations and albums in My Sonos in alphabetical order. You cannot adjust this. The first 4 items are shown, but you can play all favorites easily which I show you later on.
With the following code examples I'll show you how you can use the Sonos Group Controller Quick App to fully automate your music expecience in your smarthome:
In all examples the variable qaId
is the ID
of your Quick App.
fibaro.call(qaId, "savePlayStateAndPause")
|
Useful in presence detection automations where you want to save the state of your players and automatically pause all players when everybody left the house.This command saves the current player state (like PLAY/STOP) and pauses the player.
fibaro.call(qaId, "setPreviousPlayerState")
|
Useful in presence detection automations where you want to automatically set the previous state of your players when the first person arrives at home.This command retrieves the previous saved player state (like PLAY/STOP) and turns the speaker back on if it was playing music.
fibaro.call(qaId, "playFavorite", "title", "15")
|
Easily play a favorite from the My Sonos list by using the title of the favorite. The second parameter is the volume at which you want to play this favorite. First the volume is set before the favorite is played, so that you are not surprised with a loud volume from a previous listening session.
local playerSource = "x-rincon:" .. fibaro.getValue(1001, "model")
fibaro.call(1002, "playFromUri", playerSource , "")
|
With this command you can add a player to a group (or create one). Use the playerUuid
from the speaker that is currently playing the music (the group master).
In this example the livingroom speaker with an id
of 1001
is playing and you want to create a group with the kitchen speaker (with an id
of 1002
). You first contruct the Uri with the id
from the livingroom speaker and then add this Uri to the kitchen speaker. Now the Sonos System creates a group.
fibaro.call(qaId, "LeaveGroup")
|
When you send this command to a Sonos speaker it automatically leaves the group it is in.
fibaro.call(qaId, "configureSleepTimer", "23:15:00")
|
When you send this command to a Sonos speaker it turns off the music at 23:15 (Sonos sleep timer function).
You can read the full documentation of the Sonos Group Controller Quick App at:
https://docs.joepverhaeg.nl/sonos-group-controller/
Hello - LOVE this QA, been looking for something like this - I nearly gave up! Wondering if it would be possible to save the state and recall it? Target solution: 1. Get & save state 2. Play MP3 (Doorbell) 3. Resume saved state Idea being is that if Sonos is currently playing "something" it will resume after playing the doorbell mp3. Big fan of your smart home adventure too :)
Hello. Great QA! But it is possible to get the current state of a Sonos speaker? I would like to call something like: Fibaro.getvalue(qaID, "state") to get the state of the speaker so I can control play/pause from one button. If the speaker is paused = play and if the speaker is playing = pause. Thank you very much :-)
Great job!!
@Jeroen L: please send me an e-mail with the code you use in the scene (my e-mail address is in de QA header). With just this info about the sleep timer its very hard to help. Please note that support is limited, I'm not a support desk.
Thank you. Now it just saves play/pause state and not the current playing song. Give me 2 a 3 weeks from now to start implementing what you want, because of the summer activities with my family at the moment. 😎