Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KP400 dual port control #83

Open
darouss99 opened this issue Nov 23, 2020 · 3 comments
Open

KP400 dual port control #83

darouss99 opened this issue Nov 23, 2020 · 3 comments

Comments

@darouss99
Copy link

Hi,

I have a KP400 smartswitch. This is a outdoor unit with 2 individually controlable output.

Is there a way to control the port 1 and 2 individually? I'm able to do it by the Kasa app but not using the script.

If I use this command, it control both port. "tplink_smartplug.py -t 192.168.0.221 -c on"

Thank you

@darouss99 darouss99 changed the title Double Smartswith control KP400 KP400 dual port control Nov 23, 2020
@sylvandb
Copy link

You have to add a "context" section to the json command, specifying the child ID or IDs you wish to control.

I do it with this method, where cmd is the normal command json text, child_id is the uuid of the child (I think the index also works, see the result of info command on your KP400) and this method returns it unaltered if no child_id is specified, or returns the complete context with child_id embedded:
def add_child_context(cmd, child_id=None, **kwargs): return '{"context": {"child_ids": ["%s"]}, %s' % (child_id, cmd[1:]) if child_id else cmd

@darouss99
Copy link
Author

Thank you for your answer.

I'm a very beginner at Python. So if I understand correctly I must add that string in tplink_smartplug.py
def add_child_context(cmd, child_id=None, **kwargs): return '{"context": {"child_ids": ["%s"]}, %s' % (child_id, cmd[1:]) if child_id else cmd

The command should look like what?

If I do an "Info" on this smart switch this is the answer : (I anonymized it)

python tplink_smartplug.py -t 192.168.0.221 -c info
Sent: {"system":{"get_sysinfo":{}}}
Received: {"system":{"get_sysinfo":{"sw_ver":"1.0.6 Build 200821 Rel.090909","hw_ver":"2.0","model":"KP400(US)","deviceId":"----a_40_caracters_ID----","oemId":"----a_32_caracters_ID----","hwId":"----a_32_caracters_ID----","rssi":-30,"longitude_i":-996256,"latitude_i":994660,"alias":"TP-LINK_Smart Plug_C69F","status":"new","mic_type":"IOT.SMARTPLUGSWITCH","feature":"TIM","mac":"----the_mac_add----","updating":0,"led_off":0,"children":[{"id":"----a_42_caracters_ID----","state":1,"alias":"Plug1","on_time":15,"next_action":{"type":-1}},{"id":"----a_42_caracters_ID+1----","state":1,"alias":"Plug2","on_time":15,"next_action":{"type":1,"schd_sec":56400,"action":1}}],"child_num":2,"ntc_state":0,"err_code":0}}}

Thank you

@sylvandb
Copy link

sylvandb commented Jan 5, 2021

Sorry, it's a bit more involved than just adding that to the program. I have a fork of this repo that has diverged too much to be easily merged, but perhaps my version would work for you. https://github.com/sylvandb/tplink-smartplug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants