Thomas De Reyck's Blog

Turning off Unifi switch ports via SSH

I’m using a UniFi 24-port PoE switch as a core switch for my home network. Via PoE, it supplies power to a number of access points in my home. However, some of those access points are not always in use, e.g. at night. By turning off the PoE power via telnet, and scheduling this as a cron job, power can be turned off automatically using the following command:

echo '{
echo enable
sleep 1
echo configure
sleep 1 
echo "interface 0/7"
sleep 1
echo poe opmode shutdown
echo exit
sleep 1
echo exit
sleep 1
echo exit
} | telnet localhost' | ssh admin@switch.home.arpa 'sh -s'

A similar command can be used to turn the PoE on the port on again:

echo '{
echo enable
sleep 1
echo configure
sleep 1 
echo "interface 0/7"
sleep 1
echo poe opmode auto
echo exit
sleep 1
echo exit
sleep 1
echo exit
} | telnet localhost' | ssh admin@switch.home.arpa 'sh -s'

Before this works, you will also need to set up SSH public-key authentication so you can connect to the switch using SSH without entering a password.

#UniFi #Power Saving