Art-of-WiFi / UniFi-API-client

A PHP API client class to interact with Ubiquiti's UniFi Controller API
MIT License
1.09k stars 217 forks source link

Disable PoE #128

Closed gcormier closed 2 years ago

gcormier commented 2 years ago

I'm trying to toggle PoE on a port. There is a PoE splitter on that port, so no actual network device nor MAC address.

My code is below. I'm not clear on how to do this. Am I switching a port between profiles, or am I assign the port to 1 profile, and then modifying the profile?

I do see my unifi portal say "updating" for a minute, and back to ready, but the lightning bolt remains on the port.

$site_id = 'default';
$device_mac = 'f4:92:bf:a6:da:ba';
$port_idx = 4;

 // All : 5627faa4e4b09e0c48d5ee14
 // Disabled / No PoE : 61146f9ca7b11b01299d9ca4
// LightProfile 6155ebd124aa9a01274f3531
$port_conf_id = '6155ebd124aa9a01274f3531';

$unifi_connection   = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, true);
$set_debug_mode     = $unifi_connection->set_debug($debug);
$loginresults       = $unifi_connection->login();
$data               = $unifi_connection->list_devices($device_mac);

$device_id          = $data[0]->device_id;
$existing_overrides = $data[0]->port_overrides;
//var_dump($existing_overrides);
//var_dump($unifi_connection->list_portconf());
foreach ($existing_overrides as $key => $value) {
    if (!empty($value->port_idx) && $value->port_idx === $port_idx) {
        $updated_override = [
            'portconf_id' => $port_conf_id,
            'port_idx'    => $port_idx,
            'poe_mode'    => $value->poe_mode,
            //'poe_mode'    => "Off",
            'name'        => 'Lights',
        ];

        $existing_overrides[$key] = $updated_override;
    }
}

$payload = [
    'port_overrides' => $existing_overrides
];

$update_device = $unifi_connection->set_device_settings_base($device_id, $payload);
//echo('payload');
//var_dump($payload);

echo json_encode($update_device, JSON_PRETTY_PRINT);
malle-pietje commented 2 years ago

Why don’t you take not of the switch’s full device details, then simply toggle the PoE port to off through the controller UI and compare the changes. Specifically have a good look at the port_overrides section.

My guess is you need to change the poe_mode for the port to “off”.

gcormier commented 2 years ago

switched to pyUnifi

malle-pietje commented 2 years ago

If you’re more into Python that’s a good move. Good luck.