Giter Site home page Giter Site logo

geri-borbas / .net.library.tuyakit Goto Github PK

View Code? Open in Web Editor NEW
42.0 6.0 12.0 1.3 MB

A library to control Tuya smart home devices via local TCP connection.

C# 100.00%
tuya tuya-smart tuya-api iot iot-device iot-framework iot-middleware tcp tcp-client tcp-socket

.net.library.tuyakit's Introduction

๐Ÿ” SwiftUI Search Bar in the Navigation Bar
๐Ÿ“– Tutorial article with sample project at blog.eppz.eu

.net.library.tuyakit's People

Contributors

geri-borbas avatar realindica avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

.net.library.tuyakit's Issues

3.3 support

Hi!

I added protocol 3.3 support and repetition of dropped requests to prevent exceptions.

Would you be able to add this?

If not, I would be willing to start a new project inspired by your code.

Thank you :)

No longer working?

Hey I used this a while ago and I starting programming an application using this library, but it doesn't seem to work.
Exception I get when running [devicename].Toggle() :

System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

Any ideas?

edit:

Seems there is no support for 3.3 protocol. I'll see what I can do though.

V-TAC Light Support (Probably all lights from Tuya sub-brands)

Here is a class for the V-TAC model 5011 smart light. This should work for all V-TAC smart lights, and possibly all Tuya sub-brand lights.

using System.Collections.Generic;
using System.Threading.Tasks;

//LIGHT VARIABLES
/*					["1"] = true,
					["2"] = "colour",
					["3"] = 25,
					["5"] = "0000ff00f0ffff",
					["6"] = "00ff0000000000",
					["7"] = "ffff500100ff00",
					["8"] = "ffff8003ff000000ff000000ff000000000000000000",
					["9"] = "ffff5001ff0000",
					["10"] = "ffff0505ff000000ff00ffff00ff00ff0000ff000000",
					["11"] = ""
					
*/

namespace EPPZ.Tuya.Devices
{


	[Serializable]
	public class Vtac_5011 : Device
	{


		public async Task<bool> GetIsOn()
		{
			Dictionary<string, object> dps = await Get();
			if (dps.ContainsKey("1")) return (bool)dps["1"];
			return false;
		}

		public async void TurnOff()
		{
			Dictionary<string, object> response = await Set(
				new Dictionary<string, object>
				{
					["1"] = false
				}
			);

			Log.Format("response: `{0}`", response);
		}

		public async void TurnOn()
		{
			Dictionary<string, object> response = await Set(
				new Dictionary<string, object>
				{
					["1"] = true
				}
			);

			Log.Format("response: `{0}`", response);
		}

		public async void setColour(int R, int G, int B)
		{
			Dictionary<string, object> response;
			if (R == 255 && G == 255 && B == 255)
			{
				response = await Set(
				new Dictionary<string, object>
				{
					["1"] = true,
					["2"] = "white",
				});
			} else {
				response = await Set(
				   new Dictionary<string, object>
				   {
					   ["1"] = true,
					   ["2"] = "colour",
					   ["5"] = R.ToString("X2").ToLower() + G.ToString("X2").ToLower() + B.ToString("X2").ToLower() + "0000ffff",
					   ["6"] = "00ff0000000000",
					   ["7"] = "ffff500100ff00",
					   ["8"] = "ffff8003ff000000ff000000ff000000000000000000",
					   ["9"] = "ffff5001ff0000",
					   ["10"] = "ffff0505ff000000ff00ffff00ff00ff0000ff000000",
					   ["11"] = ""
				   });
			}

			Log.Format("response: `{0}`", response);
		}

		public async void setBrightness(int brightness)
		{
			Dictionary<string, object> response = await Set(
				new Dictionary<string, object>
				{
					["1"] = true,
					["3"] = brightness
				}
			);

			Log.Format("response: `{0}`", response);
		}

		public async void Toggle()
		{
			Dictionary<string, object> dps = await Get();
			if (dps.ContainsKey("1"))
			{
				bool isOn = (bool)dps["1"];
				if (isOn) TurnOff(); else TurnOn();
			}
		}
	}
}```

Any issues, and I will sort it.
Tried to make a pull request but would not let me :(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.