TP-Link Support

Questions and comments specific to a particular plugin should go here.
fuqit3
Posts: 16
Joined: Sat Mar 04, 2017 5:22 pm

Re: TP-Link Support

Post by fuqit3 » Sun Jun 03, 2018 9:09 pm

I know you took down the plugin but was wondering if you know an alternative or if I can still get it someplace. All I need is a way of turning on or off a smart plug I don't have any hardware yet so if there's something that you know of that will work, please let me know
thanks

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Sun Jun 24, 2018 4:08 am

OK I wanted to let everyone know. i am going to head out to my workshop to put together a test rig and get the ball rolling with this plugin. I am sorry for the delay. To many things on my plate. I should have a working version in the next day or so (hopefully) I fell asleep for a few hours earlier so that means i will be up all night. So i should be able to get a good 8 hours of uninterrupted coding time.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Mon Jun 25, 2018 1:14 am

ok sorry about the delay. I am still working on it. I have a working back end. I was going to add the cloud scheduling to the plugin, I do not see the point since you can use EG to schedule the devices. so I am thinking I am going to skip that bit of it. it is taking longer then I thought it took me a whole to remember where I had left off. There are still a few more things i need to do but it is shaping up pretty good.
If you like the work I have been doing then feel free to Image

Flyingsubs
Experienced User
Posts: 127
Joined: Sat Dec 29, 2012 11:26 pm

Re: TP-Link Support

Post by Flyingsubs » Wed Jun 27, 2018 12:47 am

kgschlosser wrote:
Mon Jun 25, 2018 1:14 am
ok sorry about the delay. I am still working on it. I have a working back end. I was going to add the cloud scheduling to the plugin, I do not see the point since you can use EG to schedule the devices. so I am thinking I am going to skip that bit of it. it is taking longer then I thought it took me a whole to remember where I had left off. There are still a few more things i need to do but it is shaping up pretty good.
Awesome, thank you! Let me know if you want me to test any builds.

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Wed Jun 27, 2018 6:38 am

ok plugin is up. attached to the first post.

I was only able to test this with a smart switch all functions associated with that device seem to work properly.

please report errors with a screen shot and an exact way of replicating the problem.


I also added a nice little feature to this plugin. the setting of the location of the device you are able to enter the address and it will get the data that is needed to populate the latitude and longitude on the device. it also will use that same latitude and longitude when displaying the device information to grab the address. so that's a pretty cool thing

another bonus feature
I also setup the plugin to be multi network card compatible. so in the off chance someone has 2 network cards and the networks for each card are separated and the user has devices on both networks it will discover all devices.

and again sorry for the delay on this. I do try to provide a means to access all aspects of a device i am creating a plugin for. and with this device and the fact that the API is closed (meaning no docs) and has to be entirely reverse engineered, it gave an added complexity to it. There are still features I am going to be adding I think I will add the cloud scheduling for sake of completeness. I want to make sure the current feature set works properly.

There was an already existing python library for this but the authors were not so receptive to any additions/changes and they also dropped support for python 2 so I ended up rewriting the whole library in a manner that would allow for new devices to be added easily and keeps the code organized by device model instead of simply having 3 device types and having to patch the code when a new device is released. The latter makes for a very large mess after a bunch of devices comes out and they have changes made to the communication that does not conform to any of the other devices. They were also against the use of singletons or any kind of an automatic discovery to device class association. A singleton means that there can only be one instance of a device even if 2 complete unrelated pieces of code with no attachment to each other ask for a specific device the object that gets returned is the same for both of them. so any changes to a device on one block of code will also get changed in the other. so it eliminates any possibility of conflicting data. as an example if one piece of code tells the device to toggle the state and another block of code does the same then the light won't go completely bonkers not knowing what to do. I am going to make this thread safe and launch a thread when changes to a device are made so that it doesn't slow up EventGhost at all. The command structures that have to be sent back and forth do have an impact in performance. even tho it is not a whole lot if you stacked all the lights into one macro for an all on/off and there are 40 devices it would take a bit to complete.
If you like the work I have been doing then feel free to Image

Flyingsubs
Experienced User
Posts: 127
Joined: Sat Dec 29, 2012 11:26 pm

Re: TP-Link Support

Post by Flyingsubs » Wed Jun 27, 2018 1:26 pm

Thank you so much! I tested with one smart switch and its working!!

I've noticed only one minor bug which in the list when I select a light, it shows one and keeps repeating the whole list. I'll send a screen shot later when the downstairs TV is free. I noticed as well for the Light Switch on/off, it takes a second or two to turn on. I'm not sure that's related to your last paragraph in terms of performance.

-Flyingsubs

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Wed Jun 27, 2018 7:29 pm

any errors you come across i will fix them. no worries.

I do want to mention this was made possible by a donation of a TPLink HS200 (switch) by Flyingsubs. So anyone that uses this plugin please thank him for making this possible


I also wanted to let everyone know how involved this plugin is. there is almost 5000 lines of code that is another reason why it took a little while to write.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Thu Jun 28, 2018 8:14 am

I have found a really nasty bug it causes an infinite loop. I would recommend discontinuing use of the plugin. But at the very least DO NOT TURN ON DEBUGGING. it will fill your HDD over several hours.

I am working on fixing the issue i should have a working version in the next few hours.

I also hope to have some new actions
anti theft action
schedule action
timer action
access point action


I also found a way to daisy chain commands into a single send /receive, and I am going to cache data that is persistent this will speed up device communications greatly.

we will see what i can finish up.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Thu Jun 28, 2018 3:23 pm

OK I wanted to let you all know what I am doing over here.


I am changing the whole plugin to use the device id in the actions instead o the device name. this is because the device name can be set from a source other then EG. so it is dynamic and can break an action that you have in your tree.. using the device id will not change so no matter what you have the name set to it will work.

If using an action in a script. you have the option of passing the device name, the device id or the ip address of the device. This will be very helpful for you script kiddies.

I have also changed the geolocation and how it functions. it is not going to populate the fields in the Set Location action with the data the device has set. it will only do this when you choose a device. So be sure to enter the data in the fields after you choose the device and not before. because it will change it on ya if you fill it all out then change the device. The only time it will not populate these fields is if the action has already been set up. it will use the information that was keyed in when you added the action. When it auto populates the fields it is going to populate all fields including the latitude and longitude. If you change something in the address fields you will need to delete the data in the latitude and longitude fields. By default when running the action it will always use the latitude and longitude fields as the primary. this is because this is what the device natively uses and a call to get the geolocation is not necessary. It will only use the address information if either the latitude or the longitude field is blank.

I finished up coding the whole backend for the schedules and anti theft as well as the timer. i have to add the actions.

There was an error in the device time code which i have fixed.

I also had to code in a mechanism to set the time on a device if the device errors with "time not sync" I found that I was unable to resolve this problem by using the Kaza app. Even tho i entered the location and the time zone using the app it would not sync the device time. So upon discovery of any device if that error exists this plugin will correct it. Ya gotta love having to fix device problems for the manufacturer of the device. So if anyone else has experienced this issue and knows how to get it working from the Kaza app please let me know. because i really feel stupid not being able to figure this out. If it is some dumbass sequence of things that has to be done then the programmers at TP Link are idiots and i don't feel stupid. I am thinking the latter is the case.

I find i really dumb that it requires you to have security enabled on your wifi network. I am going to see if i can find a way around this. Because i have other mechanisms in place to keep others off my network. I have no need to slow my wifi connection as much as 50% because of enabling security. I feel this is the choice of the user and TP Link has no right to dictate what you have to have running in the form of security. It is not their responsibility to make sure that other people are not on your network accessing your lights. that is the responsibility of the user. I am going to send them a nice little email regarding that.

so it is going to be a little while longer. I have a bunch of other things to do today. and I want to finish up what I am working on before i release the next version. so it will probably be this evening when the release is made.

The reason i decided to add the scheduling, anti theft, and timer is because the data for this is not stored on their cloud servers. it is actually stored on the device. I see an importance to this in the event of an EG crash or a PC crash the devices can still function as normal.

I am going to add 3 additional actions. all on, all off and all anti theft. these actions will do all switches and all bulbs and the user will be able to optionally add plugs.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Tue Jul 03, 2018 4:19 am

I haven't forgotten this plugin. I have been working on it. my work has slowed due to Family coming in for the 4th of July. Which i did not know about until a week ago. I had already begun a full suspension replacement on my Wife's car in which i ran into some parts issues. so I am down a vehicle.

Sometime I think that the man upstairs likes to watch me run around like a loony tune, he throws in something extra special. This morning I had a very large deer 10 or 12 point run right into the side of my car while i was doing 50 mph. Now mind you this is a small 2 seater convertible. the deer pushed the car when it hit the drivers door. glass everywhere top crushed hood bent front fender bent rear quarter panel is toast as well. trunk lid is tweaked. the whole general body of the car the top of it has been pushed to the passenger side.

That deer was running full throttle. i was on the tele with my mom and when i saw it coming the only thing i said was ahhh shit!!! then my mom heard the crash. I kept on driving until i could get off the main road. deer got up but i am sure he has one hell of a headache (will probably die in the woods).

So now I am down to 0 cars have to get family from the airport in just over a day, Still have to get the wife to work , haven't finished organizing the house.

and oh did i mention one of the relatives kids is autistic and gets into everything and seem to like sharp objects. Now remember my house is under construction.

I am at the point of simply throwing my hands up and saying fuck it.

Oh yeah and my drivers door wouldn't open so I had to "dukes of hazzard" it out of the broken window. I am 43 years old and that window was just big enough for me to fit out of it. But that was one hell of a chore, i don't bend like i used to. tomorrow i get to climb back in it to drive my wife to work. I spent 14 hours today working on the wife's car in 85 degree heat. Which doesn't sound all that hot, but I am at 8500 foot elevation so it may as well have been 120 degrees in the sun. needless to say i am pretty crispy.


Welcome to a day in the life of Kevin.

So i want to let you know it will be a little bit longer on this plugin.

"If life wasn't full of adversity... It'd be boring" --K
If you like the work I have been doing then feel free to Image

Flyingsubs
Experienced User
Posts: 127
Joined: Sat Dec 29, 2012 11:26 pm

Re: TP-Link Support

Post by Flyingsubs » Mon Jul 23, 2018 6:23 pm

We're you able to take a look and fix the nasty bug? Anything I can do to help?

-Flyingsubs

User avatar
kgschlosser
Site Admin
Posts: 4803
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: TP-Link Support

Post by kgschlosser » Thu Jul 26, 2018 4:27 am

Yeah i got the nasty bug sorted out. I am adding to the functionality of the plugin. But I am also changing how queries are done against the devices. so this way if a polling loop is set the data gets cached for one. but for 2 instead of making a whole mess of transactions back and forth to check the various elements for changes i have figured out how i can stack everything into a single transaction. This is going to greatly reduce the amount of time it takes to generate events if something has changed. but also reduce CPU load. network operations are expensive to do. so if i can make 30 transactions turn into a single one, this is what I am going to do. making this change requires rewriting a pretty good sized chunk of the code. I also noticed that a problem could occur with the plugin. I was tracking devices by IP Address then i realized that there is no setting to make the devices have static IP's so if a router goes down that is providing the IP's and it gets rebooted after a leas term has expired the IP addresses of the devices will change and performing actions on a device wouldn't marry correctly to the device. I had done the legwork to account for this in the actions but not in the assigning of the different device types. so even tho it does a search for the correct device id the actual container that represents the device is going to have the wrong abilities attached to it. this is a pretty tricky one to work around because of how the discovery process works using UPNP. the devices seem to respond pretty quickly but that may not always be the case. so the devices have to be able to be dynamically changed. in order to do this threading locks have to be put in place so data is not being changed at the same time. this can lead to corruption. it's very complicated to say the least. I want to make sure that I do not have a repeat of the last version would could have crashed a computer.
If you like the work I have been doing then feel free to Image

Flyingsubs
Experienced User
Posts: 127
Joined: Sat Dec 29, 2012 11:26 pm

Re: TP-Link Support

Post by Flyingsubs » Mon Nov 26, 2018 4:43 pm

kgschlosser wrote:
Thu Jul 26, 2018 4:27 am
Yeah i got the nasty bug sorted out. I am adding to the functionality of the plugin. But I am also changing how queries are done against the devices. so this way if a polling loop is set the data gets cached for one. but for 2 instead of making a whole mess of transactions back and forth to check the various elements for changes i have figured out how i can stack everything into a single transaction. This is going to greatly reduce the amount of time it takes to generate events if something has changed. but also reduce CPU load. network operations are expensive to do. so if i can make 30 transactions turn into a single one, this is what I am going to do. making this change requires rewriting a pretty good sized chunk of the code. I also noticed that a problem could occur with the plugin. I was tracking devices by IP Address then i realized that there is no setting to make the devices have static IP's so if a router goes down that is providing the IP's and it gets rebooted after a leas term has expired the IP addresses of the devices will change and performing actions on a device wouldn't marry correctly to the device. I had done the legwork to account for this in the actions but not in the assigning of the different device types. so even tho it does a search for the correct device id the actual container that represents the device is going to have the wrong abilities attached to it. this is a pretty tricky one to work around because of how the discovery process works using UPNP. the devices seem to respond pretty quickly but that may not always be the case. so the devices have to be able to be dynamically changed. in order to do this threading locks have to be put in place so data is not being changed at the same time. this can lead to corruption. it's very complicated to say the least. I want to make sure that I do not have a repeat of the last version would could have crashed a computer.
Hey kgschlosser, were you able to make any updates to the plugin? I see on the first page of the thread that the plugin isn't posted.

Thanks,
Flyingsubs

Flyingsubs
Experienced User
Posts: 127
Joined: Sat Dec 29, 2012 11:26 pm

Re: TP-Link Support

Post by Flyingsubs » Mon Mar 04, 2019 1:21 am

kgschlosser has generously posted the plugin here: https://github.com/kdschlosser/EventGhost-TPLink

I tried taking a look at it myself and there are some errors that I can't fix since my python knowledge is limited. Anyone able to identify the errors? What I'm trying to do is make it so that I can use a new device HS220 which has the ability to dim. It seems like all the pieces are there in the plugin, but I can't solve the errors before modifying the plugin.


I commented out a few things but I can't see to get the devices to show up on the actions screen.


This is what I tried commenting out:

I commented out import Louie from smartdevices
Commented out TPLINK paragraph in smartdevices

I commented out a lot of the run(self) in the init file and put back

plugs=[],
bulbs=[],
switches=[],
other=[]

I think kgschlosser was redoing the run(self) method but didn't get all the way to get it to working. Any ideas?

Thanks!
Flyingsubs

fuqit3
Posts: 16
Joined: Sat Mar 04, 2017 5:22 pm

Re: TP-Link Support

Post by fuqit3 » Tue Mar 12, 2019 2:15 pm

I’ve got it working without the plugin using IFTTT. It was super easy to set up

Post Reply