[Unifi][Feature request] Power cycle Poe devices

Hi, this is just a feature request for being able to power cycle Poe connected devices to the unifi poe switch.
Dissable/enable a port would also be a great feature addition.

1 Like

Put up a bounty on bountysource to encourage a volunteer developer to implement this.

1 Like

Hi, I needed this to reboot some devices at specific times, and this is how I solved it using this reverse engineered api (https://ubntwiki.com/products/software/unifi-controller/api).

Create a button with an exec addon with the following command. In bold the parts that you have to replace to make it work for your case:

curl -d “{\“username\”: \“login\”,\“password\”: \“password\”}” --head -c /tmp/cookie.txt -k “https://unifi_controller_ip:9443/api/login” ; curl -d “{\“cmd\”:\“power-cycle\”,\“mac\”:\“switch_mac_address\”,\“port_idx\”:\“port_to_power_cycle\”}” -b /tmp/cookie.txt -k “https://unifi_controller_ip:9443/api/s/site_name/cmd/devmgr”

I left “9443” as the port for the unfi controller as it is the default one, but it could be different.
The “site_name” is “default” if you did not change it.


Thanks for posting a way to get a Power Cylce of a Unifi switch port.
I was looking for this. Unfortunality I get errors when I try to run this ( I filled in the bold parts with my credentials )
See the error below.

Warning: You can only select one HTTP request method! You asked for both POST
Warning: (-d, --data) and HEAD (-I, --head).
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) Failed to convert “https to ACE; string contains a disallowed character

Have you got this running on a Pi with Openhabian ? Or an other linux distro ?
Hope you can help me with this. I have tried it just from command line, not a EXEC binding button yet.


Hi, I think that the problem is that you copied and pasted from the post. I don’t know why by the quotes are not normal quotes here in the post. If I copy the command from my post into a terminal I get some strange quotes. Try typing the whole command, or at least replace all the quotes and backslash and forwardslash by characters typed by you in the terminal itself. Your command should look exactly like it looks in the post, but type it yourself.

They are actually 2 commands. One to get the cookie with the credentials and another one to actually do the reboot. Try the first one first.
curl -d "{\"username\":\"login\",\"password\":\"password\"}" --head -c /tmp/cookie.txt -k "https://unifi_controller_ip:9443/api/login" ;

And once this works try the second one

curl -d "{\"cmd\":\"power-cycle\",\"mac\":\"switch_mac_address\",\"port_idx\":\"port_to_power_cycle\"}" -b /tmp/cookie.txt -k "https://unifi_controller_ip:9443/api/s/site_name/cmd/devmgr"

Now I put the commands as code so hopefully they dont have strange characters but I cannot put bold in code formated text.

Thanks for your answer, unfortunately it still doesn’t work.
I have typed to command instead of copy paste. When run de first command I get the following message ( same as before, only a parts as the command is now split in 2 parts ).

Warning: You can only select one HTTP request method! You asked for both POST
Warning: (-d, --data) and HEAD (-I, --head).

I have no idea why, it seems like its been interpreted as 2 different request in 1 go.

I have googled a around to find some more info about the POE port toggle of a Unifi switch.
And hopefully find some more info why your command isn’t working for me.

But I found an other way to do it with SSH, and this one is working for me. It sends the reboot command direct to the switch.

sshpass -p password ssh login@switch_ip '(echo "enable" ; echo "configure" ; echo "interface 0/port_number" ; echo "poe opmode shutdown" ; echo  "poe opmode auto" ; echo "exit" ; echo "exit"; echo "exit"  ) | telnet localhost 23 ; exit;'

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.