npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

homebridge-sonos-so-simple

v0.5.2

Published

A very simple plugin for controlling Sonos devices via Homebridge.

Downloads

140

Readme

Build and Lint npm npm MIT license

Homebridge Sonos So Simple

What does it do?

If, like me, you've bought a Sonos soundbar (Beam/Arc) and just want to expose a few settings to Homekit to control via Siri then this is the package for you!

This package gives you options to control the volume, mute, speech enhancement and night mode via Homebridge with very little config setup.

Example Configuration

    "platforms": [
        ...
        {
            "muteSwitch": true, //with this to false there will be no mute switch, you will only be able to toggle volume by turning the volume off
            "soundbarsOnly": false, //if you only want to expose your TV soundbar, and not sonos speakers in another room, set this to true
            "roomNameAsName": false, //setting this to false will take the master device name instead; e.g. Beam
            "volume": "fan", //Options here are bulb/fan/none
            "platform": "SonosSoSimplePlatform",
            "volumeControlEndpoints": false //Really only if you want some volume endpoint madness, see section below
        }
        ...
    ]

Installation

Either search via the Homebridge config for homebridge-sonos-so-simple

npm install homebridge-sonos-so-simple -g

Once installed update the config, again using the config ui or using the example config above.

REST Control Endpoints

As of version 0.3.0 the plugin can offer api endpoints to allow you to hook up shortcuts and or buttons to trigger the volume up and down. And as of 0.5.0, toggle device settings like mute, night mode and speech enhancement. By default this feature is turned off in the config.

Once the featured is toggled on the plugin will open up a port on the Homebridge server and offer the endpoints for each discovered Sonos zone.

Eg:

{{HOMEBRIDGE_ADDRESS}}:3000/LivingRoom/Beam/volume-up
{{HOMEBRIDGE_ADDRESS}}:3000/LivingRoom/Beam/volume-down
{{HOMEBRIDGE_ADDRESS}}:3000/LivingRoom/Beam/toggle-mute
{{HOMEBRIDGE_ADDRESS}}:3000/LivingRoom/Beam/toggle-night-mode
{{HOMEBRIDGE_ADDRESS}}:3000/LivingRoom/Beam/toggle-speech-enhancement

To create a shortcut in the shortcuts app, pick the "Get Contents of URL" option, type the url in and voila!

The actual port it opened & the URIs it generated will be outputted into the logs so have a look and grab yours from there.

By default the endpoint will increment/decrement the volume in steps of 2 but you can change this by adding a value param to the URL.

Eg:

{{HOMEBRIDGE_ADDRESS}}:3000/LivingRoom/Beam/volume-up?value=10
{{HOMEBRIDGE_ADDRESS}}:3000/LivingRoom/Beam/volume-down?value=5

You can make the request using any HTTP verb you want. GET/PUT/POST, pick whatever your heart desires. Technically it should be a PUT but I can't be bothered restricting it in case it causes someone a problem.

Plugin Notes & Caveats:

The Home app doesn't play nicely with speakers, or properly support most of what HomeKit offers. So to get around this you'll be offered the option to treat the volume control as a fan or a lightbulb. The goal being that you can still say 'Hey Siri, set my Beam to 20%' or have a movie scene that cranks the volume up and turns speech enhancement on. Choosing to treat the volume as a lightbulb will cause the volume to mute if you issue commands to turn all the lights off to Siri.

The port number for the volume endpoints could change when Homebridge is restarted, but I think this is unlikely. Essentially the plugin will try to grab port 3000, but if it can't it will try to grab the next available port. There is a chance that a previous setup will output a port number but then after restarting Homebridge that port will be taken. So in this case the plugin will grab another port instead.

I could mitigate this by asking users to pick a port for themselves and then have it in the config and handle the error if the port is in use but I think that adds complexity that sort of ruins the name of "sonos-so-simple". If the port changing is becoming a problem for you open up a ticket on the issues tab and I'll have a look at it.

Finally, I'm fairly certain that the Volume Endpoints feature is an utterly stupid implementation in this instance, but I came across Avi Millers neat idea and thought it might suit. So if you have a firmer understanding of Homebridge and know of a better way please open up a ticket in the issues tab and let me know.

References

Thanks to Avi Miller and his repo for the idea for implementing the Volume Endpoints feature.