Node-red-contrib-tplink

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 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

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

Thank I just resolve it, Is working

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:

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.

yes that is the state of the relay.

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

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

This is one switch

[
    {
        "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
    }
]

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

I just imported your flow

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

Did you do that on purpose?

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.

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

[{"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

THANKS, For your time,