Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Sonos as a Speaker instead of a Light #10

Closed
jasongoldsmith opened this issue Dec 22, 2016 · 29 comments
Closed

Expose Sonos as a Speaker instead of a Light #10

jasongoldsmith opened this issue Dec 22, 2016 · 29 comments

Comments

@jasongoldsmith
Copy link

jasongoldsmith commented Dec 22, 2016

HomeKit has an accessory type of Speaker with Mute and Volume characteristics. Exposing Sonos as a light has side effects ("Siri, turn off the lights" will turn off the Sonos for example).

Exposing the Sonos as a speaker would also be more semantically correct.

Speakers are at line 3060 (approximately)

https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js

@ebaauw
Copy link
Owner

ebaauw commented Dec 22, 2016

Hi @jasongoldsmith

I currently expose a Sonos zone as a Switch service (see README), not as a Lightbulb service. I suspect you set the Type of the Switch service to Light in (one of) your HomeKit app(s). If you set it back to Switch, Siri should leave it alone dealing with your lights.
In Eve, you can specify what the Switch is Used for, including a Speaker symbol under Other. This setting is part of the Eve app, however, and not synced across devices through the HomeKit database.

I'm aware of the Speaker service and tried that one originally (before publishing homebridge-zp on GitHub). The Speaker service only contains Volume and Mute as standard characteristics, so I added On as an optional characteristic. However the iOS 10 home app doesn't support that (at least under iOS 10.1 - I haven't checked 10.2 yet). I agree that exposing Sonos as Speaker makes more sense semantically, but I don't think that's worth sacrificing being able to turn on/off the Sonos from the iOS 10 Home app.

Note to self: They have added the Speaker service and Volume and Mute characteristics to HAP-NodeJS, so I can delete the definitions for these from homebridge-zp.

@ebaauw
Copy link
Owner

ebaauw commented Dec 22, 2016

No change to iOS 10.2: Speaker service not supported by iOS Home app. Even under Eve or Home, Mute is shown as the main characteristic (at that's the only non-optional characteristic).

@NovaGL
Copy link

NovaGL commented Dec 24, 2016

Light is a much better use until Speaker is supported that means you can say set speaker to 10 and it will do the volume change easily. If someone wants that I can fork this with those changes.

@ebaauw
Copy link
Owner

ebaauw commented Dec 24, 2016

@NovaGL You'll need to use the Brightness characteristic for volume. I did that on iOS 9, before HomeKit supported the Volume and Mute characteristics. Indeed, it's übercool to have Siri change your speaker volume, and it's very annoying that she includes the Sonos when you want to interact with only the lights. Best use a config.json parameter to select Switch/Volume or Lightbulb/Brightness.

@NovaGL
Copy link

NovaGL commented Dec 24, 2016

It's not supported on the Home app so I just changed it to be a lightbulb with brightness. When Siri supports volume then it can be changed back. I don't have smart lights so it doesn't bother me.

@ebaauw
Copy link
Owner

ebaauw commented Dec 24, 2016

Changed to HAP-NodeJS characteristics in v0.1.2.

ebaauw added a commit that referenced this issue Dec 24, 2016
Added `light` parameter in config.json to expose ZonePlayer as
Lightbulb and volume as Brightness, so Siri can set the volume.
Documented parameters in README.
@ebaauw
Copy link
Owner

ebaauw commented Dec 24, 2016

Solved in v0.1.3.
Added a config.json flag light to expose zones as Lightbulbs, using Brightness for volume.

@NovaGL
Copy link

NovaGL commented Dec 25, 2016

Thanks, so would you then do. (EDITED)

  "platforms": [
    {
      "platform": "ZP",
      "name": "ZP",
      "light": true
    }
  ]

Or how would you do it? Maybe have it as service. So you can have light, speaker, switch. If not included default to switch.

Speaker should be reserved for future as its not natively supported.

@ebaauw
Copy link
Owner

ebaauw commented Dec 25, 2016

Yes, except for a missing comma and true doesn't need quotes:

"platforms": [
  {
    "platform": "ZP",
    "name": "ZP",
    "light": true
  }
]

Good point, @NovaGL , I might as well add support for Speaker. Indeed, in that case, a service parameter in config.json would make more sense, holding lightbulb, speaker, or (default) switch.

Once the iOS 10 app supports the Speaker service and Siri understands Volume, I'll default to speaker.

@NovaGL
Copy link

NovaGL commented Dec 25, 2016

Thanks, I mainly control my Sonos via https://github.com/jishi/node-sonos-http-api

That way I can launch playlists and everything much more easily. I say Hey Siri Play Today's Top Hits

@NovaGL
Copy link

NovaGL commented Dec 25, 2016

Another thing can you change model to show model name not model number?

@ebaauw
Copy link
Owner

ebaauw commented Dec 26, 2016

Technically, I could, but I don't know where to get the model name from. It doesn't seem to be returned in any of the Sonos endpoints homebridge-zp currently uses, and I cannot seem find another endpoint that includes it. @NovaGL do you know how to get the model name?

@jasongoldsmith
Copy link
Author

There is a very small number of Sonos model numbers, a lookup table should be able to map from model number to model name. A little bit fragile and requires some maintenance, but not too much effort overall.

@ebaauw
Copy link
Owner

ebaauw commented Dec 30, 2016

I found the model name is in the Player's xml/device_description.xml. I should be able to extract it from there, with a little effort upfront, but without the need to maintain manually a lookup table.

@m3lvn
Copy link

m3lvn commented Jan 4, 2017

Dear @ebaauw, first of all I would like to thank you for the clear explanations. I am relatively new to programming but I think that I have managed set up my RPI 3 the way it should.

The problem I have is that I am not able to control the Sonos system via the iOS Home app nore the Eve app. It does show the Sonos system but when I try to turn on/turn off the Sonos it comes up with an explanation mark. (The Homebridge-Nest is working fine from both the iOS Home app and Eve).

I ran the debug command and it shows that the Sonos is found, connected and even shows activity such as switching channels on Sonos (from TV to radio for example).

It also shows an IP address (192.169.0.29...etc) but I am not able to go to that address via my browser. I have forwarded all the ports on my router and I am sure that I am on the same network.

UPDATE: I am able to control volume and source from the EVE app, but I can't turn on/turn off the Sonos. That's probably also why I am not able to control that from the iOS Home app.

Any ideas what could be wrong?

Thanks,
Melvin

@ebaauw
Copy link
Owner

ebaauw commented Jan 4, 2017

Hi Melvin, @m3lvn

I'm not entirely sure what's going on. Could you please capture the full debug output (see Troubleshooting in the README) and attach that here?

As I understand, homebridge-zp and your Sonos seem to have found each other, as you can control volume from Eve. When you change the volume using the Sonos physical +/- buttons or the Sonos app, is that reflected in Eve? Indeed the Home app doesn't support volume, nor mute, nor track, so you can only use the on/off control from that app to play/pause the Sonos.

As you mention TV, I assume you have a PlayBar? Note that the PlayBar doesn't accept play/pause when its on TV input - the controls are disabled in the Sonos app, but I have yet to find a way to do that in homebridge-zp. See also issue #12. Can you control the PlayBar if you switch to another input source using the Sonos app?

@leoneleone
Copy link

@ebaauw

My opinion is that Sonos Speakers should be exposed as a HomeKit Speaker (Service), with added:

  1. Characteristic.Brightness - which would be a duplicate of Characteristic.Volume - so that we can control volume(brightness) via Siri Commands "set the living room speaker to 70", etc. only until Siri supports control of HomeKit Speakers officially with voice commands for Characteristic.Volume and Characteristic.Mute
  2. Characteristic.On - so than Siri (On/Off) Commands work as well.

So what you would see in Eve app for example:
Power On/Off - mapped to Sonos play/stop
Brightness - mapped to Sonos volume
Volume - mapped to Sonos volume
Mute - mapped to Sonos pause/play (or mute if Sonos supports this - I'm not sure)

Apple's Home app would only show its Speaker icon with NO on-screen controls for brightness/volume, but at least we would have Siri Voice Command control for volume(brightness) and on/off functions.

I do like the current exposure as HomeKit Switches and I do use Home app Switches to turn Sonos Speakers (HomeKit Switches) on and off sometimes, but not often enough. I can live without having on-screen controls in Home app if Siri Commands still work (Brightness + On/Off). This just personal taste of course.

Has anyone tried adding Characteristic.On to a HomeKit Speaker Service before? I wonder if Home app would at least give you on-screen capabilities to turn a Speaker Service On/Off by tapping the icon..?

@ebaauw
Copy link
Owner

ebaauw commented Jan 5, 2017

Hi @leoneleone
That brilliant, using both Volume and Brightness simultaneously! No config.json parameter needed.

I did try adding On to a Speaker service. This kills the play/pause control from the iOS builtin Home app. In Eve, in the room view, it shows Mute instead of Power. For me, those are dealbreakers. Using a Lightbulb service gives both play/pause and volume control in the builtin Home app, but causes Siri to treat the Sonos as one of your lights, also a dealbreaker. So I was left with Switch. I haven't tried Brightness on a Switch (or any other service than Lightbulb) yet, but I think that could work. Otherwise, we keep a parameter in config.json, to cater for personal taste.

Sonos does support mute - that's what homebridge-zp uses for Mute.

Note that the HomeKit Speaker service is meant for doorbells: Mute is a mandatory characteristic, and the only standard optional characteristic is Volume. It might be a long time before Siri handles Volume.

@m3lvn
Copy link

m3lvn commented Jan 5, 2017

Hi @ebaauw, thanks for your comments! I will try to see if I can control the Sonos in case I switch to another input. I will run a debug report when I am back home tonight.

PS: not sure if this is the place to ask but is there an easy guide/manual to setup homebridge-zp so that I can ask Siri to play a certain track or playlist?

@ebaauw
Copy link
Owner

ebaauw commented Jan 5, 2017

OK, I did some extensive testing with different service/characteristic combinations:

  • Lightbulb/Brightness: Home app: on/off and volume; Siri: on/off and volume;
  • Switch/Brightness: Home app: on/off; Siri on/off and volume. It doesn't matter whether the Switch type is set to Switch or Light;
  • Switch/Volume: Home app: on/off; Siri: on/off;
  • Speaker/Volume: Home app: no support; Siri: on/off;
  • Speaker/Brightness: Home app: no support; Siri: on/off and volume;
  • Fan/RotationSpeed: Home app: on/off and volume; Siri: on/off and volume. I forgot all about Fan/RotationSpeed. I used that long ago for homebridge-music my pre-Sonos iTunes homebridge plugin (which I never published on GitHub);
  • Lightbulb/(any): Siri includes the Sonos when you set the room lights;
  • Switch/(any): When Type is set to Light, Siri includes the Sonos when you set the room lights;
  • Speaker/(any): The main characteristic is Mute; in Eve, this characteristic is shown in the room view instead of on/off.

Conclusions

  • If you want volume control in Siri and builtin Home app, Fan/Rotation is the best choice (better than Lightbulb/Brightness), but semantically insane;
  • If you want correct semantics, Speaker/Volume is the best choice, but no built-in Home app support and no volume support in Siri;
  • Other combinations are compromises between correct semantics and full functionality. Until Apple supports speakers and volume control in the built-in Home app and in Siri, there's no solution that offers all functionality in a semantically correct way.

Next Steps
I'll create config.json parameters:

  • "service", which will take values "switch" for Switch/Volume (default); "fan" for Fan/RotationSpeed; "speaker" for Speaker/Volume; "light" for LightBulb/Brightness;
  • "brightness", which will take values true and false (default). When set, it adds Brightness to Switch or Speaker (in addition to Volume).

@leoneleone @NovaGL @jasongoldsmith , please let me know what you think.

@ebaauw
Copy link
Owner

ebaauw commented Jan 5, 2017

@m3lvn Currently, there's no way to select a music source in homebridge-zp (see issue #8). Even if there were, it would be through custom characteristics, which Siri won't understand.

My approach would be:

  • To use Siri to control the built-in music app on your AppleTV, connected (through your TV to) a Sonos PlayBar;
  • To use Siri to control the built-in music app on iOS or iTunes on macOS, sending the music to your AppleTV over Airplay, with the AppleTV connected to the PlayBar;
  • As before, but now sending the music to another AirPlay device, connected to the line-in of a Play:5 or Sonos Connect (see http://www.sonos.com/en/airplay). I actually have my macOS server line-out connected to a Sonos Connect line-in and use AirFoil to make my macOS server appear as an AirPlay speaker (see https://rogueamoeba.com/airfoil/. The connect is set to switch to line-in automatically when it detects a signal.

@NovaGL I took a look at node-sonos-http-api, but I don't understand how that enables you to launch your playlist from Siri. Can you please shed light on your setup?

@NovaGL
Copy link

NovaGL commented Jan 6, 2017

I am confused why you would want to use fan as a service.

I am personally happy with light but I don't have other smart lights.

@ebaauw The HTTP API is just that an API, it is up to you how you use it.

I have mapped buttons to the favourites it then switches to to that favourite when telling that switch to turn on.

ebaauw added a commit that referenced this issue Jan 6, 2017
- Explicit grouping/ungrouping control (issue #3);
- Group volume and mute control (issue #4);
- Allow different combinations of HomeKit service and characteristic
for volume (issue #10);
- Bumped dependency to [email protected] (issue
bencevans/node-sonos#152).
@ebaauw
Copy link
Owner

ebaauw commented Jan 6, 2017

v0.1.4 - @leoneleone @NovaGL @jasongoldsmith please let me know if this works for you.
Note that, contrary to what I proposed earlier, setting "brightness": true in config.json replaces Volume with Brightness for Switch or Speaker rather than adding it.

@NovaGL: using Fan and Rotation Speed enables volume control in Siri and play/pause and volume control in the iOS built-in Home app, just like using LightBulb and Brightness, but without Siri including the Sonos in the lights. I suppose it's really a matter of taste, hence the multiple options through config.json.

@leoneleone
Copy link

@ebaauw
I will test this on Monday when I have a chance. Replacing Volume with Brightness (rather than adding it) sounds good to me. In practice, one would only use one or the other - no real need for both.
Personally, I prefer turning a Sonos Speaker (HomeKit Switch- Characteristic.On) using Siri Commands and have that "Stop" rather than "Pause" the Sonos Speaker. I'll stick to HomeKit Switches until Siri can handle a Speaker Mute command 🙂

ebaauw added a commit that referenced this issue Jan 7, 2017
Ensure consistency after issue #10 and issue #7.
@ebaauw
Copy link
Owner

ebaauw commented Jan 7, 2017

Some cleanup and enhancements in v0.1.5. @leoneleone please test this version.

  • The service for the group is now called Sonos, e.g. Living Room Sonos;
  • The optional service for the zone is now called Speakers, e.g. Living Room Speakers;
  • The config.json setting to enable the optional Speakers service is: "speakers": true;
  • Added support for Bass, Treble, and Loudness (issue Support EQ functions #7) to the optional Speakers service;
  • Changed "pause" to "stop" in the README. homebridge-zp actually issues a stop command to Sonos. The Sonos app displays a Pause symbol when playing a playlist and a Stop symbol otherwise, but seems to issue the same stop command in both cases;
  • Adjusted README and log messages accordingly.

@ebaauw
Copy link
Owner

ebaauw commented Jan 12, 2017

@leoneleone , please see pull request #13 for new info on stop vs pause.

@suxus-zz
Copy link

Hello

I will use the plugin with fan to control the volume, but i don't know whats the right setting for the config.

"platforms": [
{
"platform": "ZP",
"service": "fan",
"brightness": true,
"speakers": false
}
]

Is this right, i don't know i read something from rotation speed but where is the setting for that?

I hope you can help me.

regards

@ebaauw
Copy link
Owner

ebaauw commented Feb 25, 2019

The ”service”: “fan” setting uses Rotation Speed for volume. Just don’t include ”brightness”.

@ebaauw
Copy link
Owner

ebaauw commented May 31, 2019

Another thing can you change model to show model name not model number?

I found the model name is in the Player's xml/device_description.xml. I should be able to extract it from there, with a little effort upfront, but without the need to maintain manually a lookup table.

In 71397d1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants