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

Support for disabling Remote Access #519

Open
lacojim opened this issue Oct 2, 2023 · 8 comments
Open

Support for disabling Remote Access #519

lacojim opened this issue Oct 2, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@lacojim
Copy link

lacojim commented Oct 2, 2023

Would it be possible to add support for disabling Remote Access? The Kasa app once had this feature for each device but was apparently removed at some point. Now all my devices are Remotely accessible and I do not want this, but I see no way to disable it. Simply blocking INet access in the router causes them to constantly request a new DHCP address while blocked, but work fine when not blocked.

@rytilahti
Copy link
Member

rytilahti commented Oct 4, 2023

This is implemented but untested and not implemented in the cli tool, see

def disconnect(self):
"""Disconnect from the cloud."""
return self.query_for_command("unbind")
.

The cli tool allows executing raw commands, so you could try the same command like this (also documented here:

kasa --debug --host 192.168.xx.xx raw-command cnCloud unbind

As my test device is not added to any cloud account, I'm just getting this:

Got error: SmartDeviceException("Error on cnCloud unbind: {'err_code': -8, 'err_msg': 'not bind yet'}")

Please report back if it works (and what was the response), that would help to improve and add this functionality to the cli tool, too.

@rytilahti rytilahti added the enhancement New feature or request label Oct 4, 2023
@lacojim
Copy link
Author

lacojim commented Oct 5, 2023

I have tried this on three different devices. It certainly returns a boat load of information for sure!

Device 1 - HS103 (US) HW 2.1 FW 1.1.4 Build 210409 Rel.113427
DEBUG:kasa.protocol:192.168.254.218 >> {"cnCloud": {"unbind": null}}
DEBUG:kasa.protocol:192.168.254.218 << {'cnCloud': {'unbind': {'err_code': 0}}}

Device 2 - EP25 (US) HW 1.0 FW 1.0.10 Build 230423 Rel.134727
DEBUG:kasa.protocol:192.168.254.233 >> {"cnCloud": {"unbind": null}}
DEBUG:kasa.protocol:192.168.254.233 << {'cnCloud': {'unbind': {'err_code': -24, 'err_msg': 'no reply from server'}}}
Got error: SmartDeviceException("Error on cnCloud unbind: {'err_code': -24, 'err_msg': 'no reply from server'}")

Device 3 - HS105 (US) HW 1.0 FW 1.5.6 Build 191114 Rel.104204
DEBUG:kasa.protocol:192.168.254.215 >> {"cnCloud": {"unbind": null}}
DEBUG:kasa.protocol:192.168.254.215 << {'cnCloud': {'unbind': {'err_code': -21, 'err_msg': 'cloud send cmd failed'}}}
Got error: SmartDeviceException("Error on cnCloud unbind: {'err_code': -21, 'err_msg': 'cloud send cmd failed'}")

Looks like Device 1 maybe worked. Device 2 and 3 both failed most likely because they are presently being blocked by Pi-Hole. This suggests they need to unlink from the cloud itself so access may be required for this to work. I will remove this block and attempt this again later today. A bit short on time right now.

EDIT Running this command again on Device 1 returns this:
Got error: SmartDeviceException('Error on cnCloud unbind: {'err_code': -43, 'err_msg': "Device hasn't bound to any account yet"}')
So apparently the older FW doesn't need cloud access to unbind, but these newer firmware versions appear to need it.

Thanks!

@lacojim
Copy link
Author

lacojim commented Oct 5, 2023

Okay, so while this app did report on Device 2 and 3 the cloud error above, it still actually worked. After I removed the block, the two devices that seemingly failed, were indeed unbound. Brilliant!! I have ran this now on 17 devices and it worked on all of them. Thank you! I saved all the output logs for each device. If you want to look at them, please let me know.

@rytilahti
Copy link
Member

Thanks for reporting back and glad it worked! I'd guess that the device resets itself into a state where it cannot be remotely controlled, but it still tries to inform the server (e.g., to allow removing the device from server-side device list) about the fact.

Let's keep this issue still open until the cli tool has a way to manage cloud settings.

@lacojim
Copy link
Author

lacojim commented Oct 7, 2023

Interesting thing to note. Even though my devices are all unbinded to the cloud, they STILL call home. However, it does not now cause them to reset or do a dhcp renew as before, even with the block re-enabled in Pi-Hole. I have been watching them in Wireshark.

@lacojim
Copy link
Author

lacojim commented Oct 11, 2023

Also interesting to note: After a few days, my Kasa phone app now has zero devices. It wants me to add them to the cloud to become available locally. Damn dirty apes! I mean Apps! :) So it looks like going forward (I still have 3 power monitoring switches I have not yet added), it looks as though I have to add them via the app, to the cloud, then use the command line to unlink them. What a load of crap this has become! More research needed.

EDIT: I am going to factory reset a few devices and see if they again get added locally before adding any new devices. This is most peculiar to say the least.

@rytilahti
Copy link
Member

Is "offline" provisioning not working for those devices? I haven't tested it with all of my devices, but it worked fine with my most recent additions (KP115, KL130, EU versions).

@lacojim
Copy link
Author

lacojim commented Oct 11, 2023

I'm not really sure what's going on. The app shows zero devices initially, but when I click on Add, it asks if I want to "Choose from discovered devices (17)", so it knows they are present. If I then tap on this, it says "Discovered Devices: Please add the unlinked devices to your Kasa account so you can access more features thought the Kasa app." and it then shows me all all my devices, but this is ONLY to Link them to my account, not to control them.

It's not a big deal as I only use the app to add new devices anyway. I control them all via Home Assistant which continues to see and control them all just fine.

I just added a new EP25(US) smart plug. It immediately wanted to do a firmware update once added and I could not get it to go back from this page. I killed the app, restarted it and the device now shows up as a local device. It is presently running sw_ver': '1.0.6 Build 210928 Rel.185924'. It wants to update the device to 1.0.10 Build 230423 Rel 134727. The Remote Control Button is currently present under the device settings for now, and turned off. I wonder if it will still be there if I update it?

EDIT: Did the FW update and to my surprise the Remote Control button is still present.

Also, I believe the app dropping my existing devices is most likely a bug in the Kasa app and certainly has nothing to do with python-kasa. I will just simply reset and re-add them at some point.

Edit2: Just reset and re-added an older device (HS103). Now the EP25 I just added above disappeared and the newly reset device is the only one showing. If I disconnect my phone from WiFi and run the Kasa app, no devices show as expected. But whenever I go back onto the WiFi, still no devices. This is most certainly a Kasa app bug. I will remove and reinstall it later this evening and see if that fixes it.

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

No branches or pull requests

2 participants