openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[tplinksmarthome] Add support for TP-Link HS107, HS300, KP200, and KP400 #5051

Closed Hilbrand closed 5 years ago

Hilbrand commented 5 years ago

HS107, HS300, KP200, and KP400 are devices with more than 1 outlet on the same device. The HS107, KP200 and KP400 all have 2, and the HS300 has 6 outlets. These outlets can be controlled separately and also have the ability to read power usage. Because of this they also have different control commands and require additional programming to be supported by the tplinksmarthome binding.

This issue report is also to report some work already has been done to add support for these devices. However since not all commands are known it's still a work in progress. And since I don't have either device I can't test this.

Anyone who has such a device and is interested in support for one of these devices please comment in this item.

Power outlet devices:

Open questions

The following questions remain open with regards to how the devices work:

  1. Is it possible to switch all outlets at once?
  2. Energy reading command needs to be given for each outlet (based on what I see with other implementations of support for these devices). Is is possible to get readings for multiple devices at once?
  3. Is is possible to get a total energy reading for all outlets combined?
  4. Can the status leds be switch on and off like with the plugs and switched?
babela commented 5 years ago

In regard to the open questions: 1) on the KP200 it is possible to switch both outlets at once. I have been using tasker to control a HS100 as described here: https://www.reddit.com/r/tasker/comments/52lvhq/how_to_control_a_tplink_hs100/

The same code when sent to the KP200 switches on/off both outlets. I have not figured out how to automate switching the KP200 outlets individually.

4) from the KASA app you can disable/enable the leds, so we should be able to do this programmatically as well.

Hilbrand commented 5 years ago

@babela do you mean the kp200 instead of the hs200?

babela commented 5 years ago

Sorry, yes, I meant KP200. I have updated the original comment. Separate from OpenHab, I am using tasker specifically to turn switches on/off when phone's charge is at a certain percentage to maximize the useful lifespan of the battery... The comment was to answer the question of turning on/off all sockets at once on the KP200. This does work via the same methods as the already supported devices. My OpenHab is currently down so I can not test via OpenHab currently. I have not figured out or found any info on controlling the KP200 individual sockets. It certainly is possible. Hoping to find time to do some packet sniffing in the near future.

c6fc commented 5 years ago

@Hilbrand I have a Kasa HS300 6-outlet power strip, and I'd be happy to help you test!

mythbai commented 5 years ago

I have a HS300 too, and would appreciate the support for it. I can help with the test as well.

c6fc commented 5 years ago

Another project seems to have had a lot of luck developing support for the HS300, and it's currently licensed MIT: https://github.com/plasticrake/tplink-smarthome-api/

The API documentation would probably shed a great deal of light on the questions you have about how the device behaves: https://github.com/plasticrake/tplink-smarthome-api/blob/master/API.md

Hilbrand commented 5 years ago

@babela, @mythbai and @c6fc I've create an initial version supporting HS107, HS300, KP200 and KP400. The binding is available through the Eclipse IoT marketplace and can thus be installed from PaperUI when the MarketPlace is enabled in PaperUI -> Configuration -> System with Maturity Level Beta.

Let me know what works and what doesn't. If you are experiencing problems please enable log level TRACE. In karaf console: log:set TRACE org.openhab.binding.tplinksmarthome. Make sure to disable it when done, otherwise you'll get lots of logging: log:set DEFAULT org.openhab.binding.tplinksmarthome

Hilbrand commented 5 years ago

I've made some changes. I changed the channels of the power outlet devices to channel groups. So it shows up nicer. If you had the experimental binding installed before this day you need to re-add the new things as the channels have changed.

MyRaceData commented 5 years ago

Hilbrand: Do I need to uninstall the 2.4 version before installing the beta? My gut is telling me yes and because it is probably 4am in the Netherlands I'm going to try that first. Let you know andy OK... it works! great work Hilbrand. I uninstalled the regular 2.4 binding first, then install the beta and HS300 popped up immediately in inbox. Each outlet has power (switch) power (number) energy usage, current and voltage (all numbers) In addition there is an Outlet Group Power (switch) SwitchLED (switch) and Signal (number) channels Also all items, channels from 2.4 binding still work and I created an switch item for LED light on HS300 and turned it off and viola! LED is off BRAVO!