A Wake on Lan plugin for Homebridge
Turn your PCs, laptops, servers and more on and off through Siri
To install the plugin, head over to the machine with Homebridge set up and run the following command:
npm install -g homebridge-wol
Add your devices to your
Table of contents
To make Homebridge aware of the new plugin, you will have to add it to your configuration usually found in
/home/username/.homebridge/config.json. If the file does not exist, you can create it following the config sample. Somewhere inside that file you should see a key named
accessories. This is where you can add your computer as shown here:
For more configuration examples, please see the wiki which contains a growing collection of user-contributed guides on how to setup the plugin, Windows 10, Samba, Linux etc.: https://github.com/AlexGustafsson/homebridge-wol/wiki.
|accessory||The type of accessory - has to be "NetworkDevice"|
|name||The name of the device - used in HomeKit apps as well as Siri, default
|ip||The address or hostname of the device - used to check current status by pinging the device|
|pingInterval||Ping interval in seconds, only used if
|pingsToChange||The number of pings necessary to trigger a state change, only used if
|pingTimeout||Number of seconds to wait for pinging to finish, default
|pingCommand||Command to run in order to know if a host is up or not. If the command exits successfully (zero as the exit code) the host is considered up. If an error is thrown or the command exits with a non-zero exit code, the host is considered down|
|pingCommandTimeout||Timeout for the ping command in seconds. Use 0 (default) to disable the timeout|
|mac||The device's MAC address - used to send Magic Packets. Allows any format such as
|broadcastAddress||The broadcast address to use when sending the Wake on LAN packet|
|startCommand||Command to run in order to start the machine|
|startCommandTimeout||Timeout for the start command in seconds. Use 0 (default) to disable the timeout|
|wakeGraceTime||Number of seconds to wait after startup before checking online status and issuing the
|wakeCommand||Command to run after initial startup, useful for macOS users in need of running
|wakeCommandTimeout||Timeout for the wake command in seconds. Use 0 (default) to disable the timeout|
|shutdownCommand||Command to run in order to shut down the remote machine|
|shutdownGraceTime||Number of seconds to wait after shutdown before checking offline status, default
|shutdownCommandTimeout||Timeout for the shutdown command in seconds. Use 0 (default) to disable the timeout|
|log||Whether or not the plugin should log status messages, default
|logPinger||Whether or not the plugin should log ping messages (state transitions), default
|debugLog||Whether or not the plugin should log debug information, default
|returnEarly||Whether or not to let the plugin return early to mitigate Siri issue (see https://github.com/AlexGustafsson/homebridge-wol/issues/85). Defaults to
Whenever Homebridge starts, the plugin will check the state of all configured devices. This is done by pinging or executing the
pingCommand once, depending on the configuration. If the pinging or
pingCommand executes successfully, the device is considered online and vice versa.
The pinging by actual pings or use of the
pingCommand will continue in the background, monitoring the state of the device. If
pingsToChange (defaults to 5) pings have the same result and that result is not the current state, the state of the device will be considered changed. If
pingCommand is configured, it is used instead of actual pings and will result in an immediate state change.
This pinging will result in state changes between online and offline.
Whenever you flick a switch to its on position via HomeKit, the device is marked as "turning on". Then a WoL packet is sent to the device if a MAC address is configured and if a
startCommand is configured, it is also executed immediately. After the device has been started, it is marked as online. Then the plugin will wait for the time configured by
wakeGraceTime (defaults to 45s). If a
wakeCommand is configured, it will be called after the wait is over. Once all commands are completed, the device will be monitored again by the pinger - switching its state automatically.
Whenever you flick a switch to its off position via HomeKit, the device is immediately marked as turning off. A shutdown command is executed if it is configured. After the command's completion (or directly if none is configured), the plugin will wait for
shutdownGraceTime (defaults to 15s) before continuing to monitor the device using the configured pinging method.
Notes and FAQ
This plugin requires extra permissions due to the use of pinging and magic packages. Start Homebridge using
sudo homebridge or change capabilities accordingly (
setcap cap_net_raw=pe /path/to/bin/node). Systemd users can add the following lines to the
[Service] section of Homebridge's unit file (or create a drop-in if unit is packaged by your distro) to achieve this in a more secure way like so:
Waking an Apple computer
The Macbook configuration example uses
caffeinate in order to keep the computer alive after the initial wake-up. See this issue for more information.
Controlling a Windows PC
The Windows configuration example requires the
samba-common package to be installed on the server. If you're on Windows 10 and you're signing in with a Microsoft account, the command should use your local username instead of your Microsoft ID (e-mail). Also note that you may or may not need to run
net rpc with
SSH as wake or shutdown command
The Raspberry Pi example uses the
sshpass package to sign in on the remote host. The
-oStrictHostKeyChecking=no parameter permits any key that the host may present. This usage is heavily discouraged. You should be using SSH keys to authenticate yourself.
Secrets in the configuration
Using username and passwords in a command is heavily discouraged as this stores them in the configuration file in plaintext. Use other authentication methods or environment variables instead.
Any contribution is welcome. If you're not able to code it yourself, perhaps someone else is - so post an issue if there's anything on your mind.
This repository has evolved thanks to you. Issues reporting bugs, missing features or quirks are always a welcome method to help grow this project.
Beyond all helpful issues and wiki posts, this repository has seen modifications from these helpful contributors:
# Clone project git clone https://github.com/AlexGustafsson/homebridge-wol.git && cd homebridge-wol # Set up for development npm install && npm link # Make sure linting passes npm run lint # Try to start Homebridge with the Homebridge Config UI X - available on localhost:8080 # with default credentials admin:admin npm run test # Run Homebridge, Homebridge Config UI X and Homebridge WoL on the current maintainance node LTS version docker-compose -f integration/docker-compose.yml up --force-recreate # If you make changes to the code base, you may have to rebuild the containers before running the above command docker-compose -f integration/docker-compose.yml build
The things to look out for when running the dockerized environment is:
- Is the configuration UI working correctly? That is, is the
config.schema.jsonup to date?
- Can you interact with the accessories as expected? See the logs for full insights.
MacBook Pro is fully hooked up to simulate a real world MacBook, with proper shutdown over SSH as well as a custom ping command.
Generic accessory features regular pinging using ICMP messages over IPv4.
Localhost accessory represents the same instance as that running the Homebridge server. It features only mock configuration. It does feature the full range of configurations available, which should help debugging the configuration UI.