[Tutorial] Wake up a client on another network via Home Assistant (RestAPI)

Started by balrog, March 15, 2026, 11:51:09 AM

Previous topic - Next topic
Introduction

With ISC DHCP, it was possible to set up WoL over routed networks using a NAT workaround. However, since ISC DHCP is deprecated, and tools like Dnsmasq or KEA DHCP do not offer an option for "fake" ARP entries, and solutions such as defining the MAC address via Neighbors did not work for me (presumably due to CARP), this guide describes a solution for setting up WoL using OPNsense's built-in API. In this example, the "Magic Packet" is sent via Home Assistant.

OPNsense
1. Install the plugin
The os-wol plugin is required for this solution. Simply installing it is sufficient; no configuration is needed here.


2. Create a user
A user must be created for API access. You can choose the name yourself.
Under Privileges, select the service we just installed: Service: Wake on LAN
Then save.


3. Create API Key
We create the API key pair by clicking this icon. This downloads the key pair to a .txt file.


4. Extract Network Identifier
In the script later on, we'll specify which network the client to be woken up is on. To do this, we need to note down the identifier of the interface. In my case: lan


Home Assistant

I'm going to create a button in Home Assistant that I'll use to wake up the client. To do this, the following must be entered in the Home Assistant YAML configuration. I've moved "templates" to a separate file called template.yaml, which is why I have the following line in my configuration.yaml:
template: !include template.yaml

1. configuration.yaml
Insert the following block and adjust it according to the comments. For payload: make sure the identifier of the OPNsense interface is included:
rest_command:
  opnsense_wake_client:
    url: "https://x.x.x.x:xxx/api/wol/wol/set" # actual IP and Port of the OPNsense WebGUI
    method: POST
    username: "Kc/vYhlWU/K4fS3N3vhyKJ1234oxwg2adbDtVJZLZwL2k5QhhmxhLa/mxxI4LNhqKyZougxnSMnHWiA6" # key from the txt
    password: "Yz/7A1lTzSi+I4XXWMMrV1234FlwIwFZsowocpAH1r7dfBHRAGZLVk7aSBX2/n5tg4cwKaEmeV9GJIuS" # secret from the txt
    content_type: "application/json"
    payload: '{"wake":{"interface":"lan","mac":"AA:BB:CC:DD:EE:FF"}}' # interface=identifier, mac=MAC-Address of the client
    verify_ssl: false # when you use the default self-signed cert from OPNsense

2. template.yaml
Insert the following block into template.yaml:
- button:
  - name: "WoL Client"
    press:
      - action: rest_command.opnsense_wake_client


3. Restart Home Assistant
For me, simply loading the YAML config wasn't enough, so I had to restart Home Assistant


4. Add a button
Now you can create a button on the dashboard and select "WoL Client" as the entity.

NOFI but having to run Home Assistant to do this would not be my choice at all no matter how bad I would need this feature :

After having heard from people that it does some kind of weird annoying scanning of your network the whole time that basically works like a huge "flood" in your network it officially landed on my "Software Blacklist" so to speak !!

I think it would be better if OPNsense offered a feature for this like my old DrayTek Router did with a small "WoL webGUI section" put away together with all the Diagnostic Tools for example :)
Weird guy who likes everything Linux and *BSD on PC/Laptop/Tablet/Mobile and funny little ARM based boards :)

I see your point about Home Assistant, but since I already use it for my home automation anyway—and many others do too—this guide might be helpful for them.

If you don't use Home Assistant, you can access the API directly via curl (Linux) or PowerShell (Windows).

And WoL can be executed directly through the installed WoL plugin. Personally, though, I don't want to have to go through the OPNsense firewall every time I want to wake up a PC. That's why I included the steps in the guide.