Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I am running Python 3.9.4 under OSX and have installed python-kasa version 0.4.0.dev2 and using an ASUS RT-AC88U router
I have 3 Kasa devices currently connected on my network - KP115 and two HS105s

Discovery does not find any devices but I can reach the devices directly if I look up their IP addresses. Any ideas how to fix this?

Thanks in advance for any help!

Discovery does not find any devices:
My-MBP:~ home$ kasa discover
Discovering devices on 255.255.255.255 for 3 seconds

Devices can be reached directly:
_My-MBP:~ home$ kasa --host 192.168.1.111
No --strip nor --bulb nor --plug given, discovering..
== Garage freezer - KP115(US) ==
Host: 192.168.1.111
Device state: ON

== Generic information ==
Time:         2021-04-13 09:19:51
Hardware:     1.0
Software:     1.0.10 Build 201111 Rel.083419
MAC (rssi):   E4:C3:2A:33:0A:D6 (-34)
Location:     {'latitude': x, 'longitude': -x}

== Device specific information ==
LED state: True
On since: 2021-04-12 18:44:37.084805


== Current State ==
{'current_ma': 0, 'voltage_mv': 120277, 'power_mw': 0, 'total_wh': 2, 'err_code': 0}_
You must be logged in to vote

Replies: 3 comments · 19 replies

Comment options

Is your laptop in the same network as the devices? The discovery uses broadcast datagrams, so depending on how your network looks like the discovery requests may be sent out using wrong interface.

You could try kasa --target 192.168.1.255 discover to see if that works, it may or it may not do so.

You must be logged in to vote
14 replies
@jazzjohn27
Comment options

That makes some sense to me. Thanks.
Can kasa python use unicast to control the plug if the ip is given?

@kirichkov
Comment options

--host IP_ADDRESS should do the trick

@jazzjohn27
Comment options

Please show me the correct syntax for using --host IP_ADDRESS or point to a doc that explains it. All I need to do is turn the plug on and off.
Below is what I tried. It works to print the status, but plug.turn_on() produces runtime warnings and doesn't turn the plug on.

import asyncio
from kasa import SmartPlug
from pprint import pformat as pf
plug = SmartPlug("192.168.0.20")
asyncio.run(plug.update())
print("Hardware: %s" % pf(plug.hw_info))
print("Full sysinfo: %s" % pf(plug.sys_info))
print("Current state: %s" % plug.is_on)
plug.turn_on()
@rytilahti
Comment options

As all actions are coroutines (defined with async def), you need to schedule their execution. In your example, executing asyncio.run(plug.turn_on()) should do the trick! To do the same inside another coroutine, you need to use await like await plug.turn_on().

@jazzjohn27
Comment options

OK, this code runs on my network: Win 10 computer on ethernet and the plug on WiFi.

In another location, same setup: Win10 on ethernet and the plug on WiFI. Program hangs. Note: the computer can ping the plug with no problem. But SmartPlug(IP) can't find it. Seems like it should if it uses unicast like ping does???


import asyncio
import time
from kasa import SmartPlug
from pprint import pformat as pf
f = open("IP.txt")
IP=f.readline()
print("IP.txt = ", IP)
plug = SmartPlug(IP)
asyncio.run(plug.update())
print("Hardware: %s" % pf(plug.hw_info))
print("Full sysinfo: %s" % pf(plug.sys_info))
while(True):
	asyncio.run(plug.turn_on())
	asyncio.run(plug.update())
	print("Current state: %s" % plug.is_on)
	time.sleep(1)	
	asyncio.run(plug.turn_off())
	asyncio.run(plug.update())
	print("Current state: %s" % plug.is_on)
	time.sleep(1)
Comment options

Did you ever find out why discovery wasn't working? It looks like the answer here was to just not use discovery and use the hardcoded IP address instead, but no one answered the original question of why you couldn't discover the IP addresses in the first place.

I too am able to connect to devices by IP address but can't seem to get discover() to return anything other than an empty dictionary.

You must be logged in to vote
2 replies
@ba2512005
Comment options

I'm running into the same issue, were you able to figure it out?

@neato5oh
Comment options

me 3

Comment options

This is interesting... I suddenly had this issue today on my Ubuntu server 24.04 box, both using this library via python as well as homebridge - no devices could be discovered. I was ultimately able to fix this using kasa --target 192.168.1.255 discover in CLI, await kasa.Discover.discover(target='192.168.1.255', on_discovered=on_discovered_async) in my python apps, and adding the IP address to my "additionalBroadcasts" array in homebridge. I can also fix the python side by using await kasa.Discover.discover(interface='<my interface>'...) instead of specifying a broadcast target. I suspect something in a dependent or system package caused this, but I have no evidence of this.

Seems to be the same issue reported here ZeliardM/homebridge-kasa-python#245

You must be logged in to vote
3 replies
@ZeliardM
Comment options

@jasonlboggs Do you have your network segmented at all? Different WiFi for IOT and servers or other equipment? That is what ended up being the issue with the thread you quoted from my plug-in.

@jasonlboggs
Comment options

I have several access points, but this was working correctly without specifying the interface with the exact same setup.

@ZeliardM
Comment options

Do you remember if the python-kasa version updated and there may have been changes in the discovery process?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
9 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.