# Node-red-contrib-tplink

**URL:** https://discourse.nodered.org/t/node-red-contrib-tplink/85390
**Category:** General
**Tags:** node-red-dashboard
**Created:** [10 February 2024 01:32 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390 "2024-02-10T01:32:46Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [10 February 2024 01:32 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/1 "2024-02-10T01:32:46Z")

</div>

Can some one help me to understand the meaning of : Under the hood, this uses [TP-Link Smart Home API in the description of node-red-contrib-tplink

This is a [Node-RED](https://nodered.org/) node that allows you to control smart plugs, switches, and bulbs from the TP-Link Kasa Smart ecosystem. Under the hood, this uses [TP-Link Smart Home API

I a running node red on windows and look to me this is for Pi. I did install the api using CMD and the node red crash when I deploy the node.

9 Feb 19:06:31 - [red] Uncaught Exception:  
9 Feb 19:06:31 - [error] Error: Cannot set headers after they are sent to the client  
at ServerResponse.setHeader (node:\_http\_outgoing:652:11)  
at ServerResponse.header (C:\Users\Casa\AppData\Roaming\npm\node\_modules\node-red\node\_modules\express\lib\response.js:794:10)  
at ServerResponse.send (C:\Users\Casa\AppData\Roaming\npm\node\_modules\node-red\node\_modules\express\lib\response.js:174:12)  
at C:\Users\Casa.node-red\node\_modules\node-red-contrib-tplink-iot\smart-plug.js:11:502  
at processTicksAndRejections (node:internal/process/task\_queues:95:5

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [10 February 2024 01:48 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/2 "2024-02-10T01:48:40Z")

</div>

I use that node a lot but if there is a question in your post I didn't see it.

---

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [10 February 2024 02:00 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/3 "2024-02-10T02:00:10Z")

</div>

Thank I just resolve it, Is working

---

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [10 February 2024 02:19 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/4 "2024-02-10T02:19:55Z")

</div>

Gerry

You say that you use it a lot, I have a HS300 i was able to send command to turn each plug on/off. Can you let me know how I can get the individual state for each plug to display on the dashboard as a text. "PC 1" state "PC 2"state etc,  
This is the debug

object

sw\_ver: "1.0.12 Build 220121 Rel.175814"

hw\_ver: "2.0"

model: "HS300(US)"

deviceId: "800678AF75F06F8D141FE71D5A153A59222667A6"

oemId: "32BD0B21AA9BF8E84737D1DB1C66E883"

hwId: "955F433CBA24823A248A59AA64571A73"

rssi: -55

latitude\_i: 185074

longitude\_i: -671196

alias: "TP-LINK\_Power Strip\_11AB"

status: "new"

mic\_type: "IOT.SMARTPLUGSWITCH"

feature: "TIM:ENE"

mac: "E4:FA:C4:56:11:AB"

updating: 0

led\_off: 0

children: array[6]

0: object

id: "800678AF75F06F8D141FE71D5A153A59222667A600"

state: 0

alias: "PC 1"

on\_time: 0

next\_action: object

1: object

id: "800678AF75F06F8D141FE71D5A153A59222667A601"

state: 1

alias: "PC2"

on\_time: 446

next\_action:

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [10 February 2024 03:57 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/5 "2024-02-10T03:57:04Z")

</div>

If you send the command  
Msg ={payload:getinfo}  
The node will spit out a ton of info. Somewhere in that mess you will find a statement of relay\_state that tells you whether it's on or off, I think. I don't have that exact device but that command is supposed to work on all if them. Put a debug node on the output send that command and somewhere you should find the state.  
[Edit] I see a "state" in your post. Is that the relay on/off? Try checking that out.

---

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [10 February 2024 05:27 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/6 "2024-02-10T05:27:48Z")

</div>

yes that is the state of the relay.

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [10 February 2024 05:30 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/7 "2024-02-10T05:30:36Z")

</div>

That answer your question? Put a node on the end of the tplink node to get that value.

---

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [10 February 2024 05:44 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/8 "2024-02-10T05:44:34Z")

</div>

If a put a text node is showing a bunch of info. all the data. what I did is put a switch in front of the kasa node and connect the switch nodeto a funtion node with this:  
switch (msg.payload) {  
case true:  
msg.color = "Lime";  
msg.payload = "ON";  
break;  
case false:  
msg.color = "Red";  
msg.payload = "OFF";  
break;  
}

return msg;  
and connect his to a text node. Long but work

Thanks for you time and interest in my problem

---

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [10 February 2024 05:48 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/9 "2024-02-10T05:48:53Z")

</div>

This is one switch

```auto
[
    {
        "id": "617b0f14a87101b4",
        "type": "ui_switch",
        "z": "c9fad22bd2981aac",
        "name": "PC 1",
        "label": "<font size=\"+2\"><font color=\"yellow\">PC 1",
        "tooltip": "",
        "group": "241820d172e65d1d",
        "order": 4,
        "width": 4,
        "height": 1,
        "passthru": true,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "true",
        "onvalueType": "bool",
        "onicon": "fa-2x fa-power-off",
        "oncolor": "lime",
        "offvalue": "false",
        "offvalueType": "bool",
        "officon": "fa-2x fa-power-off",
        "offcolor": "red",
        "animate": false,
        "className": "",
        "x": 450,
        "y": 340,
        "wires": [
            [
                "a67dd9aa75613c8a",
                "d5fddc3e569367a6",
                "f45e2d8ef9c7740f"
            ]
        ]
    },
    {
        "id": "a67dd9aa75613c8a",
        "type": "kasa",
        "z": "c9fad22bd2981aac",
        "name": "Sw PC 1",
        "device": "10.0.4.86/0",
        "interval": 60000,
        "eventInterval": 15000,
        "payload": "getInfo",
        "payloadType": "info",
        "debug": false,
        "x": 580,
        "y": 340,
        "wires": [
            []
        ]
    },
    {
        "id": "8a71f28828efeda0",
        "type": "ui_text",
        "z": "c9fad22bd2981aac",
        "group": "241820d172e65d1d",
        "order": 10,
        "width": 4,
        "height": 1,
        "name": "pc 1",
        "label": "<font size=\"+2\"><font color=\"yellow\">PC 1",
        "format": "<font size=\"+2\"><font color= {{msg.color}} > {{msg.payload}} </font>",
        "layout": "row-spread",
        "className": "ON.color = 'red';",
        "style": false,
        "font": "",
        "fontSize": "",
        "color": "#000000",
        "x": 830,
        "y": 340,
        "wires": []
    },
    {
        "id": "d5fddc3e569367a6",
        "type": "ui_led",
        "z": "c9fad22bd2981aac",
        "order": 12,
        "group": "241820d172e65d1d",
        "width": 1,
        "height": 1,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#00ff00",
                "value": "true",
                "valueType": "bool"
            },
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "bool"
            }
        ],
        "allowColorForValueInMessage": true,
        "shape": "square",
        "showGlow": true,
        "name": "PC 1",
        "x": 950,
        "y": 340,
        "wires": []
    },
    {
        "id": "f45e2d8ef9c7740f",
        "type": "function",
        "z": "c9fad22bd2981aac",
        "name": "C",
        "func": "switch (msg.payload) {\n\n case true:\n msg.color = \"Lime\";\n msg.payload = \"ON\";\n break;\n\n case false:\n msg.color = \"Red\";\n msg.payload = \"OFF\";\n break;\n \n}\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 710,
        "y": 340,
        "wires": [
            [
                "8a71f28828efeda0"
            ]
        ]
    },
    {
        "id": "241820d172e65d1d",
        "type": "ui_group",
        "name": "MAIN POWER",
        "tab": "76c1d76e82d63ff5",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "76c1d76e82d63ff5",
        "type": "ui_tab",
        "name": "OBS",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [10 February 2024 05:55 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/10 "2024-02-10T05:55:06Z")

</div>

A quick way is a function node I'm doing this from a phone so I'm not able to recommend a core node but there are easier ways. In a function node something like  
let X = msg.payload.something.something  
You can get the exact path from the debug output

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [10 February 2024 11:24 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/11 "2024-02-10T11:24:57Z")

</div>

I just imported your flow

 ![Screenshot 2024-02-10 at 6.25.43 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2385b05a8da8ba18ea300b9295b8ade95c6eae2.png)

and then I moved things around and the nodes are NOT connected in the order it looks

 ![Screenshot 2024-02-10 at 6.23.49 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e7938d4d460cf98ce92c674ae2f84e48d6a9b271.png)

Did you do that on purpose?

---

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [10 February 2024 12:22 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/12 "2024-02-10T12:22:30Z")

</div>

Yes I did,to be able to display it correct. I left the kasa node alone to control the plug because the output have a lot of info. . I use the function to get the state of the switch and change the color of the output and display in a text note. The led is get getting the state from the Switch. Long way but it work as I want.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [10 February 2024 22:26 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/13 "2024-02-10T22:26:24Z")

</div>

I played around a bit and this is how I would do it

 ![Screenshot 2024-02-10 at 5.25.43 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/adc4cb3d906f4213da39fe6aaa299bed01cdaa68.png)

```auto
[{"id":"6581c4e7a136c26e","type":"ui_switch","z":"0d3a52d34b03f1bc","name":"PC 1 switch","label":"<font size=\"+2\"><font color=\"brown\">PC1","tooltip":"","group":"e473f267eadc0fbb","order":1,"width":4,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"fa-2x fa-power-off","oncolor":"lime","offvalue":"false","offvalueType":"bool","officon":"fa-2x fa-power-off","offcolor":"red","animate":false,"className":"","x":230,"y":180,"wires":[["3d93a8d8868d2016"]]},{"id":"3d93a8d8868d2016","type":"kasa","z":"0d3a52d34b03f1bc","name":"tplink40 - HS105(US)","device":"192.168.1.151","interval":60000,"eventInterval":15000,"payload":"getInfo","payloadType":"info","debug":false,"x":420,"y":180,"wires":[["2d36082ebbcce245"]]},{"id":"464c1297f1d0d93d","type":"ui_text","z":"0d3a52d34b03f1bc","group":"e473f267eadc0fbb","order":3,"width":4,"height":1,"name":"pc 1 text","label":"<font size=\"+2\"><font color=\"blue\">PC 2","format":"<font size=\"+2\"><font color= {{msg.color}} > {{msg.payload}} </font>","layout":"row-spread","className":"ON.color = 'red';","style":false,"font":"","fontSize":"","color":"#000000","x":1060,"y":200,"wires":[]},{"id":"2d36082ebbcce245","type":"switch","z":"0d3a52d34b03f1bc","name":"","property":"payload.relay_state","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":180,"wires":[["eb9e225ea5b832f9"],["5af8c8990be25261"]]},{"id":"5af8c8990be25261","type":"change","z":"0d3a52d34b03f1bc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"color","pt":"msg","to":"red","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":200,"wires":[["d6f46141cc96dcc5","464c1297f1d0d93d"]]},{"id":"eb9e225ea5b832f9","type":"change","z":"0d3a52d34b03f1bc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"color","pt":"msg","to":"Lime","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":160,"wires":[["d6f46141cc96dcc5","464c1297f1d0d93d"]]},{"id":"d6f46141cc96dcc5","type":"ui_led","z":"0d3a52d34b03f1bc","order":2,"group":"e473f267eadc0fbb","width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#00ff00","value":"true","valueType":"bool"},{"color":"#ff0000","value":"false","valueType":"bool"}],"allowColorForValueInMessage":true,"shape":"square","showGlow":true,"name":"PC 1 led","x":1060,"y":160,"wires":[]},{"id":"e473f267eadc0fbb","type":"ui_group","name":"Online Devices1","tab":"20e4869160d94f4b","order":4,"disp":true,"width":"6","collapse":false,"className":""},{"id":"20e4869160d94f4b","type":"ui_tab","name":"Home2","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

Note: You will have to change the KASA node to your devices IP address

---

<div class="post-metadata">

### Author: ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)
#### Post date: [11 February 2024 01:02 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/14 "2024-02-11T01:02:30Z")

</div>

THANKS, For your time,

---

<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: [11 May 2024 01:02 UTC](https://discourse.nodered.org/t/node-red-contrib-tplink/85390/15 "2024-05-11T01:02:45Z")

</div>

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