TapoSharp 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TapoSharp --version 1.0.0
NuGet\Install-Package TapoSharp -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TapoSharp" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TapoSharp --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TapoSharp, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TapoSharp as a Cake Addin #addin nuget:?package=TapoSharp&version=1.0.0 // Install TapoSharp as a Cake Tool #tool nuget:?package=TapoSharp&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TapoSharp
TapoSharp is a .NET implementation of the Tapo Smart Plug API. It is written in .NET 6
Getting Started
Scanning for devices
var scanRange = "192.168.1.0/24"; // CIDR notation. /32 for single IP, /24 for 254 IPs
var clients = TapoClient.ScanForDevices(scanRange);
Console.WriteLine($"Found '{clients.Count}' devices in the range: '{scanRange}'");
Attaching an event handler
var _username = "{ENTER_TAPO_ACCOUNT_EMAIL_HERE}";
var _password = "{ENTER_TAPO_ACCOUNT_PASSWORD_HERE}";
TapoClient.OnDeviceDiscovered += (s, e) =>
{
// Attempt to login
if (e.Client.Login(_username, _password, e.Key))
{
var info = e.Client.GetDeviceInfo();
Console.WriteLine($"Found '{info.Nickname} - {info.MacAddress} - {info.IpAddress}'");
}
};
var scanRange = "192.168.1.0/24"; // CIDR notation. /32 for single IP, /24 for 254 IPs
var clients = TapoClient.ScanForDevices(scanRange);
Getting device information
var _username = "{ENTER_TAPO_ACCOUNT_EMAIL_HERE}";
var _password = "{ENTER_TAPO_ACCOUNT_PASSWORD_HERE}";
var device = IPAddress.Parse("192.168.1.10");
Console.WriteLine($"Connecting to device: '{device.ToString()}'");
var client = new TapoClient(device);
Console.WriteLine($"Sending handshake to device: '{device.ToString()}'");
var handshakeResponse = client.Handshake();
if (handshakeResponse != null)
{
Console.WriteLine($"Logging into device: '{device.ToString()}'");
if (client.Login(_username, _password, handshakeResponse.Key))
{
Console.WriteLine($"Getting device info for: '{device.ToString()}'");
var info = client.GetDeviceInfo();
Console.WriteLine($"Device name is: '{info.Nickname}'");
Console.WriteLine($"Device model is: '{info.Model}'");
Console.WriteLine($"Device version is: '{info.FirmwareVersion}'");
Console.WriteLine($"Device IP address is: '{info.IpAddress}'");
Console.WriteLine($"Device MAC address is: '{info.MacAddress.Replace("-", ":")}'");
}
}
Setting device state (On/Off)
var _username = "{ENTER_TAPO_ACCOUNT_EMAIL_HERE}";
var _password = "{ENTER_TAPO_ACCOUNT_PASSWORD_HERE}";
var device = IPAddress.Parse("192.168.1.10");
Console.WriteLine($"Connecting to device: '{device.ToString()}'");
var client = new P100Client(device);
Console.WriteLine($"Sending handshake to device: '{device.ToString()}'");
var handshakeResponse = client.Handshake();
if (handshakeResponse != null)
{
Console.WriteLine($"Logging into device: '{device.ToString()}'");
if (client.Login(_username, _password, handshakeResponse.Key))
{
Console.WriteLine($"Turning device ON: '{device.ToString()}'");
var stateResponse = client.ChangeState(PowerState.ON);
Console.WriteLine($"Turning device OFF: '{device.ToString()}'");
stateResponse = client.ChangeState(PowerState.OFF);
}
}
Getting device power consumption (P110 Only)
var _username = "{ENTER_TAPO_ACCOUNT_EMAIL_HERE}";
var _password = "{ENTER_TAPO_ACCOUNT_PASSWORD_HERE}";
var device = IPAddress.Parse("192.168.1.10");
Console.WriteLine($"Connecting to device: '{device.ToString()}'");
var client = new P110Client(device);
Console.WriteLine($"Sending handshake to device: '{device.ToString()}'");
var handshakeResponse = client.Handshake();
if (handshakeResponse != null)
{
Console.WriteLine($"Logging into device: '{device.ToString()}'");
if (client.Login(_username, _password, handshakeResponse.Key))
{
Console.WriteLine($"Getting energy usage for: '{device.ToString()}'");
var usage = client.GetEnergyUsage();
}
}
Authors
Version History
- 0.1
- Initial Release
License
This project is licensed under the GNU GPLv3 License - see the LICENSE.md file for details
Acknowledgments
Thanks to the guys over on the Home Assistant community forum for their great work reverse engineering the device. Without them this API would not exist.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- BouncyCastle.NetCore (>= 1.8.10)
- IPNetwork2 (>= 2.5.402)
- Portable.BouncyCastle (>= 1.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.