# Toggle POE State of UniFi Switch Ports WITH node-red-contrib-unifi-os

**URL:** <https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734>\
**Category:** General\
**Tags:** unifi\
**Created:** [27 May 2023 12:22 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734 "2023-05-27T12:22:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ager](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ager](https://discourse.nodered.org/u/ager)\
**Post date:** [27 May 2023 12:22 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/1 "2023-05-27T12:22:40Z")

</div>

**Hi all,**

I would like to be able to toggle (On/Off POE) POE on unifi switch ports from Loxone commands (http or udp doesnt matter it is working for me).

I have POE Unifi switch US-8-60W. (1-4 port is without POE and ports 5-8 is POE ports).

I am using Node-RED v2.1.3.

I have found related nodes:  
**Toggle POE State of UniFi Switch Ports**  
**node-red-contrib-unifi-os**

I have installed **node-red-contrib-unifi-os** and imported **Toggle POE State of UniFi Switch Ports** and setup Unifi network Aplication in **unifi-request node** it is inicialized:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e9c2f9f0a3c5ef15a5948a1a626b02fc4787bab2.png)

As you can see in above picture by default Endpoint was **proxy/network/api/s/default/stat/device** but there I was not able to get any data in browser:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe55aac53d340c6257e73625bee860ab542ca093.png)

So after some search I have found that correct Endpoint should be **/api/s/vorj5idg/stat/device** and there I am able to get data in browser:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70d1e90ffd9f03880e1cf2ec181a53213e318a60.png)

an also in nodered see here::

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b06c8b5f24c9e57fc80c2a34b76fd7e3416fb8a.png)

But if try in **Toogle POE port** I always get this error:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/9642a89f6a768f434f2789610b3601f811383196.png)

Can you help me please?

I have read [here in forum](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246) and it helped me due to @crxporter replies ([Library - Node-RED](https://flows.nodered.org/user/crxporter)) to find correct **Endpoint** but I am not able to get over ☹

@Shaquu  
@fritz

Let me inform you that if I connect by putty (SSH) to me Unifi switch US-8-60W and send comand:  
**swctrl poe set auto id 5**  
POE on port 5 is switched on.  
and if I send command:  
**swctrl poe set off id 5**  
POE on port 5 is switched Off  
So switch is working correctly.

Many thanks for each help  
BR  
ager

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [27 May 2023 12:37 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/2 "2023-05-27T12:37:41Z")

</div>

Yes this should be possible. You'll need to use an HTTP `PATCH` command sent to that same endpoint. Just send the JSON key and value that you notice changing.

The closest example I have documented is for toggling camera motion detection: [Changing camera settings · NRCHKB/node-red-contrib-unifi-os Wiki · GitHub](https://github.com/NRCHKB/node-red-contrib-unifi-os/wiki/Changing-camera-settings)

I'll watch (also @marcus-j-davies will watch, we're together this week 😉 ) how things go and might have time this weekend to do a few quick tests if you need more help.

---

<div class="post-metadata">

**Author:** ![ager](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ager](https://discourse.nodered.org/u/ager)\
**Post date:** [27 May 2023 20:30 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/3 "2023-05-27T20:30:28Z")

</div>

Many many thanks @crxporter for your fast and reply and help!!!  
I have read your post many times and also your example link and looks eassy but to be honest I dont want to kill me switch 🙂

So at first I triggered **unifi-request node** and you can see response.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e921d7eb8f51da104a75110b90a1488202a99155.png)  
There is 4 array object:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/bafe446b4f0d487caa696dee330d5d6b527d1f04.png)  
I can see 4 object is 4 devices I have already connected.

I can see **0: object** is my unifi switch:

```auto
object
meta: object
data: array[4]
0: object
_id: "645d722dabf5720019b938aa"
ip: "192.168.1.188"
mac: "74:ac:b9:4d:96:44"
model: "US8P60"
model_in_lts: false
model_in_eol: false
type: "usw"
version: "6.5.32.14509"
adopted: true
site_id: "63c5c749a50c04001efb5388"
x_authkey: "a7dea8371734d783289b4169319935f4"
cfgversion: "13ee190b9c1a099e"
syslog_key: "6b62c90708da02852ddeae71254d1ecd7fc83d358da48fea5a92bdb5055a6850"

```

so I suppose first line is ID we are looking for:

```auto
_id: "645d722dabf5720019b938aa"

```

Little down in **0: object** I have found **port\_table** and I suppose it is 8 me port of the switch:

```auto
port_table: array[8]
0: object
1: object
2: object
3: object
4: object
5: object
6: object
7: object

```

and there I have found that POE port 5 is **4: object:** :

```auto
port_table: array[8]
0: object
1: object
2: object
3: object
4: object
port_idx: 5
media: "GE"
port_poe: true
poe_caps: 1
speed_caps: 1048623
op_mode: "switch"
portconf_id: "63c5c749a50c04001efb5486"
poe_mode: "auto"
anomalies: 0
autoneg: true
dot1x_mode: "unknown"
dot1x_status: "disabled"
enable: true
flowctrl_rx: false
flowctrl_tx: false
full_duplex: false
is_uplink: false
jumbo: false
mac_table: array[0]
poe_class: "Unknown"
poe_current: "0.00"
poe_enable: false
poe_good: false
poe_power: "0.00"
poe_voltage: "0.00"
rx_broadcast: 0
rx_bytes: 0
rx_dropped: 0
rx_errors: 0
rx_multicast: 0
rx_packets: 0
satisfaction: 100
satisfaction_reason: 0
speed: 0
stp_pathcost: 0
stp_state: "disabled"
tx_broadcast: 0
tx_bytes: 0
tx_dropped: 0
tx_errors: 0
tx_multicast: 0
tx_packets: 0
up: false
tx_bytes-r: 0
rx_bytes-r: 0
bytes-r: 0
name: "Port 5"
port_security_mac_address: array[0]
stp_port_mode: true
port_security_enabled: false
masked: false
aggregated_by: false

```

And there I can notice changing value:  
If POE is ON:

```auto
poe_mode: "auto"

```

If POE is OFF:

```auto
poe_mode: "off"

```

So now I need to create 2 unifi-request nodes. One for Off and one for ON like this? :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b55dc3947ca41aed23ce2dde960c45e88511875.png)

Many thanks!!!

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [30 May 2023 00:38 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/4 "2023-05-30T00:38:51Z")

</div>

Sorry for the delay I've been busy.

First up: you won't kill the switch. Best case is the command works. Worst case it does nothing and you try another command.

I'm going to give it a try from my side - the thing missing from your PATCH command is the port index, this will have to be added. I'll return back soon with whatever I learn.

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [30 May 2023 01:19 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/5 "2023-05-30T01:19:54Z")

</div>

Alright. After a bit of testing - I have this working.

With your device as

```json
"_id": "645d722dabf5720019b938aa"

```

and you want to change`"port_idx": 5`

You would do the following command:

Send a `PUT` command to this endpoint:

`/api/s/vorj5idg/rest/device/645d722dabf5720019b938aa `

with this data:

```json
{
    "port_overrides": [
        {
            "port_idx": 5,
            "poe_mode": "off"
        }
    ]
}

```

And of course change "off" to "auto" if you want to turn it back on.

Screenshots from my test:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af391cf90085a1711d96f3c92def445a8ca47dca.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51c5ad59f03e995f899dd1a0610f37f666e485db.png)

I figured this out with help from @marcus-j-davies , [this webpage](https://ubntwiki.com/products/software/UniFi-controller/api), and safari debug while changing the PoE on one of my switches.

---

<div class="post-metadata">

**Author:** ![ager](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ager](https://discourse.nodered.org/u/ager)\
**Post date:** [31 May 2023 08:36 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/6 "2023-05-31T08:36:04Z")

</div>

@crxporter  
Many thanks for your famous reply and help mate and especially your lost time!  
To be honest I was trying to find such solution for years!!!!  
You are great I love you 🙂  
Also big thanks to @marcus-j-davies  
I have already check and all is working as you sent exactly!  
As you can see here in picture I am sending text commands by UDP from loxone and in the switch it is splited to your unifi request nodes (ON or OFF).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc90f29930d04c320a19040bd4afda5cc1d3e4dd.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21ca8449c5938c79c00d18b3796073c635fb56a3.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/896a20798e7363e3e49d0a040de20e7257086183.png)

Is it ok or I should implement some more simple way...any advise from you please?

I have already give you stars in nodered page and also I have already registered in github and also there give you stars and how I should buy coffe please?  
Many many thanks !!!!

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [31 May 2023 11:42 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/7 "2023-05-31T11:42:34Z")

</div>

If the flow works and you know what it's doing - you're in great shape!

As for thanks, knowing you are happy is enough. I'm glad we could figure it out!

---

<div class="post-metadata">

**Author:** ![ager](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ager](https://discourse.nodered.org/u/ager)\
**Post date:** [13 June 2023 22:13 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/8 "2023-06-13T22:13:14Z")

</div>

@crxporter  
Sorry for late reply.  
At first let me say big thanks really you are owesome! Great job!!  
To be honest, once all working, I went to test in real condition and I have found my switch doesnt support 24V POE where I want to use so I am considering to buy some new unifi switch currently....☹  
Just the question, this way it should be working in any Unifi switch ?  
Thanks !  
BR  
ager

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [25 June 2023 00:40 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/9 "2023-06-25T00:40:41Z")

</div>

> [@ager](#):
>
> Just the question, this way it should be working in any Unifi switch ?

I would expect yes. But there may be more values for PoE mode to set it at 24v - since 24v mode will cook many devices if they aren't 24v PoE compatible.

Sorry I can't help, I don't have any of those switches. I can tell you what to look for though if you decide to get another switch.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 August 2023 00:40 UTC](https://discourse.nodered.org/t/toggle-poe-state-of-unifi-switch-ports-with-node-red-contrib-unifi-os/78734/10 "2023-08-24T00:40:58Z")

</div>

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