• Stars
    star
    155
  • Rank 239,373 (Top 5 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sonos plugin for homebridge: https://github.com/nfarina/homebridge

Sonos accessory

This accessory allows you to turn Sonos speakers on and off using Siri and/or a HomeKit enabled iOS app.

  • Siri, turn Bedroom Speakers on.
  • Siri, turn Bedroom Speakers off.

Installation

Homebridge is published through NPM and should be installed "globally" by typing:

sudo npm install -g homebridge
sudo npm install -g homebridge-sonos

If you don't have Homebridge installed, check the repository for detailed setup instructions.

Configuration

The plugin is configured as part of your Homebridge config.json file.

Example addition to existing config.json:

,{
  "accessories": [
    {
      "accessory": "Sonos",
      "name": "Bedroom Speakers",
      "room": "Bedroom",
      "mute": true
    }
  ]
}

The name parameter is how the device will apear in Apple Homekit.

The room parameter must match the room name in Sonos exactly.

The mute parameter is optional. Setting it to true will mute/unmute the speaker instead of a pause/play. (More information about how this parameter affects devices in groups can be found below.)

Example new config.json:

{
	"bridge": {
		"name": "Homebridge",
		"pin": "000-00-001"
	},

	"description": "Example config for sonos only.",

	"accessories": [{
		"accessory": "Sonos",
		"name": "Bedroom Speakers",
		"room": "Bedroom"
	}]
}

Advanced Configuration Values:

These are additional (and optional) configuration parameters available, with their default values.

      "groupCacheLifetime": 15,
      "deviceCacheLifetime": 3600,

groupCacheLifetime is the maximum amount of time (in seconds) the current Sonos group configuration will be cached in this plugin. The group configuration is how the devices on the current Sonos network are grouped (controlled via the Sonos app).

Note: This setting is currently only used if mute is false. If mute is true, Sonos group information isn't used.

deviceCacheLifetime is the maximum amount of time (in seconds) the information about each Sonos device discovered on the network will be cached.

For the curious, an explanation of what these configurations do can be found below.

Run Homebridge:

$ homebridge

Notes

The name "Speakers" is used in the name for the above example configurations instead of something more intuitive like "Sonos" or "Music" or "Radio".

This is because Siri has many stronger associations for those words. For instance, including "Sonos" in the name will likely cause Siri to just launch the Sonos app. And including "Music" in the name will cause Siri to launch the built-in Music app.

You could of course pick any other unique name, like "Turn on the croissants" if you want. Or add it to a Scene with a custom phrase.

Device Behavior When Grouped

When mute is false

The device status displayed in Homekit will reflect the status of the group the device is part of. On/off commands will result in the entire group being played or paused.

When mute is true

The device status displayed in Homekit will reflect the status of the individual device. On/off commands will apply only to the individual device.

Alternative

You also might check out this fork of homebridge-sonos by dominicstelljes that exposes the Sonos as a "lightbulb" instead of a switch. This will allow you control the volume through Siri - "Set the Speakers to 50%" for example. But it will have some side-effects. Check out his README for more details.

Advanced Configuration explained:

Additional network calls to Sonos devices are required to get detailed descriptions of each device and information about groups. If mute is false (using pause/play for control instead of mute/unmute), this information is used whenever Homekit requests status updates of devices and when requests to turn on/off (play/pause) are made from Homekit. Typically, Homekit will additionally request another status update for the device after a command is issued to play or pause the device.

Requesting these details from Sonos devices every time simple actions are performed in Homekit are unnecessary, so the details retrieved from devices are cached to be used in the next lookup.

Detailed device descriptions are unlikely to change often, so these can be cached for a longer period of time. The lifetime of this cache is controlled by deviceCacheLifetime, and is set to 1 hour by default. In most networks that are unlikely to change, this can practically be any large amount of time with no consequences.

Groups, however, may change frequently or infrequently depending on the preferences of the user, and updates through the Sonos app will not be updated in this plugin until the group cache is refreshed. The lifetime of this cache is controlled by groupCacheLifetime. The default value of 15 seconds is long enough to ensure a single network call is enough to get the information for multiple uses instead of making the request every time, but (ideally) short enough to make the delay between group updates in Sonos app and the information being discovered in this plugin negligible.

More Repositories

1

calloutview

A lightweight callout view class for iOS mimicking UICalloutView.
Objective-C
1,198
star
2

feeds

Keep tabs on your favorite website and RSS feeds from your Mac's menubar.
Objective-C
322
star
3

xmldocument

A lightweight XML Document class for iOS.
Objective-C
276
star
4

xmldoc

A lightweight XML Document class for JavaScript.
JavaScript
269
star
5

homebridge-dummy

Dummy switches for Homebridge: https://github.com/nfarina/homebridge
JavaScript
264
star
6

homebridge-tesla

Tesla plugin for homebridge: https://github.com/nfarina/homebridge
TypeScript
153
star
7

webrequest

A lightweight class for iOS for making asynchronous web requests.
Objective-C
102
star
8

modelobject

ObjC Model Object class using new language features.
Objective-C
69
star
9

dropdav

WebDAV frontend for Dropbox.
Python
66
star
10

homebridge-legacy-plugins

Legacy plugins for Homebridge: https://github.com/nfarina/homebridge
JavaScript
35
star
11

simpledav

Simple WebDAV Server for Google App Engine
Python
31
star
12

homebridge-liftmaster

LiftMaster support for Homebridge: https://github.com/nfarina/homebridge
JavaScript
23
star
13

homebridge-kevo

Kevo support for Homebridge: https://github.com/nfarina/homebridge
HTML
21
star
14

homebridge-eightsleep

Eight Sleep plugin for homebridge: https://github.com/nfarina/homebridge
TypeScript
11
star
15

homebridge-lockitron

Lockitron support for Homebridge: https://github.com/nfarina/homebridge
JavaScript
8
star
16

homebridge-icontrol

iControl (Xfinity Home) for Homebridge: https://github.com/nfarina/homebridge
JavaScript
7
star
17

homebridge-philipshue

PhilipsHue plugin for homebridge: https://github.com/nfarina/homebridge
JavaScript
3
star
18

pooljs

Manage parallel workers with optional rate limits
TypeScript
1
star
19

run

Executes scripts in your package.json much faster than NPM or Yarn, especially for projects using Yarn Workspaces. And with less typing.
TypeScript
1
star
20

homebridge-stack

Stack Lighting plugin for homebridge: https://github.com/nfarina/homebridge
1
star