I’m having trouble getting a KP303 wifi outlet strip working with Mycodo.
First, I have used the Kasa app to get the power strip on my wifi. It’s connected, I can see the IP address from my router, and control the outlets with the app.
I successfully add it as an output in Mycodo, but when changing the default IP in the configuration, I get a red error message:
Error: Modify Output: Could not connect to Daemon: receiving: timeout
This is what the Mycodo logs show after trying to do this:
2021-10-11 15:06:26,636 - INFO - mycodo.outputs.kp303_552b40a3 - Initialized in 18367.8 ms
2021-10-11 15:06:44,692 - ERROR - mycodo.outputs.kp303_1dc6637a - Output was unable to be setup: Unable to query the device:
2021-10-11 15:06:46,722 - ERROR - mycodo.outputs.kp303_552b40a3 - Output was unable to be setup: Unable to query the device:
2021-10-11 15:07:31,404 - ERROR - mycodo.outputs.kp303_552b40a3 - Output was unable to be setup: Unable to query the device:
2021-10-11 15:07:46,484 - ERROR - mycodo.outputs.kp303_1dc6637a - Output was unable to be setup: Unable to query the device:
After some playing around I found I could get it working from the commend line. I SSH’d into the pi, and ran the following:
$ sudo pip install "python-kasa"
(install progress text omitted)
$ kasa discover
Discovering devices on 255.255.255.255 for 3 seconds
== TP-LINK_Power Strip_A8C4 - KP303(US) ==
Host: 192.168.1.16
Device state: ON
== Plugs ==
* Socket 'Plug 1' state: ON on_since: 2021-10-10 15:36:31.410375
* Socket 'Plug 2' state: ON on_since: 2021-10-10 14:34:51.411362
* Socket 'Plug 3' state: ON on_since: 2021-10-10 14:34:51.412301
== Generic information ==
Time: 2021-10-11 15:15:15
Hardware: 2.0
Software: 1.0.3 Build 201015 Rel.173920
MAC (rssi): C0:06:C3:3D:A8:C4 (-35)
Location: {location info removed}
== Device specific information ==
LED state: True
Childs count: 3
On since: 2021-10-10 15:36:31.453909
$ kasa --host 192.168.1.16 --strip --plug off
Turning off TP-LINK_Power Strip_A8C4
Upgrade to master seemed to go well. Once it finished I restarted the pi for good measure. Also unplugged the power strip and moved it to another room, in case that helped any ghosts lose it.
Unfortunately no change- it can intermittently switch the plugs on or off, but fails far more often than it succeeds.
Turning things on and off from the command line (as described in my first post) is still working, if that helps narrow things down.
Try downgrading your python-kasa library with the following commands, then restart the daemon and see if that fixes the issue.
cd ~/Mycodo && ./env/bin/pip uninstall python-kasa && ./env/bin/pip install python-kasa==0.4.0.dev4
I discovered that if you installed python-kasa to your system, this is likely the root of the issue. You will need to first uninstall your system package with the commands below, then run the above commands for good measure, so Mycodo can use the virtualenv version it has installed. To uninstall your system package, use this command:
sudo pip uninstall python-kasa
Explanation: version 0.4.0.dev4 and lower of python-kasa works with the module, however 0.4.0.dev5 and 0.4.0 causes it to break. If you install python-kasa to your system, it pulls the latest version (0.4.0) to install. Since Mycodo’s virtualenv is set to use system packages first before virtualenv packages, by installing a system package (0.4.0), you are preventing it from using the version the output module installed (0.4.0.dev4).
After uninstalling system package, and downgrading library to dev2 version, it’s not working at all. None of the plug status indicators ever change from “unconfigured”.
Thought I’d add an update for anybody fighting the same problem here.
I decided I’d start from a fresh Mycodo install, in case my experimenting had screwed anything else up. Found that the default python-kasa version that gets installed when first adding the power strip output (0.4.0.dev3) doesn’t work with my power strip, which is:
Thanks for the update. I put a comment in the KP303 module file in Mycodo not to update past dev4 (as a personal note if I ever modify the module) because it will break functionality for some hardware versions. A new module will likely need to be created for the latest library in order for it to work, however I’m not familiar enough with asyncio to know how to properly do that.