nfarina / homebridge-sonos

Sonos plugin for homebridge: https://github.com/nfarina/homebridge
154 stars 52 forks source link

Volume Control with Sonos #3

Open andy-81 opened 8 years ago

andy-81 commented 8 years ago

Hi All,

First of all thanks for all the hard work everyone has put in with the homebridge server, Ive been using it on a RPi model B version 1 and after having some issues getting it up and running have now managed to get through all the issues I had making it stable but after switching to Jessie all is working well.

The issue I have at present is with the Sonos plugin. I can turn the speakers on and off without any issues however the volume I am unable to control with Siri. I believe the issue is somewhere in how it is registering the volume and as others are mentioning they have it working I am wondering what has gone wrong but I have reinstalled and cleared settings a number of times and it always comes back the same. If I use the MyTouchHome application I can indeed see the volume and it shows the volume correctly and allows me to adjust it within the app however it has N/A next to the volume control which is why I believe it has registered somewhere incorrectly.

Can anyone think of anything I have done wrong or any adjustments in the son files I may need to make? I took a quick look through and couldn't see anything obvious (I have a small amount of programming knowledge although it is very rusty as this was from when I was in school) Any help would be appreciated to work out why it is showing as N/A in the app and why Siri is unable to understand volume.

All I did for the install was npm install -g home bridge-sonos and then configured the Accessories section in my config file so not hacked around with the code as yet only had a look at the relevant files to see anything obvious. The latest install was a week ago now, I did try an npm update.

Thanks all and thanks for your help and special thanks to nfarina for starting up the project.

davidgruhin commented 8 years ago

I too am unable to control the volume with Siri, although I am able to adjust it in MyTouchHome, as well as turn the speakers on and off using Siri.

Please advise.

Thanks!

hdoucet commented 8 years ago

Same problem .. i can change the volume via MyTouch App .. but not via Siri. Can somebody tell what SIRI words must be used to change the volume ?

NovaGL commented 8 years ago

The reason it doesn't work is Siri doesn't understand the word "Volume"

It is a custom command for HomeKit, if this plugin was implemented differently you could say set brightness or hue or any other known command and it would change the volume

farberm commented 8 years ago

NovaGL

Can you help implenmenting the sonos plugin to do volume?

NovaGL commented 8 years ago

It's not possible Siri does not support volume, if you change the word to brightness (in the code) it will work.

Eg "Hey Siri, set Lounge Sonos Brightness to 50"

farberm commented 8 years ago

I have tried that and it does not work.

On Jan 2, 2016, at 8:51 PM, NovaGL notifications@github.com wrote:

It's not possible Siri does not support volume, if you change the word to brightness it will work.

Eg "Hey Siri, set Lounge Sonos Brightness to 50"

— Reply to this email directly or view it on GitHub https://github.com/nfarina/homebridge-sonos/issues/3#issuecomment-168449585.

farberm commented 8 years ago

nfarina:

Can you update the code. I tried to do it locally and it did not work.

NovaGL commented 8 years ago

Did you try replacing

.addCharacteristic(VolumeCharacteristic)

with

.addCharacteristic(new Characteristic.Brightness())

You can also use the word hue or saturation if you prefer.

JBX77 commented 8 years ago

You can create scenes with the Elgato Eve app to change the volume. I have scenes for 10, 20 and 30% which is enough for daily use.

andy-81 commented 8 years ago

As per NovaGL's response changing the one line he mentioned will allow you to change the volume using brightness as well as ask what the brightness is to get the current volume of the speaker. It is on line 35 of the index.js file.

JBX77 commented 8 years ago

I can confirm NovaGL's solution works for the volume. It now works with a spoken command like "Change Sonos Livingroom to 20%".

hdoucet commented 8 years ago

So i tried changing line 35 from addCharacteristic(VolumeCharacteristic) to .addCharacteristic(new Characteristic.Brightness()) But when i start homebridge i cannot run the program. I get following output ...

"dgram.js:461 throw new Error('Not running'); // error message from dgram_legacy.js ^

Error: Not running at Socket._healthCheck (dgram.js:461:11) at Socket.close (dgram.js:354:8) at SonosAccessory. (/usr/local/lib/node_modules/homebridge-sonos/index.js:70:23) at /usr/local/lib/node_modules/homebridge-sonos/node_modules/sonos/lib/sonos.js:614:7 at Parser. (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sonos/node_modules/xml2js/lib/xml2js.js:255:20) at emitOne (events.js:77:13) at Parser.emit (events.js:169:7) at Object.saxParser.onclosetag (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sonos/node_modules/xml2js/lib/xml2js.js:225:24) at emit (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sonos/node_modules/xml2js/node_modules/sax/lib/sax.js:615:33) at emitNode (/usr/local/lib/node_modules/homebridge-sonos/node_modules/sonos/node_modules/xml2js/node_modules/sax/lib/sax.js:620:3"

Any explanation why it worked with @JBX77, @NovaGL, @andy-81 ?

Nousemusic commented 8 years ago

To control the volume with siri via brightness: In the Version v0.0.4 of the package, has the word "volume" be replaced to "brightness" every time it appears in the index.js?

jkoehl commented 8 years ago

Just to add come more clarity and references to the above info provided...

This is from the HomeKit documentation about integrating with Siri:

(https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/HomeKitDeveloperGuide/AccessingServicesandTheirCharacteristics/AccessingServicesandTheirCharacteristics.html#//apple_ref/doc/uid/TP40015050-CH6-SW1)

"Apple-defined service types that are recognized by Siri include:

Door locks Fans Garage door openers Lights Outlets Thermostats "

What this means is the apps like Eve can see the custom characteristic that this module adds (the "Volume" characteristic). The Eve app just lists all of the characteristics that are set on the service including custom ones.

But Siri doesn't know about it since there isn't a "Speaker" service with a "Volume" characteristic that she knows about.

NovaGL commented 8 years ago

Siri doesn't care as much about the service, eg I combined a door with a motion sensor, it cares about the characteristic. Even though we named it Volume, all Siri sees is Custom.

It's up to Hardware vendors to push the Volume Characteristic via the MFI program.

I suggest people just create scenes like suggested above. Call it "Volume 50%" and then set the speaker volume to 50% in the setup. That way when you say "Volume 50%" Siri will understand it.

mattnewham commented 8 years ago

This should be added to the Readme, or at least the Wiki

keith commented 7 years ago

Here's a patch that you can apply to the current version of homebridge-sonos in order to get volume working:

diff --git i/index.js w/index.js
index 40ce2b3..fcadc75 100644
--- i/index.js
+++ w/index.js
@@ -144,7 +144,7 @@ function SonosAccessory(log, config) {

   if (!this.room) throw new Error("You must provide a config value for 'room'.");

-  this.service = new Service.Switch(this.name);
+  this.service = new Service.Lightbulb(this.name);

   this.service
     .getCharacteristic(Characteristic.On)
@@ -152,7 +152,7 @@ function SonosAccessory(log, config) {
     .on('set', this.setOn.bind(this));

   this.service
-    .addCharacteristic(VolumeCharacteristic)
+    .addCharacteristic(Characteristic.Brightness)
     .on('get', this.getVolume.bind(this))
     .on('set', this.setVolume.bind(this));

This makes HomeKit think it's a lightbulb so the Siri commands are a little strange but it seems to work as expected.

farberm commented 7 years ago

keith: Could you be more specific as to where to apply the above patch. Should I edit a specific file and which file where in the file or di I need to add a file etc. Thx

keith commented 7 years ago

If you use git apply this will "just work"

farberm commented 7 years ago

Excuse my ignorance but is that the complete terminal command. I am working on OSX?

I installed using the sudo npm install -g homebridge-sonos

aebgit commented 7 years ago

@farberm just edit the file index.js with your favourite editor.

Instead of using service Lightbulb I've got great results with service Fan. I have no fans in my house, so there is no conflict with dimmable lights in the same room when using Siri. I just renamed my Sonos speakers within the iOS 10 Home-App (from Apple) to "Musik" and moved the speakers into their rooms. Now I can control the volume via Siri with "Stelle Musik im Wohnzimmer auf 15%" ("Set music in the livingroom to 15%") .

//this.service = new Service.Switch(this.name);
this.service = new Service.Fan(this.name);

this.service
//    .addCharacteristic(VolumeCharacteristic)
    .addCharacteristic(new Characteristic.RotationSpeed())
    .on('get',  @this.getVome.bind(this))
    .on('set', this.setVolume.bind(this));

Apple lists all service types and their characteristics here: https://developer.apple.com/reference/homekit/1627282-homekit_constants

EDIT: I figured out later that it doesn't matter on which Sonos player I change the volume. Homebridge-Sonos will always only the volume ONLY for one player (I guess its the current 'master').

elmstreet commented 7 years ago

I tried NovaGL trick. It works for on of my Sonos Speakers. The Play:3. It doesn't work for the Play:5 as far as Voice Command. When using in Home app, I can control the volume with a slider. I don't understand why Siri can't work with my Play:5...

raphus commented 7 years ago

thanks so much for the volume 'mod' ! worked like a charm

markoox commented 7 years ago

He, have problems with the Volume control! Can everyone help me.

I use the eve app, and I see the Sons as a switch, I can change the volume with the app, but not with Siri. I use Siri in German.

Like: Setze Box Küche auf 50%. But Siri Don´t know what I mean.

The rest of the plugin works fine.