This is a java client for TP-Link smart plugs of the HS1xx device family. Currently, only the following features are implemented:
- Relay control
- LED control
- Device Reboot
- Reading general system information
- Reading power measurement info
The project is published on maven central.
<dependency>
<groupId>net.draal.home</groupId>
<artifactId>hs1xx</artifactId>
<version>2.0.0</version>
</dependency>
implementation 'net.draal.home:hs1xx:2.0.0'
public class Introduction {
public static void main(String[] args) {
// Create facade
Hs1xxFacade hs1xxFacade = Hs1xxFacade.withDefaultConfiguration();
// Create device
Hs1xxDevice device = Hs1xxDevice.builder()
.host("localhost")
.build();
// do stuff
System.out.println(hs1xxFacade.getPowerStats(device));
}
}
The withDefaultConfiguration
factory method should provide a configuration
that should fit most needs, but there also is a constructor that may give you control
over its dependencies. Please note that the provided objectMapper is configured in a
way that may be required for reliable communication with the device.
Please note that this library provides some increased log output based on the configured
log threshold. JSON payloads are logged with level debug
, raw payloads are logged with trace
.
The javadoc currently is rather incomplete. Will be extended in the future.
This project is versioned with semver v2. That's the plan at least.
Contributions are always welcome via PR. Just bear with me, this is the first OSS project that I maintain.
The build is a pretty standard gradle build and the project doesn't need any special build environment (aside from OpenJDK 11):
# build the project
./gradlew clean assemble
# Run tests
./gradlew check
Reports for tests are written to build/reports
.
I am trying to keep the number of runtime dependencies of this library reasonably small and limited to very common packages (guava, apache commons, jackson-databind) which are probably present in most java projects anyways.
Minimum JDK version is 17 at the moment.
Because I wrote this mostly for power consumption monitoring. Other features can be added rather easily though. Please note that I only own a couple of HS110's, so if you're interested in other types of devices, I will have to purchase these first.
I don't want to give code to other people for usage that wasn't even executed once in tests. There is still plenty of opportunity for bugs, but there should be at least some minimum standard.
Because I got carried away when playing with log4j2 pattern layouts.
It seems that the device has 4 listeners for incoming requests. You will have to be careful with concurrent requests to stay below that limit.
Special thanks to the folks at SoftScheck for their work in reverse engineering the protocol. See their story in their blog. This library is largely based on their work published on github/tplink-smartplug.