View Source TpLink
Client library for interacting with Kasa/TP-Link smart home devices via either tplinkcloud.com or directly over the local network (no Internet connection required).
installation
Installation
The package can be installed by adding tp_link
to your list of dependencies in mix.exs
:
def deps do
[
{:tp_link, "~> 0.2"}
]
end
usage
Usage
cloud
Cloud
Create a session by calling TpLink.Cloud.login
:
{:ok, session} = TpLink.Cloud.login("user@example.com", "password")
To list devices, call TpLink.Cloud.list_devices
:
{:ok, devices} = TpLink.Cloud.list_devices(session)
Using the device_id
returned by the previous call, you can turn on a smart switch by calling:
session
|> TpLink.cloud_device("800626A81D45A54544ADE5222EB50BF11BB7CBE3")
|> TpLink.Type.Plug.set_relay_state(true)
local-network
Local network
To list devices on the local network, call TpLink.Local.list_devices
. There is no need to authenticate because TP-Link devices are not secure on the local network:
{:ok, devices} = TpLink.Local.list_devices()
Using the IP address or hostname of the device, you can turn on a smart switch by calling:
TpLink.local_device({192, 168, 0, 3})
|> TpLink.Type.Plug.set_relay_state(true)