A Sonos control module for Scriptable.
- One or more Sonos speakers
- Scriptable
- Sonos HTTP API
- Install the Sonos HTTP API server on a computer that's on the same network as your Sonos system. (A Raspberry Pi works well for this purpose.)
- Copy
SonosController.js
to a location where Scriptable'simportModule
function can find it. (If you're using iCloud Drive, copy the file to the Scriptable folder in iCloud Drive. See the importModule documentation for other suitable locations.) - Copy
SonosSettings.js
to a location where Scriptable'simportModule
function can find it. (If you're using iCloud Drive, copy the file to the Scriptable folder in iCloud Drive. See the importModule documentation for other suitable locations.) - Change the
sonosServerUrl
value inSonosSettings.js
to the IP address of the computer where the Sonos HTTP API server is running. - Create a new script in Scriptable. At the top of the script, add these lines:
// Import the controller class and settings.
const SonosController = importModule('SonosController');
const settings = importModule('SonosSettings');
// Create a controller instance.
const controller = new SonosController(settings.sonosServerUrl);
You can then access any of the methods via the controller
.
Examples:
- Get a list of your Sonos playlists:
let myPlaylists = await controller.getPlaylists();
- Play a playlist in a room:
await controller.playPlaylist('My Playlist', 'Living Room');
(All of the methods are asynchronous, so use await
if you need things to happen in a particular sequence.)
See the Examples directory for examples of small and medium "now playing" widgets built using this module.