kwolo.tuya.net 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package kwolo.tuya.net --version 1.0.3                
NuGet\Install-Package kwolo.tuya.net -Version 1.0.3                
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="kwolo.tuya.net" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add kwolo.tuya.net --version 1.0.3                
#r "nuget: kwolo.tuya.net, 1.0.3"                
#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 kwolo.tuya.net as a Cake Addin
#addin nuget:?package=kwolo.tuya.net&version=1.0.3

// Install kwolo.tuya.net as a Cake Tool
#tool nuget:?package=kwolo.tuya.net&version=1.0.3                

Tuya.net

About

.net core library to retrieve Tuya smart home IoT data and switch them on and off

References

Basic operations pulled from the Javascript library at https://github.com/ndg63276/smartlife with thanks to Github user "Mark W"

Supported operations

Right now the library supports the following functionality:

  1. Authenticate
  2. Fetch device list
  3. Turn a switch on
  4. Turn a switch off

It has only been tested on bizType=tuya / from=tuya devices, unlike the original Javascript project that also supports bizType=smart_life (and possibly others). This wouldn't be hard to configure, but I don't have a way to test them.

Building

The library is a .net core 3.1 class library, with a helper / sample app as a .net core 3.1 console app.

appsettings.json (test harness)

If you want to run the test harness then you'll need to create an appsettings.json file in the test harness folder. The structure of this file should look like this:

{
    "Logging": {
        "LogLevel": {
            "Default": "Debug",
            "System": "Information",
            "Microsoft": "Information",
            "System.Net.Http.HttpClient": "Trace"
        }
    },
    "TestHarnessConfiguration": {
        "UserName": "your tuya login",
        "Password": "your tuya password",
        "CountryCode": "EU"
    }
}

The CountryCode can be one of:

  • EU for Europe / UK
  • US for United States / Canada
  • AY for China / AsiaPac

Nuget package

Nuget package is available here: https://www.nuget.org/packages/kwolo.tuya.net

Sample calls

See the TestHarness project for sample code, which contains the following:

var session = await _authenticatorService.AuthenticateAsync(_config.UserName, _config.Password, _config.CountryCode);

var devices = await _deviceListFetcher.GetDeviceListAsync(session);

await _deviceSwitcher.SwitchOnAsync(devices[0].Id, session);
await Task.Delay(2000);
await _deviceSwitcher.SwitchOffAsync(devices[0].Id, session);

First, we authenticate, which returns an AuthenticatedSession. That session contains an access code as well as an expiration - be wary of this expiring!

Next, we fetch the list of devices, passing it the authenticated session. This is a List<Device> - check the Device class to see what is returned.

Once we have a list of devices, the test harness assumes that there is at least one, and that it's a switch. You'll need to do a little sorting through the list of you have multiple devices, and multiple device types.

Finally, we switch the device on via DeviceSwitcher.SwitchOnAsync() and then off again, with a two second delay between the operations.

Contributions welcome!

I actually only wrote this so I could control a single switch, so job done for me. If you have additional Tuya devices and want to contribute to the project then please feel free!

Please note that merge/pull requests without unit tests will probably not get approved...

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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.5 234 2/8/2024
1.0.4 732 5/3/2021
1.0.3 587 10/20/2020
1.0.2 417 10/18/2020
1.0.1 464 10/7/2020