Unifi Switches POE control

There is no technical issue here AFAIK. It has just not been priorirized.

Are you sure because the documentation states that this isnā€™t yet supported by this integration. Or did you mean that it is possible from the UniFi Controller side and you switched it off there?

He means it is possible, not that the integration supports it

1 Like

Thanks @Robban - judging by the matching image on the GitHub commits you are the most active contributor so many thanks for your work on this. I was just using my very rudimentary understanding of the controller responses and your code which looked like youā€™d have to handle network infrastructure differently rather than it not be possible.

The ability to disable access points using poe on their upstream switches definitely has some utility if you get a chance to look at it.

1 Like

Thanks!

I have been rewriting the whole of the UniFi integration to improve maintainability so it will be easier to add new stuff like this in the future.

Any updates on this? I would like to control POE to a Unifi device.

I have not. After spending so much time on Unifi Iā€™ve focused my energy ok the Axis integration

no problem, thanks for the update.

Could someone point me to the API documentation on how to enable/disable PoE on ports. Since this is not supported by the UniFi integration I would like to investigate if itā€™s possible to do this outside the integration, for instance with curl.

(Iā€™d like to switch of some PoE connected access points when Iā€™m not at home)

Just for reference for other people, here are the details on how itā€™s done. Perhaps itā€™s also useful to @Robban as well when he finds time to include this in the UniFi integration. The sequence looks like this:

  • log into the UniFi controller
  • get the sites registered under the controller with the endpoint: /api/stat/sites
  • get the mac address and device id from the switch you want to control using the sites object retrieved in the previous step
  • get the device settings from using the sites object and mac address with endpoint /api/s/<site>/stat/device/<device_mac>
  • extract the port_overrides settings object from the device settings retrieved in the previous step and update the poe_mode from the port(s) you wish to change
  • update the device settings using the endpoint /api/s/<site>/rest/device/<device_id> and the updated port_overrides settings object as payload (this is a PUT request).
  • log out of the controller

So this way you can activate/deactivate POE of any port using some ssh commands from home assistant ? :slight_smile:

Youā€™d have to use curl requests instead of SSH. And you should save the cookie which is returned from the login request using --cookie-jar so you can use it with the other requests. But yeah, you should be able to do all that using Home Assistant.

2 Likes

Thks,

Iā€™ll definitely try that for my POE cams !

The integration already created poe switches for network clients powered by poe. He means controlling poe for unifi devices powered by poe

Exactly.

@Shaad, if all you need to achieve is to switch PoE connected devices (like PoE cameras) that are not part of the infrastructure (like access points) you can just use this integration and the switches it creates within HA. No need to mess around with curl requests.

Just throwing in my solution to control PoE powered fans in my network cabinet.

This is where Iā€™m coming from: My network cabinet houses all my central network equipment (DSL modem, router, Synology NAS, HomeAssistant on Raspberry Pi 4, UPS, Unifi PoE switch, Unifi AP). I want to control two 120mm fans to only run when temperatures rise above a certain level, and implement a ā€œnight modeā€ where fans remain off.

I took two standard case fans (Arctic F12 Silent), removed the three pin socket and used a 12V screw terminal to add them to an active 802.3af PoE splitter. Because obviously thereā€™s no network client attached to the PoE port Iā€™m using to power the fans, Iā€™m unable to use the current implementation from @Robban to switch the PoE port from the Unifi switch.

To sum up my hardware setup:
Unifi switch port #8 --> LAN cable --> PoE splitter --> 12V screw terminal (+/-) --> two fans (connected in parallel)

Now, to control the PoE port from Home Assistant, Iā€™m using a SSH connection. I followed these steps to set it up:

  • install ā€œSSH & Web Terminalā€ from the Add-on store in Home Assistant
  • from the plugin terminal, run ssh-keygen and save the private/public key in /config/ssh (this is important because scripts are unable to access the plugins data directory)
  • enable SSH access in the Unifi controller and add the generated public key as a new authorized key
  • create two bash scripts fan_on.sh and fan_off.sh, make them executable (contents below)
  • in Home Assistant configuration, add shell_command configuration for those scripts
  • use in automations :slight_smile:

Bash scripts (input taken from https://community.ui.com/questions/SSH-command-to-remotely-turn-off-poe-port-power/77189cb1-9222-40db-9f13-20b88d399329):

fan_on.sh

#!/bin/bash
ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] '(echo "enable" ; echo "configure" ; echo "interface 0/8" ; echo "poe opmode auto" ; echo "exit" ; echo "exit" ; echo "exit")  | telnet localhost ; exit;'

fan_off.sh

#!/bin/bash
ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] '(echo "enable" ; echo "configure" ; echo "interface 0/8" ; echo "poe opmode shutdown" ; echo "exit" ; echo "exit" ; echo "exit")  | telnet localhost ; exit;'

I have two input booleans in Home Assistant - one to toggle the fans on/off (manually or via automations by temperatures above/below thresholds), and one to toggle night mode (when active, switching off the fans during the night and disabling any automations that might start the fans).

I guess this solution could also be adapted to switch the power of Ubiquiti infrastructure devices, maybe this will be helpful to some of you!

2 Likes

Im in the process of setting up a rack, can you share more details on how you connect the fans to the poe splitter?

Does the poe splitter show up in device list, else it would require a way to set up a switch for by specifying switch port manually

A LAN cable is plugged into port #8 of my Unifi PoE switch and the input side of the PoE splitter. It looks like this:
poesplitter
Basically it splits into the LAN cable (without power, not used) and a power adapter.
Now Iā€™m sticking a screw terminal onto that:
screwterminal
Now I cut off the three pin plug from the fans. We donā€™t need the signal pin, only 12V and GND, connecting those to the screw terminal:
fancables

Iā€™m addressing port 8 in the script above by the ā€œinterface 0/8ā€ command. Of course you could pass an argument to the script to address other ports easily.

Hope this helps!

2 Likes

Hi iā€™m also looking to shut down my AP in a schedule.
My ap is connected to my unifi poe switch

Is this now already possible?

If you have a unifi Switch connected to a Unifi Controller and that controller is connected to HomeAssistant. Yes.