FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

KS240 gets discovered but will not authenticate · Issue #749 · python-kasa/python-kasa · GitHub

Repository navigation

KS240 gets discovered but will not authenticate #749

Closed

Description

Got a brand new KS240 Ceiling Fans switch and dimmer. Discovery works as all the other KASA devices. It immediately prompted for firmware upgrade (which I did and that may have been my mistake). Then I attempted to add to the HA Integration and cannot authenticate. All other KASA dimmer switches and plugs work great. https://www.tp-link.com/us/support/download/ks240/

Activity

  1. rytilahti commented on Feb 13, 2024

    Member

    Do you see any errors in the logs? It might be that we need to do some small adjustments into this library, so could you please clone this repository, and run python -m devtools.dump_devinfo --host <address>?

    It will perform several queries on the device and output a JSON file containing the results from those queries.

    The file is anonymized, just like the one above, and it would be great if you would create a PR to add it to our fixture collection to help with future development.

  2. sdb9696 commented on Feb 13, 2024

    Contributor

    The output of running kasa —username YOURUSERNAME —password YOURPASSWORD could also be helpful.

  3. briadelour commented on Feb 13, 2024

    Author

    Getting the following problems:

    python -m devtools.dump_devinfo --target 255.255.255.255
    No --host given, performing discovery on 255.255.255.255. Use --target to override.
    Detected 4 devices
    Testing component_nego call ..Unable to query the device due to an authentication error: Error logging in: 192.168.50.119: LOGIN_ERROR(-1501)
    Unclosed client session
    client_session: <aiohttp.client.ClientSession object at 0x00000158DC2D7830>
    Unclosed connector
    connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x00000158DC28F890>, 1789745.281)]']
    connector: <aiohttp.connector.TCPConnector object at 0x00000158DC2D7860>
    

    Then if I try at the host instead of the network I get:

    python -m devtools.dump_devinfo --host 192.168.50.119 --username myusername --password mypassword
    
    Host given, performing discovery on 192.168.50.119.
    Got error: [WinError 1234] No service is operating at the destination network endpoint on the remote system
    Traceback (most recent call last):
      File "<frozen runpy>", line 198, in _run_module_as_main
      File "<frozen runpy>", line 88, in _run_code
      File "C:\Users\admin\python-kasa\python-kasa\devtools\dump_devinfo.py", line 443, in <module>
        cli()
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\asyncclick\core.py", line 1205, in __call__
        return anyio.run(self._main, main, args, kwargs, **opts)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\anyio\_core\_eventloop.py", line 73, in run
        return async_backend.run(func, args, {}, backend_options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\anyio\_backends\_asyncio.py", line 1991, in run
        return runner.run(wrapper())
               ^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 118, in run
        return self._loop.run_until_complete(task)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 685, in run_until_complete
        return future.result()
               ^^^^^^^^^^^^^^^
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\anyio\_backends\_asyncio.py", line 1979, in wrapper
        return await func(*args)
               ^^^^^^^^^^^^^^^^^
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\asyncclick\core.py", line 1208, in _main
        return await main(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\asyncclick\core.py", line 1120, in main
        rv = await self.invoke(ctx)
             ^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\asyncclick\core.py", line 1485, in invoke
        return await ctx.invoke(self.callback, **ctx.params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\asyncclick\core.py", line 824, in invoke
        rv = await rv
             ^^^^^^^^
      File "C:\Users\admin\python-kasa\python-kasa\devtools\dump_devinfo.py", line 187, in cli
        device = await Discover.discover_single(host, credentials=credentials)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\admin\python-kasa\python-kasa\kasa\discover.py", line 404, in discover_single
        raise TimeoutException(f"Timed out getting discovery response for {host}")
    kasa.exceptions.TimeoutException: Timed out getting discovery response for 192.168.50.119
    
  4. rytilahti commented on Feb 13, 2024

    Member

    Thanks for testing and the logs!

    Unable to query the device due to an authentication error: Error logging in: 192.168.50.119: LOGIN_ERROR(-1501)

    You need to pass --user and --password for this command too, this just says that the device did not accept the credentials. Would you mind verifying those just in case?

    As running the command should not error out like that on device reported errors, there's also a bug that should be fixed :-)

    Got error: [WinError 1234] No service is operating at the destination network endpoint on the remote system

    This is ERROR_PORT_UNREACHABLE according to https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--1000-1299- . Alas, I'm not sure where the issue lies here, but it could be that Windows needs some special handling for the new discovery protocol implementation.

    Now, these do not explain the issues you have with the HA integration, or are you running Home Assistant also on Windows? If so, that's very brave and let's hope we can figure out how to fix these issues!

  5. briadelour commented on Feb 13, 2024

    Author

    Nope I'm running on a pi. But it was a Windows issue from where I was getting the testing login error.

    However I was able to get the json. Thanks for the help. I hope this resolves it.

    KS240(US)_1.0_1.0.5.json

  6. sdb9696 commented on Feb 13, 2024

    Contributor

    Is it still not working in HA when you enter the right username and password after pressing “reconfigure”?

  7. briadelour commented on Feb 13, 2024

    Author

    It does not work in HA. I get a Failed to Connect.

  8. sdb9696 commented on Feb 13, 2024

    Contributor

    Can you delete it from HA and try re-adding it?

  9. briadelour commented on Feb 13, 2024

    Author

    I've deleted all 7 of my kasa devices and when I rediscover I can add them all back in but the 8th is this KS240 and it won't configure.

  10. sdb9696 commented on Feb 13, 2024

    Contributor

    Are you getting the login prompt in HA asking for a username and password?

  11. briadelour commented on Feb 13, 2024

    Author

    Yes and I'm entering the same credentials I used for the other devices.

  12. sdb9696 commented on Feb 13, 2024

    Contributor

    Can you connect to it via the Kasa or TAPO app?

  13. briadelour commented on Feb 13, 2024

    Author

    Can you connect to it via the Kasa or TAPO app?

    Yes I can add it to both KASA and TAPO Apps, but not HA.

    I can see the device in the debug log attempting to make the handshake immediately followed by a error code. But it does see the details for the KS240 in the HA logs.

  14. sdb9696 commented on Feb 13, 2024

    Contributor

    Ok we have some thoughts from the json. Will revert back, thanks for all the responses.

  15. 16 remaining items

  16. pm0u commented on Feb 18, 2024

    Both work 🎉 but seems to be on a 0-100 scale for brightness on the bulb, 1 didn't really do anything. No commands seem to work without setting a child.

    $ kasa --host 192.168.0.191 command --child XXX set_device_info '{"brightness": 50}'
    Selecting child XXX from <DeviceType.Bulb at 192.168.0.191 - update() needed>
    {"set_device_info": null}
    

    Settings brightness: 0 turns the bulb all the way off however the light on the switch is still on (I guess the light is on with 0 brightness?) until I set device_on False.

    fan_speed_level seems to adjust the fan speed on the predefined scale of 1-4 however does not alter the power state of the fan. using device_on True/False I can then turn it on or off and it will turn on at the level I set before turning on. While on, fan speed changes take effect.

    In short - both behave similar but not quite the same. If the light is off, setting a brightness state will turn it on. If on, setting brightness 0 will reduce the brightness completely but not turn off the switch. If the fan is off, setting a speed will not turn it on. Once turned on the set fan speed is used. Similar to the bulb, once on setting fan speed to 0 will stop the fan but will not turn off the switch.

  17. rytilahti commented on Feb 18, 2024

    Member

    Woohoo, great! So it's indeed working (somewhat) as expected. Different devices may have different behaviors, especially when it comes to what's the range of accepted values and what happens on changes.

    Feel free to give the linked PR a try, it adds the implementation for both "brightness" and "fan_control", you should be able to control them using feature command:

    kasa --host 192.168.0.191 feature  # lists all features, including those of the children.
    kasa --host 192.168.0.191 feature --child <child id>  # lists child features
    kasa --host 192.168.0.191 feature --child <child id> brightness  # access a single value
    kasa --host 192.168.0.191 feature --child <child id> brightness 100  # set the value
    
  18. pm0u commented on Feb 18, 2024

    Listed commands all seem to work as expected from what I can tell. Is there a way to set on or off using this new CLI? I can set the fan speed but am unable to turn the fan on aside from the previous suggestion using command / parameter syntax set_device_info '{ "device_on": True }'. I tried targeting the child fan entity and using fan True but I got an error that AttributeError: 'FanModule' object has no attribute 'turn_on' and couldn't seem to see any attribute to toggle the dimmer (since 0 does not fully turn it off)

  19. rytilahti commented on Feb 19, 2024

    Member

    Ohh, the fan on/off not working was a bug which is fixed now, but that probably should be removed if we go with a generic on/off solution...

    As a temporary solution, I added a feature called state that allows turning things on and off, the name might change before this gets merged so keep that in mind if you are using this already.

  20. pm0u commented on Feb 19, 2024

    gotcha - yep, fan on/off works now. Not planning to use it until it's finalized so no worries. Not sure how to use state ? I tried setting state False but get No feature by name state when I try to turn off the light. Any commands other than feature don't seem to like the --child param, so that seemed like the place to use it?

    kasa --host 192.168.0.191 feature --child XXX state False
    Targeting child device XXX
    No feature by name state
    

    I think there should probably be some way to on/off the light (similar to the fan) as otherwise there is an LED on on the switch for the entity that when tapped, will change things to an "OFF" state. A unified solution seems like it would make sense to me as well, the HS2xx dimmers I have similarly have a brightness level and an on/off state

  21. rytilahti commented on Feb 19, 2024

    Member

    Hmm, I think I messed up the branching somehow while working on multiple at the same time. I just force-pushed an update which should fix that. If not, please paste the output from the feature command here as I can only guess what you are seeing there.

    The unified solution will come, but all of this is very new code w/o proper tests and testing, and should rather be considered a proof-of-concept for the time being :-)

    edit: created #769 so that it won't get forgotten.

  22. pm0u commented on Feb 19, 2024

    With the updated branch, everything seems to be working!

    And of course, I bought this switch close to release expecting that open source support could be awhile. Happy to help if I can, I'm not much of a py dev though :)

  23. bmmiller commented on Feb 26, 2024

    What's the general timeline for something like this making it's way into HA without the need for manually adding?

    I'm running my instance in containers and the TP-Link integration appears to get pulled in once a device is added maybe but this would be my first Kasa device so nothing seems visible at the moment.

  24. rytilahti commented on Feb 26, 2024

    Member

    We are currently doing some heavy refactoring on the library (#783) and the homeassistant integration to allow supporting more features out-of-the-box, with the plan to get it hopefully done in time for the 2024.4 release of homeassistant. If you want to follow the progress, you can subscribe to notifications for home-assistant/core#111151 :-)

  25. bmmiller commented on Feb 26, 2024

    We are currently doing some heavy refactoring on the library (#783) and the homeassistant integration to allow supporting more features out-of-the-box, with the plan to get it hopefully done in time for the 2024.4 release of homeassistant. If you want to follow the progress, you can subscribe to notifications for home-assistant/core#111151 :-)

    Appreciate the update. Is there any way to be able to take the changes from this branch and manually apply them as a custom_component for the time being?

    Maybe even something as simple as updating the manifest to point to a different tagged release of the library maybe?

  26. rytilahti commented on Feb 26, 2024

    Member

    No, the changes are so pervasive that there is no straight-forward way to do that in any practical sense.

  27. gmayfield09 commented on Mar 26, 2024

    Yeah, I'm having the same issue. It asks to authenticate but returns "PARAMS_ERROR(-1008) for method: get_device_usage" I have confirmed that my username and password are correct.

    Running on a pi 4
    Core
    2024.3.3
    Supervisor
    2024.03.0
    Operating System
    12.1
    Frontend
    20240307.0

  28. alokj85 commented on Apr 3, 2024

    Having similar issue. Getting this error on trying to authenticate
    Translation Error: The intl string context variable "error" was not provided to the string "Connection error: {error}"

  29. zaileion commented on Oct 29, 2024

    I am relatively new to HomeAssistant. I am trying to get my TPLink KS240 to connect to HomeAssitant. It shows up as a new available device in Settings, Devices & Services, Discovered but when I try to "Configure" this device it asks for credentials. I've already added over a dozen TPLink devices and have already entered my account credentials. However, I did try to enter the credentials when it requests them for the new TPLink KS240 (the credentials I enter are correct) but HA kicks back an error stating invalid credentials. I assume this is due to the fact that is is a new device on the market but wanted to find out if anyone has been successful in adding the Kasa KS240 to HomeAssistant and how they did it.

    I posted the same message here:
    #839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL