This .NET Standard 2.0 API allows programmatic control over the basic functions of Tuya Smart Plugs, including getting and setting Power status.
- .NET Core 2.0
- Zentec Living Smart Plug Outlet with USB Port
- ISELECTOR Mini Smart Plug
- Xenon Smart Plug PW701U
- Teckin Smart Plug SH-SP23-2-UK
Many Smart Plug devices compatible with the Tuya Smart Life and Jinvoo Smart app also appear to be compatible with the Tuya protocol.
Install-Package m4rcus.TuyaCore
- Install the Tuya Smart Life App onto your device
- Install ADB on your computer: https://www.xda-developers.com/install-adb-windows-macos-linux/
- Ensure your device has USB debugging enabled
- Plug device into your computer
- Run filtered ADB logcat via shell:
> adb shell > logcat | grep BindDeviceSuccessPresenter
- Add the smart plug in the Tuya App, monitor the adb logcat output for the following
- Find the "localKey" and "devId" keys listed in the output, ex:
In this example, the LocalKey is
12-06 23:58:53.544 17782 17782 D Tuya : BindDeviceSuccessPresenter updateList devIds:[{"ability":0,"attribute":0,"bv":"5.06","cloudOnline":true,"devId":"0120015260091453a970","encrypt":false,"gwType":"s","i18nTime":0,"iconUrl":"https://images.tuyaus.com/smart/icon/1496461963_0.jpeg","isLocalOnline":false,"isOnline":true,"lat":"","localKey":"5f5f784cd82d449b","lon":"","name":"WiFi Plug ","pv":"2.1","rnFind":false,"runtimeEnv":"prod","supportGroup":false,"switchDp":0,"time":1512626328,"uuid":"0120015260091453a970","verSw":"1.0.4"}]
5f5f784cd82d449b
and the Id is0120015260091453a970
- Find the IP address of your device via your router's DHCP leases. The IP address reported by the app is not the local IP address.
> dotnet m4rcus.TuyaCore.Console.dll -i <ip> -k <localKey> -d <deviceId> [status|power-on|power-off]
using m4rcus.TuyaCore;
var device = new TuyaPlug()
{
IP = "192.168.0.101",
LocalKey = "5f5f784cd82d449b",
Id = "0120015260091453a970"
};
var status = await device.GetStatus();
await device.SetStatus(!status.Powered); // toggle power
Protocol details from @codetheweb and @clach04: