kj831ca / KasaSmartPlug

Arduino Library for TP Link KASA Smart Plug
MIT License
12 stars 5 forks source link

Three suggested improvements #1

Open roblatour opened 1 year ago

roblatour commented 1 year ago

First, thank you so much for writing and releasing this code.

In working with it I found a few potential improvements, which I have coded in for myself, and would like to share with you. These are;

  1. Added some support for KASA KS devices (or at least the KS230KIT 3 way dimmer switch)

  2. Broadcast scanning only identified about half my TP-Link KASA devices. However, individual scanning port by port identified many more

  3. Debug messaging was distracting in the log, so I included an option to turn it on or off at a high level

If you like, I can share with you the code for this, which you are welcome to integrate as you like. I am not doing pull requests but would be happy to share the code with you in case you have a better way of doing it or one that is more to your liking.

Please let me know if you would like this, and if so I can send it to you separately.

kj831ca commented 1 year ago

Thanks very much for the feedback. Yes, please share the code with me I would like to see how did you add the support for the other KASA devices and scanning port by port means.

Regarding for the UDP broadcast message, I found it works for me 90% of time and when the ESP32 could not detect some device on my local network my KASA phone app could not detect neither. But I only have 5 KASA devices in my house. Did you try to increase the scan timeout, currently it set to 1000 msec. (eg. kasaUtil.ScanDevices(3000); ).

roblatour commented 1 year ago

Great.

Yes, I did try increasing the threshold, up to 5000 ms; but it didn't help.

Here (in the attached zip file) is the code:

Of note, the broadcast scan found 7 or my devices, the individual port scan found 14.

Also, all my TP Link Kasa devices are on my network at IP address between 192.168.200.1 and 192.168.200.254 so that is why you will see the individual port scan set up in that way.

Please let me know if you would like any information.

Rob KasaSmartPlug.zip

plrfishing commented 1 year ago

First, BIG THANK YOUs to both of you for this ESP32 coding. I am observing same as roblatour in that I have 20 TP-Link Kasa switches and plug modules. The original by kj831ca will find between 6 and 8 of the devices while the roblatour version finds the 20 using the individual scans.

I also have EP10 and KP115 devices that are not currently included in the coding. I will attempt to dig into the coding to determine if these devices can be included. I am only moderately proficient with Arduino coding so I may or may not be successful.

mbmorrissey commented 1 year ago

Hi plrfishing, kj831ca, et al.,

Have you had any luck with the KP115, or know of anyone who has? Is it clear if it is just a UK version of the HSXXX devices?

Michael

plrfishing commented 1 year ago

Yes, the code is able to access KP115 and EP10 devices once I added these devices to the KasaSmartPlug.cpp file @ "if ( IsStartWith("HS",model) || IsStartWith("KS",model) || IsStartWith("EP",model) || IsStartWith("KP",model) )". I bought and using the KP115 in the US.

mbmorrissey commented 1 year ago

Great - thanks for the tip - I'll order a KP115 and give it a try!

plrfishing commented 1 year ago

Good luck. The issue with this code is that it will only locate the first 5 to 8 devices. Seems the response from the broadcast does not get responses from all my 22 devices on-line at this time. But when it identifies the KP115 it will control and collect relevant information.

From: mbmorrissey @.> Sent: Sunday, December 25, 2022 3:24 PM To: kj831ca/KasaSmartPlug @.> Cc: plrfishing @.>; Manual @.> Subject: Re: [kj831ca/KasaSmartPlug] Three suggested improvements (Issue #1)

Great - thanks for the tip - I'll order a KP115 and give it a try!

— Reply to this email directly, view it on GitHub https://github.com/kj831ca/KasaSmartPlug/issues/1#issuecomment-1364740228 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ANC4N7MSAFHDHHWU2C4WA2DWPC3OJANCNFSM6AAAAAARIE2J2U . You are receiving this because you are subscribed to this thread. https://github.com/notifications/beacon/ANC4N7NTANKY7IJH2MWXN2TWPC3OJA5CNFSM6AAAAAARIE2J2WWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSRLBEII.gif Message ID: @. @.> >

viiartztoo commented 1 year ago

Hi, I'm trying to figure out how to test if a specific switch is on or off so as to make a decision in my code and act accordingly. How can I do that? Could you provide an example, please? If using: KASASmartPlug *targetSwitch = kasaUtil.GetSmartPlug("AC in Bedroom1");

how do I test for the state? Could the command targetSwitch->QueryInfo()return a 1 if "on" or a 0 if "off"?

By the way, the library works with Kasa HS-100 and HS-110 Smart switches as well, which is what I have and use.

roblatour commented 1 year ago

please take a look at the code I posted on Github, where it says "Query specific device" KasaSmartPlug.zip perhaps that will help ....

viiartztoo commented 1 year ago

Thank you! I found the problem; Don't code when you're tired!!! I mistyped 'State' instead of 'state':

KASASmartPlug *targetSwitch = kasaUtil.GetSmartPlug("Kids Room"); Serial.printf("\r\n State of sw is: %d",targetSwitch->State);

Which is why I was getting the error: 'class KASASmartPlug' has no member named 'State'

roblatour commented 1 year ago

:-)

Jch24 commented 1 year ago

great code. Now I can control my Kasa KP105. Unfortunatly, the TP-Link Tapo P110 energy meter sockes don't work with this code. Has anyone tryed to add the Tapo devices. They should be similar.