Skip to main content

A Wake on LAN Switch implementation for HomeKit

Project description

HomeKit Wake on LAN [Python]

A hap-python based implementation of HomeKit Switch Accessory to send Wake on LAN magic packets to turn your machines on.

Turning the Switch On will result sending a WoL magic packet to the target.

The state of the Switch is regulary updated, it will eventually turn off if the machine is not reachable, and turn back on, if the machine can be pinged.

You can however manually turn it Off and On again, to trigger a WoL packet, and optionally refresh the stored IP address of the target (that is used for pings).

Requirements

Requires at least Python 3.6. Uses hap-python for HomeKit integration, click for command line, pyyaml for configuration, pywol for sending the Wake on LAN packet, and scapy to get IP address from MAC, and ping.

Installation

You can use pip to install the package.

> pip install pyhapwol

Alternatively, check out the source code, and install it locally, or install the dependencies and use

> python -m pyhapwol

Command Line Options

After installation, the pyhapwol script should be available. (You can also fallback to python -m pyhapwol)

> pyhapwol --help
Usage: pyhapwol [OPTIONS]

  Start HomeKit Server with specified configuration and state file.

Options:
  -c, --config TEXT    Configuration file to use.  [default: config.yaml]
  -s, --state TEXT     HomeKit State file for persistence.  [default:
                       homekit.state]
  -d, --debug BOOLEAN  Debug messages.
  --help               Show this message and exit.

Configuration

The configuration is a YAML file:

- name: Server Name
  mac: a0:b1:c2:d3:e4:f5
  broadcast: 192.168.0.1/24
  # The following values are optional:
  ip: 192.168.0.123
  interface: eth0
  port: 9
- name: Other Server
  mac: f0:e1:d2:c3:b4:a5
  broadcast: 192.168.0.0/24

The name will act as a default name for the Switch Accessory.

The mac is the mandatory MAC (hardware) address of the network interface you want to wake up.

The broadcast is used to resolve the broadcast address of your subnet. You can use an IP address of the subnet, and the netmask. This is passed to pywol.

Optional ip can be used in case of fix (or DHCP reserved) addresses. If it is omitted, scapy is used to determine the IP address. In case it is not provided, the IP will be "forgotten" when the switch is turned off, and re-evaluated when it is turned on again.

Optional interface is the network interface to use by scapy in the machine running pyhapwol.

Optional port is the port to send the magic packet to. Default value is 9.

Caveats

Only IPv4 addresses are supported. You will need root privileges for scapy to send and receive packets to determine the IP from the given MAC address, or to ping the target machine for liveness check.

Running With Docker

You can build a docker image with

> docker build -t pyhapwol:latest .

And run it as

> docker run \
  --restart unless-stopped \
  --log-opt max-size=10m \
  --log-opt max-file=3 \
  --network host \
  --volume $PWD/config.yaml:/opt/wol/config.yaml:ro \
  --volume $PWD/homekit.state:/opt/wol/homekit.state \
  pyhapwol:latest

Note that it takes some time to compile the cryptography dependency in an ARMv7 Raspberry Pi, or similar.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhapwol-1.0.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhapwol-1.0.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pyhapwol-1.0.2.tar.gz.

File metadata

  • Download URL: pyhapwol-1.0.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for pyhapwol-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a62f85abc854d45bb905595c7d22d1901db5bf668c32e563dcb4b4e3832992c0
MD5 f59213699457596c2f0edf431d85946a
BLAKE2b-256 120975509a9c9eb23c8920d019e1db53c2e798ee9bc0c2dab5f16068c52dde50

See more details on using hashes here.

File details

Details for the file pyhapwol-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyhapwol-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for pyhapwol-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19aa6c55b2b9fad5ef5567a6aa9af046f548110b21d806f191c0b8d3f2746fcf
MD5 e18ca394214442e0d1a21ccdce5864ab
BLAKE2b-256 95f4a82cc466564028053692bc335e351b2644616bf2d1c494f2d677e1929a99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page