Schedule switch‑port enable / disable on Ubiquiti Dream Machine devices (UDM, UDM‑Pro, UDM‑SE, etc.)
Please be aware this is entirely untested and it is created as a proposed solution to the issues reported with the UI wifi scheduling, with potential other applications.
Perhaps: Handy for parents, school labs, or anyone who wants time‑based control over PoE ports and the devices plugged into them — Wi‑Fi access points, cameras, switches, and more.
| File | Description |
|---|---|
port-scheduler.sh |
Main script — enables or disables a list of switch ports via the UniFi controller API. |
find-devices.sh |
Helper script — discovers all switches on your UniFi network and lists every port with its config key. |
UDM-Port-Scheduler-Guide.pdf |
Step‑by‑step PDF guide covering setup, configuration, cron scheduling, and troubleshooting. |
curl -sL https://raw.githubusercontent.com/Sparrhawk/ubiquiti-tools/main/port-scheduler.sh -o /root/port-scheduler.sh
curl -sL https://raw.githubusercontent.com/Sparrhawk/ubiquiti-tools/main/find-devices.sh -o /root/find-devices.sh
chmod +x /root/port-scheduler.sh /root/find-devices.shEdit the credentials at the top of find-devices.sh, then run:
./find-devices.shYou'll see a table like this:
Device: Office Switch
MAC: aa:bb:cc:dd:ee:ff
Ports:
# Name Speed PoE Enabled Config Key
------------------------------------------------------------------------------------
1 Port 1 1000M auto True aa:bb:cc:dd:ee:ff:1
2 Port 2 1000M auto True aa:bb:cc:dd:ee:ff:2
Open the script and set your controller credentials plus the ports you want to control:
CONTROLLER="https://localhost"
USERNAME="admin"
PASSWORD="your_password_here"
SITE="default"
PORTS=(
"aa:bb:cc:dd:ee:ff:1"
"aa:bb:cc:dd:ee:ff:2"
)./port-scheduler.sh disable # Turn ports OFF
./port-scheduler.sh enable # Turn ports back ONAdd entries to your UDM's crontab (crontab -e):
# Disable ports at 9pm every night
0 21 * * * /root/port-scheduler.sh disable >> /root/port-scheduler.log 2>&1
# Re-enable ports at 7am every morning
0 7 * * * /root/port-scheduler.sh enable >> /root/port-scheduler.log 2>&1For detailed instructions — including SSH access, surviving firmware updates, and troubleshooting — see the UDM Port Scheduler Guide (PDF).
- Ubiquiti Dream Machine (any model running UniFi OS 3.x+)
- SSH access to the UDM
- A local admin account (not a UniFi cloud / SSO account)
curlandpython3(both pre‑installed on UniFi OS)
- Credentials are stored in plain text inside the scripts. Restrict file permissions:
chmod 700 /root/port-scheduler.sh /root/find-devices.sh
- Use a dedicated local‑only admin account with a strong password.
- The scripts communicate over
https://localhostso traffic never leaves the device.
This project is provided as‑is under the MIT License. Use at your own risk.
Pull requests and issues are welcome! If you've adapted this for a different UniFi device or OS version, please share your experience.