TapoSharp 1.0.4.1

dotnet add package TapoSharp --version 1.0.4.1
NuGet\Install-Package TapoSharp -Version 1.0.4.1
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.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TapoSharp --version 1.0.4.1
#r "nuget: TapoSharp, 1.0.4.1"
#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.4.1

// Install TapoSharp as a Cake Tool
#tool nuget:?package=TapoSharp&version=1.0.4.1

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}'");

Executing a callback function on dicsovered devices

var _username = "{ENTER_TAPO_ACCOUNT_EMAIL_HERE}";
var _password = "{ENTER_TAPO_ACCOUNT_PASSWORD_HERE}";

var scanRange = "192.168.1.0/24"; // CIDR notation. /32 for single IP, /24 for 254 IPs
var clients = TapoClient.ScanForDevices(scanRange, FilterEnum.Usable, (ip, tapoClient) => 
{
    // Attempt to login
    var client = new P100Client(e.IpAddress);
    if (client.Login(_username, _password))
    {
        var info = client.GetDeviceInfo();
        Console.WriteLine(info.Print());
    }    
});

Attaching an event handler

var _username = "{ENTER_TAPO_ACCOUNT_EMAIL_HERE}";
var _password = "{ENTER_TAPO_ACCOUNT_PASSWORD_HERE}";

var scanRange = "192.168.1.0/24"; // CIDR notation. /32 for single IP, /24 for 254 IPs
TapoClient.OnDeviceDiscovered += (s, e) =>
{
    // Attempt to login
    var client = new P100Client(e.IpAddress);
    if (client.Login(_username, _password))
    {
        var info = client.GetDeviceInfo();
        Console.WriteLine(info.Print());
    }
};
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($"Logging into device: '{device.ToString()}'");
if (client.Login(_username, _password))
{
    var info = client.GetDeviceInfo();
    Console.WriteLine(info.Print());
}

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($"Logging into device: '{device.ToString()}'");
if (client.Login(_username, _password))
{
    Console.WriteLine($"Turning device ON: '{device.ToString()}'");
    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($"Logging into device: '{device.ToString()}'");
if (client.Login(_username, _password))
{
    Console.WriteLine($"Getting energy usage for: '{device.ToString()}'");
    var usage = client.GetEnergyUsage();
    Console.WriteLine($"Current power consumption: '{usage.CurrentPower_W.ToString("0.00")}W'");
}

Authors

Version History

  • 1.0.4.1
    • Fixed the README file code examples
  • 1.0.4
    • Added login state tracker
  • 1.0.3
    • Fixed issue with multiple handshake requests
    • Fixed issue with scanning of /32 network
  • 1.0.2
    • Added callback functions on scan discovery
  • 1.0.1
    • Added a merged login and handshake request
    • Reworked the raised event args for OnDeviceDiscovered
    • Added default constructors to the clients
  • 1.0.0
    • 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 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4.1 668 4/9/2022
1.0.4 401 4/4/2022
1.0.3 394 4/4/2022
1.0.2 389 4/4/2022
1.0.1 388 4/4/2022
1.0.0 379 4/4/2022