Skip to content

Commit

Permalink
made mapMaxVolumeTo100 an option, fixed volume calculations, fake pow…
Browse files Browse the repository at this point in the history
…er state defaults to on so that brightness will update in Home app
  • Loading branch information
robertvorthman committed Dec 4, 2016
1 parent 6fe6286 commit b80ad30
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
29 changes: 25 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,23 @@ iOS 10 adds HomeKit shortcuts to the iOS Control Center, so you can adjust the v

# Configuration

Add the plugin as an accessory to have it control the main zone for your AVR. If your receiver supports a 2nd zone, add
Add as an accessory by editing the homebridge config.json file.

## Simple Example

```
"accessories": [
{
"accessory": "marantz-volume",
"name": "Stereo Volume",
"host": "192.168.1.15"
}
]
```

## Multiple Zones Example

If your receiver supports a 2nd zone, add
the plugin a second time with `"zone":2` in the accessory properties, the same host, and a different name.

Configuration sample:
Expand All @@ -63,13 +79,18 @@ Configuration sample:
]
```

In this example, the receiver has two zones, the volume control works for both zones (named "Stereo Volume" and "Outside Volume"),
In the above example, the receiver has two zones, the volume control works for both zones (named "Stereo Volume" and "Outside Volume"),
and the power control works is ignored for the main zone and is enabled for the second zone.

## Additional Configuration Details

The option `maxVolume` defaults to 70 unless otherwise specified as a values between 0 and 100.

Setting `"mapMaxVolumeTo100":true` will remap the volume percentages that appear in the Home app so that the configured maxVolume will appear as 100% in the Home app. For example, if the maxVolume is 70%, then setting the stereo volume brightness to 50% would set the receiver's volume to 35%. Adjusting the stereo volume knob to 70 will appear as 100% brightness in the Home app. This option could confuse some users to it defaults to off `false`, but it does give the user finer volume control especially when sliding the brightness slider up and down in the Home app.

# Special Thanks
This plugin was built upon code from the following homebridge plugins

https://www.npmjs.com/package/homebridge-fakebulb by schemish

https://www.npmjs.com/package/homebridge-denon by stfnhmplr
https://www.npmjs.com/package/homebridge-denon by stfnhmplr
27 changes: 21 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function ReceiverVolume(log, config) {
this.zoneName = this.zone === 1 ? "MainZone" : "Zone2";

if (!this.controlPower) {
this.fakePowerState = 0;
this.fakePowerState = 1; //default to on so that brightness will update in HomeKit apps
}
}

Expand Down Expand Up @@ -94,10 +94,11 @@ ReceiverVolume.prototype.setPowerOn = function(powerOn, callback) {
ReceiverVolume.prototype.setBrightness = function(newLevel, callback) {

if(this.mapMaxVolumeTo100){
var volumeMultiplier = 98/this.maxVolume; //Denon/Marantz percentage maxes at 98 in receiver settings
var volumeMultiplier = this.maxVolume/100;
var newVolume = volumeMultiplier * newLevel;
}else{
var newVolume = Math.max(newLevel, this.maxVolume);
//cap to max volume set in homebridge config.json
var newVolume = Math.min(newLevel, this.maxVolume);
}

//cap newVolume. //Denon/Marantz percentage maxes at 98 in receiver settings
Expand All @@ -110,14 +111,28 @@ ReceiverVolume.prototype.setBrightness = function(newLevel, callback) {

//cap between -80 and 0
relativeVolume = Math.max(-80.0, Math.min(0.0, relativeVolume));

this.setControl('Volume', relativeVolume, callback);
}

ReceiverVolume.prototype.getBrightness = function(callback) {
this.getStatus(function(status) {
var volume = -status.MasterVolume[0].value[0] / 80.0 * 100.0;
callback(null, volume);

if(status){
var volume = parseInt(status.MasterVolume[0].value[0]) + 80;
this.log("Get receiver volume %s ", volume);

if(this.mapMaxVolumeTo100){
volume = volume * (100/this.maxVolume);
}


callback(null, volume);
}else{
this.log("Unable to get receiver status");
callback(null);
}

}.bind(this));
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-marantz-volume",
"version": "1.2.2",
"version": "1.3.0",
"description": "Homebridge plugin to control Denon or Marantz receiver volume with Siri commands",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit b80ad30

Please sign in to comment.