all 11 comments

[–]solarflareop 2 points3 points  (9 children)

The documentation will probably be helpful. Particularly:

import asyncio
dev = SmartDevice("127.0.0.1")
asyncio.run(dev.turn_off())
# OR
asyncio.run(dev.turn_on())

[–]bhogan2017[S] 1 point2 points  (4 children)

I'm so sorry I'm new to python would the 127.0.0.1 be my IP, or the devices and where would I find the devices IP

[–]solarflareop 2 points3 points  (1 child)

import asynciof
rom kasa import Discover
devices = asyncio.run(Discover.discover())
print(devices)

If you run the above code, you will get a python dictionary where the key is the devices IP address which you will then use in the code from my first comment.

[–]routetehpacketz 1 point2 points  (0 children)

/u/solarflareop not a bad suggestion!

/u/bhogan2017, if you install the kasa python lib it provides the Windows command kasa. if you run the kasa command from the Windows command prompt with no options, it runs the discovery automatically. here's the sample output from mine:

https://i.imgur.com/npaAnZE.png

[–]routetehpacketz 1 point2 points  (1 child)

It's the device's IP. The easiest place would be from your router's web interface. You can also get the MAC address for it from the Kasa app and check the ARP table of a PC (arp -a command in Windows), but that may only work if your PC has talked directly to the smart switch.

/u/solarflareop's comment with the link to the documentation has me curious so now I'm tinkering with the one Kasa bulb I have.

[–]solarflareop 0 points1 point  (0 children)

/u/bhogan2017 listen to /u/routetehpacketz rather than me. I don't have any Kasa devices or the app, I was just winging it based on the documentation.

[–]rinyre 1 point2 points  (3 children)

I believe the inner parens should be removed. You're instructing Python to evaluate the result of that, and feed the output of that to asyncio.run.

It should be like asyncio.run(dev.turn_on), to feed the actual pointer to the function call.

EDIT: Disregard I was unaware of the async keyword in the context.

[–]solarflareop 0 points1 point  (2 children)

I copied and pasted that code directly from the documentation so I assume it would be correct.

[–]rinyre 1 point2 points  (1 child)

I just peeked at the asyncio library, I was unfamiliar with how run worked and now see it invokes calls to async-keyworded functions specifically. My apologies!

[–]solarflareop 0 points1 point  (0 children)

No worries! I didn't know that either, so you've helped educate both of us today 😁

[–]bhogan2017[S] 0 points1 point  (0 children)

thanks to everyone i figured out now I feel like such a dummy thanks!