#tp-link #devices #smart #control #networking #light #query

bin+lib tplinker

Interface to TPLink smart devices such as HS100, HS110, LB110, LB120, KL110

9 releases

0.4.4 Dec 13, 2021
0.4.3 May 17, 2021
0.4.2 Aug 4, 2020
0.4.0 Jul 7, 2020
0.1.0 Nov 27, 2019

#3 in #tp-link

26 downloads per month
Used in 2 crates

MIT license

100KB
2.5K SLoC

TPLinker

GitHub Actions crates.io docs.rs

A rust library to query and control TPLink smart plugs and smart lights.

Supported devices include HS100, HS110, LB110, LB120, KL110.

Inspired and influenced by pyHS100 and hs100api.

There are two main entrypoints. If you know the IP address and device type you can instantiate directly. Alternatively you can discover devices on the local network.

In order to do things with devices you must bring in the capabiliy traits from capabilities.

Discovery

To see all TPLink smart devices on the local network use discovery::discover.

use tplinker::{
  discovery::discover,
  devices::Device,
  capabilities::Switch,
};

fn main() {
  for (addr, data) in discover().unwrap() {
    let device = Device::from_data(addr, &data);
    let sysinfo = data.sysinfo();
    println!("{}\t{}\t{}", addr, sysinfo.alias, sysinfo.hw_type);
    match device {
      Device::HS110(device) => { device.switch_on().unwrap(); },
      _ => {},
    }
  }
}

Direct device

To connect to a specific TPLink device use the specific device struct from devices.

use tplinker::{
  devices::LB110,
  capabilities::{Switch, Dimmer},
};

let device = LB110::new("192.168.0.99:9999").unwrap();
if device.is_on().unrwap() {
  let brightness = device.brightness().unwrap();
  if brightness < 50 {
    device.set_brightness(brightness + 20).unwrap();
  }
}

Capabilities

In order to do things with devices you must bring in the relevant capability traits from capabilities.

CLI

There is a basic CLI:

tplinker discover

tplinker status 192.168.1.2 192.168.1.3

tplinker switch 192.168.1.4 on

Dependencies

~3.5–5MB
~88K SLoC