| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
I just setup a new WiFi network at home and wondered if there was a way to move my ~50 TP-Link Kasa devices over to the new SSID. I found this, and it looked like I could script it all out using the command line wifi join arguments instead of manually resetting every piece of hardware!
This plan worked perfectly for all my HS220 dimmer switches and KP115 plugs; they moved over to the new wireless SSID very easily. Unfortunately the rest (and majority) of my switches and plugs (model numbers: HS200, HS210, HS103, HS105, HS107, & KP400) didn't seem to change over to the new SSID when I ran the exact same commands. There were no obvious error messages that I could find.
I'm using v0.8.1 and ran the same command for each type of device:
kasa --host <IP> --verbose --debug --timeout 60 wifi join <NEW-SSID>
Running a wifi scan on these devices is successful and shows the SSID I want them to connect to. Other command line instructions like turning these switches/plugs on/off were also successful.
Here's the command line output I'm seeing for a successful attempt with a HS220 and an unsuccessful attempt with a HS200. Any idea what could be causing this behaviour and what to try next? Thanks!
person@device:~ $ kasa --host 10.4.10.222 --verbose --debug --timeout 60 wifi join <NEW-SSID>
Discovering device 10.4.10.222 for 10 seconds
DEBUG:kasa.discover:[DISCOVERY] 10.4.10.222 >> {'system': {'get_sysinfo': {}}}
DEBUG:kasa.discover:Waiting a total of 10 seconds for responses...
DEBUG:kasa.discover:[DISCOVERY] 10.4.10.222 << {'system': {'get_sysinfo': {'active_mode': 'none',
'alias': '#MASKED_NAME#',
'brightness': 85,
'dev_name': 'Wi-Fi Smart Dimmer',
'deviceId': 'XXXXXX',
'err_code': 0,
'feature': 'TIM',
'hwId': 'XXXXXX',
'hw_ver': '2.0',
'icon_hash': '',
'latitude_i': 0,
'led_off': 0,
'longitude_i': 0,
'mac': '00:5F:67:00:00:00',
'mic_type': 'IOT.SMARTPLUGSWITCH',
'model': 'HS220(US)',
'next_action': {'type': -1},
'oemId': 'XXXXXX',
'on_time': 0,
'preferred_state': [{'brightness': 100, 'index': 0},
{'brightness': 75, 'index': 1},
{'brightness': 50, 'index': 2},
{'brightness': 25, 'index': 3}],
'relay_state': 0,
'rssi': -62,
'status': 'new',
'sw_ver': '1.0.8 Build 210423 Rel.075507',
'updating': 0}}}
DEBUG:kasa.device:Initializing 10.4.10.222 of type <class 'kasa.iot.iotdimmer.IotDimmer'>
DEBUG:kasa.iot.iotdevice:Adding module <Module Schedule (schedule) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module Usage (schedule) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module Antitheft (anti_theft) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module Time (time) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module Cloud (cnCloud) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module Led (system) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module Motion (smartlife.iot.PIR) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module AmbientLight (smartlife.iot.LAS) for 10.4.10.222>
DEBUG:kasa.iot.iotdevice:Adding module <Module Light (light) for 10.4.10.222>
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: schedule
DEBUG:kasa.iot.iotdevice:Adding query for <Module Schedule (schedule) for 10.4.10.222>: {'schedule': {'get_rules': {}, 'get_next_action': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: schedule
DEBUG:kasa.iot.iotdevice:Adding query for <Module Usage (schedule) for 10.4.10.222>: {'schedule': {'get_realtime': {}, 'get_daystat': {'year': 2024, 'month': 12}, 'get_monthstat': {'year': 2024}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: anti_theft
DEBUG:kasa.iot.iotdevice:Adding query for <Module Antitheft (anti_theft) for 10.4.10.222>: {'anti_theft': {'get_rules': {}, 'get_next_action': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: time
DEBUG:kasa.iot.iotdevice:Adding query for <Module Time (time) for 10.4.10.222>: {'time': {'get_time': {}, 'get_timezone': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: cnCloud
DEBUG:kasa.iot.iotdevice:Adding query for <Module Cloud (cnCloud) for 10.4.10.222>: {'cnCloud': {'get_info': {}}}
DEBUG:kasa.iot.iotdevice:Adding query for <Module Led (system) for 10.4.10.222>: {}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: smartlife.iot.PIR
DEBUG:kasa.iot.iotdevice:Adding query for <Module Motion (smartlife.iot.PIR) for 10.4.10.222>: {'smartlife.iot.PIR': {'get_config': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: smartlife.iot.LAS
DEBUG:kasa.iot.iotdevice:Adding query for <Module AmbientLight (smartlife.iot.LAS) for 10.4.10.222>: {'smartlife.iot.LAS': {'get_config': {}, 'get_current_brt': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: light
DEBUG:kasa.iot.iotdevice:Adding query for <Module Light (light) for 10.4.10.222>: {}
DEBUG:kasa.protocols.iotprotocol:10.4.10.222 >> {"system":{"get_sysinfo":{}},"schedule":{"get_rules":{},"get_next_action":{},"get_realtime":{},"get_daystat":{"year":2024,"month":12},"get_monthstat":{"year":2024}},"anti_theft":{"get_rules":{},"get_next_action":{}},"time":{"get_time":{},"get_timezone":{}},"cnCloud":{"get_info":{}},"smartlife.iot.PIR":{"get_config":{}},"smartlife.iot.LAS":{"get_config":{},"get_current_brt":{}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.222 sending query {"system":{"get_sysinfo":{}},"schedule":{"get_rules":{},"get_next_action":{},"get_realtime":{},"get_daystat":{"year":2024,"month":12},"get_monthstat":{"year":2024}},"anti_theft":{"get_rules":{},"get_next_action":{}},"time":{"get_time":{},"get_timezone":{}},"cnCloud":{"get_info":{}},"smartlife.iot.PIR":{"get_config":{}},"smartlife.iot.LAS":{"get_config":{},"get_current_brt":{}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.222 query response received
DEBUG:kasa.protocols.iotprotocol:10.4.10.222 << {'anti_theft': {'get_next_action': {'err_code': -2,
'err_msg': 'member not support'},
'get_rules': {'enable': 0,
'err_code': 0,
'rule_list': [],
'version': 2}},
'cnCloud': {'get_info': {'binded': 1,
'cld_connection': 1,
'err_code': 0,
'fwDlPage': '',
'fwNotifyType': -1,
'illegalType': 0,
'server': 'n-devs.tplinkcloud.com',
'stopConnect': 0,
'tcspInfo': '',
'tcspStatus': 1,
'username': 'user@example.com'}},
'schedule': {'get_daystat': {'day_list': [{'day': 4,
'month': 12,
'time': 135,
'year': 2024},
{'day': 9,
'month': 12,
'time': 0,
'year': 2024}],
'err_code': 0},
'get_monthstat': {'err_code': 0,
'month_list': [{'month': 10,
'time': 3195,
'year': 2024},
{'month': 11,
'time': 2788,
'year': 2024},
{'month': 12,
'time': 135,
'year': 2024},
{'month': 1,
'time': 5721,
'year': 2024},
{'month': 2,
'time': 2798,
'year': 2024},
{'month': 3,
'time': 2556,
'year': 2024},
{'month': 4,
'time': 4305,
'year': 2024},
{'month': 5,
'time': 3471,
'year': 2024},
{'month': 6,
'time': 2951,
'year': 2024},
{'month': 7,
'time': 2257,
'year': 2024},
{'month': 8,
'time': 2051,
'year': 2024},
{'month': 9,
'time': 1168,
'year': 2024}]},
'get_next_action': {'err_code': 0, 'type': -1},
'get_realtime': {'err_code': -2, 'err_msg': 'member not support'},
'get_rules': {'enable': 1,
'err_code': 0,
'rule_list': [],
'version': 2}},
'smartlife.iot.LAS': {'err_code': -1, 'err_msg': 'module not support'},
'smartlife.iot.PIR': {'err_code': -1, 'err_msg': 'module not support'},
'system': {'get_sysinfo': {'active_mode': 'none',
'alias': '#MASKED_NAME#',
'brightness': 85,
'dev_name': 'Wi-Fi Smart Dimmer',
'deviceId': 'XXXXXX',
'err_code': 0,
'feature': 'TIM',
'hwId': 'XXXXXX',
'hw_ver': '2.0',
'icon_hash': '',
'latitude_i': 0,
'led_off': 0,
'longitude_i': 0,
'mac': '00:5F:67:00:00:00',
'mic_type': 'IOT.SMARTPLUGSWITCH',
'model': 'HS220(US)',
'next_action': {'type': -1},
'oemId': 'XXXXXX',
'on_time': 0,
'preferred_state': [{'brightness': 100, 'index': 0},
{'brightness': 75, 'index': 1},
{'brightness': 50, 'index': 2},
{'brightness': 25, 'index': 3}],
'relay_state': 0,
'rssi': -58,
'status': 'new',
'sw_ver': '1.0.8 Build 210423 Rel.075507',
'updating': 0}},
'time': {'get_time': {'err_code': 0,
'hour': 16,
'mday': 9,
'min': 53,
'month': 12,
'sec': 2,
'year': 2024},
'get_timezone': {'err_code': 0, 'index': 18}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: light
Keytype: 3
Password:
Asking the device to connect to <NEW-SSID>..
DEBUG:kasa.protocols.iotprotocol:10.4.10.222 >> {"netif":{"set_stainfo":{"ssid":"<NEW-SSID>","password":"<NEW-PASSWORD>","key_type":3}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.222 sending query {"netif":{"set_stainfo":{"ssid":"<NEW-SSID>","password":"<NEW-PASSWORD>","key_type":3}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.222 query response received
DEBUG:kasa.protocols.iotprotocol:10.4.10.222 << {'netif': {'set_stainfo': {'err_code': 0}}}
Response: {} - if the device is not able to join the network, it will revert back to its previous state.
person@device:~ $
person@device:~ $ kasa --host 10.4.10.102 --verbose --debug --timeout 60 wifi join <NEW-SSID>
Discovering device 10.4.10.102 for 10 seconds
DEBUG:kasa.discover:[DISCOVERY] 10.4.10.102 >> {'system': {'get_sysinfo': {}}}
DEBUG:kasa.discover:Waiting a total of 10 seconds for responses...
DEBUG:kasa.discover:[DISCOVERY] 10.4.10.102 << {'system': {'get_sysinfo': {'active_mode': 'none',
'alias': '#MASKED_NAME#',
'dev_name': 'Smart Wi-Fi Light Switch',
'deviceId': 'XXXXXX',
'err_code': 0,
'feature': 'TIM',
'fwId': '00000000000000000000000000000000',
'hwId': 'XXXXXX',
'hw_ver': '2.0',
'icon_hash': '',
'latitude_i': 0,
'led_off': 0,
'longitude_i': 0,
'mac': '68:FF:7B:00:00:00',
'mic_type': 'IOT.SMARTPLUGSWITCH',
'model': 'HS200(US)',
'next_action': {'type': -1},
'oemId': 'XXXXXX',
'on_time': 0,
'relay_state': 0,
'rssi': -43,
'sw_ver': '1.5.7 Build 191118 Rel.140152',
'updating': 0}}}
DEBUG:kasa.device:Initializing 10.4.10.102 of type <class 'kasa.iot.iotplug.IotWallSwitch'>
DEBUG:kasa.iot.iotdevice:Adding module <Module Schedule (schedule) for 10.4.10.102>
DEBUG:kasa.iot.iotdevice:Adding module <Module Usage (schedule) for 10.4.10.102>
DEBUG:kasa.iot.iotdevice:Adding module <Module Antitheft (anti_theft) for 10.4.10.102>
DEBUG:kasa.iot.iotdevice:Adding module <Module Time (time) for 10.4.10.102>
DEBUG:kasa.iot.iotdevice:Adding module <Module Cloud (cnCloud) for 10.4.10.102>
DEBUG:kasa.iot.iotdevice:Adding module <Module Led (system) for 10.4.10.102>
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: schedule
DEBUG:kasa.iot.iotdevice:Adding query for <Module Schedule (schedule) for 10.4.10.102>: {'schedule': {'get_rules': {}, 'get_next_action': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: schedule
DEBUG:kasa.iot.iotdevice:Adding query for <Module Usage (schedule) for 10.4.10.102>: {'schedule': {'get_realtime': {}, 'get_daystat': {'year': 2024, 'month': 12}, 'get_monthstat': {'year': 2024}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: anti_theft
DEBUG:kasa.iot.iotdevice:Adding query for <Module Antitheft (anti_theft) for 10.4.10.102>: {'anti_theft': {'get_rules': {}, 'get_next_action': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: time
DEBUG:kasa.iot.iotdevice:Adding query for <Module Time (time) for 10.4.10.102>: {'time': {'get_time': {}, 'get_timezone': {}}}
DEBUG:kasa.iot.iotmodule:Initial update, so consider supported: cnCloud
DEBUG:kasa.iot.iotdevice:Adding query for <Module Cloud (cnCloud) for 10.4.10.102>: {'cnCloud': {'get_info': {}}}
DEBUG:kasa.iot.iotdevice:Adding query for <Module Led (system) for 10.4.10.102>: {}
DEBUG:kasa.protocols.iotprotocol:10.4.10.102 >> {"system":{"get_sysinfo":{}},"schedule":{"get_rules":{},"get_next_action":{},"get_realtime":{},"get_daystat":{"year":2024,"month":12},"get_monthstat":{"year":2024}},"anti_theft":{"get_rules":{},"get_next_action":{}},"time":{"get_time":{},"get_timezone":{}},"cnCloud":{"get_info":{}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.102 sending query {"system":{"get_sysinfo":{}},"schedule":{"get_rules":{},"get_next_action":{},"get_realtime":{},"get_daystat":{"year":2024,"month":12},"get_monthstat":{"year":2024}},"anti_theft":{"get_rules":{},"get_next_action":{}},"time":{"get_time":{},"get_timezone":{}},"cnCloud":{"get_info":{}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.102 query response received
DEBUG:kasa.protocols.iotprotocol:10.4.10.102 << {'anti_theft': {'get_next_action': {'err_code': -2,
'err_msg': 'member not support'},
'get_rules': {'enable': 0,
'err_code': 0,
'rule_list': [],
'version': 2}},
'cnCloud': {'get_info': {'binded': 1,
'cld_connection': 1,
'err_code': 0,
'fwDlPage': '',
'fwNotifyType': 0,
'illegalType': 0,
'server': 'n-devs.tplinkcloud.com',
'stopConnect': 0,
'tcspInfo': '',
'tcspStatus': 1,
'username': 'user@example.com'}},
'schedule': {'get_daystat': {'day_list': [{'day': 1,
'month': 12,
'time': 262,
'year': 2024},
{'day': 2,
'month': 12,
'time': 319,
'year': 2024},
{'day': 3,
'month': 12,
'time': 838,
'year': 2024},
{'day': 4,
'month': 12,
'time': 651,
'year': 2024},
{'day': 5,
'month': 12,
'time': 229,
'year': 2024},
{'day': 6,
'month': 12,
'time': 174,
'year': 2024},
{'day': 7,
'month': 12,
'time': 343,
'year': 2024},
{'day': 8,
'month': 12,
'time': 0,
'year': 2024},
{'day': 9,
'month': 12,
'time': 52,
'year': 2024}],
'err_code': 0},
'get_monthstat': {'err_code': 0,
'month_list': [{'month': 8,
'time': 829,
'year': 2024},
{'month': 10,
'time': 5179,
'year': 2024},
{'month': 9,
'time': 2374,
'year': 2024},
{'month': 11,
'time': 6566,
'year': 2024},
{'month': 12,
'time': 2868,
'year': 2024},
{'month': 5,
'time': 1746,
'year': 2024},
{'month': 7,
'time': 741,
'year': 2024},
{'month': 6,
'time': 3487,
'year': 2024}]},
'get_next_action': {'err_code': 0, 'type': -1},
'get_realtime': {'err_code': -2, 'err_msg': 'member not support'},
'get_rules': {'enable': 1,
'err_code': 0,
'rule_list': [],
'version': 2}},
'system': {'get_sysinfo': {'active_mode': 'none',
'alias': '#MASKED_NAME#',
'dev_name': 'Smart Wi-Fi Light Switch',
'deviceId': 'XXXXXX',
'err_code': 0,
'feature': 'TIM',
'fwId': '00000000000000000000000000000000',
'hwId': 'XXXXXX',
'hw_ver': '2.0',
'icon_hash': '',
'latitude_i': 0,
'led_off': 0,
'longitude_i': 0,
'mac': '68:FF:7B:00:00:00',
'mic_type': 'IOT.SMARTPLUGSWITCH',
'model': 'HS200(US)',
'next_action': {'type': -1},
'oemId': 'XXXXXX',
'on_time': 0,
'relay_state': 0,
'rssi': -43,
'sw_ver': '1.5.7 Build 191118 Rel.140152',
'updating': 0}},
'time': {'get_time': {'err_code': 0,
'hour': 16,
'mday': 9,
'min': 54,
'month': 12,
'sec': 20,
'year': 2024},
'get_timezone': {'err_code': 0, 'index': 18}}}
Keytype: 3
Password:
Asking the device to connect to <NEW-SSID>..
DEBUG:kasa.protocols.iotprotocol:10.4.10.102 >> {"netif":{"set_stainfo":{"ssid":"<NEW-SSID>","password":"<NEW-PASSWORD>","key_type":3}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.102 sending query {"netif":{"set_stainfo":{"ssid":"<NEW-SSID>","password":"<NEW-PASSWORD>","key_type":3}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.102 query response received
DEBUG:kasa.protocols.iotprotocol:10.4.10.102 << {'netif': {'set_stainfo': {'err_code': 0}}}
Response: {} - if the device is not able to join the network, it will revert back to its previous state.
person@device:~ $
P.S. I've been using this integration with Home Assistant for years, and it is great! Thank you!
| Back | FazBrowse Home | New Git URL |
Activity
rytilahti commented on Dec 10, 2024
Glad you have enjoyed the integration :-)
To your problem, could check what the logs wifi scan show for the key type? Is it also 3? You could also verify whether the "module" for scanning is also netif as in your logs above, just to be sure.
It might be that these devices use a slightly different API for the wifi configuration (as they sound seemingly newer hw than HS220 and KP115), that no one has yet investigated, but checking those details I mentioned would be the first step to start debugging the issue.
convexone commented on Dec 10, 2024
wifi scan shows key_type=3 for all networks and looks to be using netif from what I can tell.
Here's a little bit of the output when I run kasa --host 10.4.10.102 --type switch --verbose --debug --timeout 60 wifi scan
Scanning for wifi networks, wait a second..
DEBUG:kasa.protocols.iotprotocol:10.4.10.102 >> {"netif":{"get_scaninfo":{"refresh":1}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.102 sending query {"netif":{"get_scaninfo":{"refresh":1}}}
DEBUG:kasa.transports.xortransport:Device 10.4.10.102 query response received
DEBUG:kasa.protocols.iotprotocol:10.4.10.102 << {'netif': {'get_scaninfo': {'ap_list': [{'key_type': 3,
'ssid': '#MASKED_SSID#'},
{'key_type': 3,
'ssid': '#MASKED_SSID#'},
{'key_type': 3,
'ssid': '#MASKED_SSID#'},
{'key_type': 3,
'ssid': '#MASKED_SSID#'},
I think the devices not working as hoped are actually the older ones. Most of my HS200 switches & HS10x plugs are from 2018-2019. The HS220's & KP115 are from 2020-2021.
rytilahti commented on Dec 10, 2024
Maybe your SSID or the password has some special characters these devices do not like, ` or $, maybe? Just guessing here, as the device reports that the call succeeded.
convexone commented on Dec 10, 2024
I tried creating a new network with SSID & pw both having only alphanumeric characters - same results (still didn't work).
I can change the HS220's back and forth between all these SSID's with no issue.
rytilahti commented on Dec 10, 2024
If your wifi router has some logging on connections (I know that openwrt I personally use does), you could take a look if there is ever an attempt to connect when you execute that command.
Besides incorrect ssid / password / key type, I don't unfortunately have any ideas what to try.
github-actions commented on Mar 11, 2025
There hasn't been any activity on this issue recently. This issue has been automatically marked as stale because of that. It will be closed if no further activity occurs.
Please make sure to update to the latest python-kasa version and check if that solves the issue.
Thank you for your contributions.
shinerblue commented on Oct 5, 2026
Same symptom here on an older fleet (HS200 v2/v3, HS220 v1, HS103 v1/v2, KP200, KP400): wifi join returns OK while the device is connected, but it never switches networks.
Sending the same join while the device is in setup mode worked every time. You don't have to press the button for that: kasa --host <ip> device factory-reset drops the device into setup mode remotely. Then join its TP-LINK_Smart … network and run kasa --host 192.168.0.1 wifi join <ssid>. I opened #1783 to document this.
One thing I hit along the way: factory-reset fails on a KL120 bulb with err -2000. That bulb only accepts {"smartlife.iot.common.system":{"reset":{"delay":1}}}, while a KL135 accepts the normal system.reset. I can open a separate PR for a fallback if that's useful.