JosephDuffy / homebridge-pc-volume

Homebridge plugin to control your computer's volume using HomeKit and Siri
MIT License
59 stars 8 forks source link
computer-volume home-automation homebridge homekit

homebridge-pc-volume

Verified by Homebridge Tests Status codecov npm version

homebridge-pc-volume is a Homebridge plugin that adds a support for changing a computer's volume using HomeKit and Siri.

OS Support

homebridge-pc-volume utilises node-loudness, which currently supports macOS, Linux (using ALSA), and Windows. Windows may need OpenSSL to be installed; it is required when being run on CI, which installs the latest 64-bit not-light 1.0.2 build avialable from https://slproweb.com/products/Win32OpenSSL.html. I have not personally tested this project on Linux or Windows.

Installation

First, install Homebridge.

Then install homebridge-pc-volume via npm:

npm install -g homebridge-pc-volume

homebridge-pc-volume will also need to be specified as an accessory in your ~/.homebridge/config.json:

{
  // Other keys here...
  "accessories": [
    {
      "accessory": "ComputerSpeakers",
      "name": "MacBook"
    }
  ]
}

Note that accessory must be "ComputerSpeakers", while the name can be any value of your choosing.

Configuration

When the property logarithmic is set to true the volume will be scaled logarithmically+from+x%3D0+to+100).

The services property can be used to decide how your computer's speaker will be exposed: as a lightbulb, fan, speaker, or a combination of all 3.

Please note that while iOS 11 supports "HomeKit speakers" this appears to actually be via AirPlay 2, so the "speaker" option is unlikely to work!

If no services key is provided a lightbulb will be exposed.

Lightbulb Only (default, implicit)

  "accessories": [
    {
      "accessory": "ComputerSpeakers",
      "name": "MacBook"
    }
  ]

Lightbulb Only (default prior to 1.1)

  "accessories": [
    {
      "accessory": "ComputerSpeakers",
      "name": "MacBook",
      "services": ["lightbulb"]
    }
  ]

Fan Only

  "accessories": [
    {
      "accessory": "ComputerSpeakers",
      "name": "MacBook",
      "services": ["fan"]
    }
  ]

Speaker and Fan

  "accessories": [
    {
      "accessory": "ComputerSpeakers",
      "name": "MacBook",
      "services": ["speaker", "fan"]
    }
  ]

Volume Buttons

Buttons can be exposed that will increase or decrease the system volume by a set percentage. These services are called increase-button and decrease-button. switchVolumeDelta can be provided to change the default percentage change of 5%. switchDelay controls the delay in ms between the switch being turned on and turned back off. Without a delay the Home app will not display the change. Defaults to 10.

  "accessories": [
    {
      "accessory": "ComputerSpeakers",
      "name": "MacBook",
      "services": ["fan", "increase-button", "decrease-button"],
      "switchVolumeDelta": 10,
      "switchDelay": 100
    }
  ]

Initial Values

If you wish to set some initial values when the plugin starts you can set the initialVolume and initiallyMuted properties:

  "accessories": [
    {
      "accessory": "ComputerSpeakers",
      "name": "MacBook",
      "initialVolume": 70,
      "initiallyMuted": true
    }
  ]

Development

To develop homebridge-pc-volume locally:

  1. Clone the project
  2. Run npm install
  3. Run npm run build
  4. Run npm install --global $(pwd)

This will allow homebridge to find your local version of homebridge-pc-volume. After making changes you will need to restart homebridge.

You may also stop any homebridge instance you already have running and run yarn build:watch:debug, which will start homebridge, and automatically restart it when a source file is updated. This instance of homebridge uses the .homebridge-debug/config.json config file.