kwolo.tuya.net 1.0.3

# Tuya.net
           .net core library to retrieve Tuya smart home IoT data and switch them on and off
           
           # Compatibility
           The project was built and tested using C# 8.0 on dotnet core 3.1

           # Project site
           See https://gitlab.com/skotl/tuya.net

Install-Package kwolo.tuya.net -Version 1.0.3
dotnet add package kwolo.tuya.net --version 1.0.3
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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&lt;Device&gt; - 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...

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&lt;Device&gt; - 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...

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.3 176 10/20/2020
1.0.2 66 10/18/2020
1.0.1 105 10/7/2020