GithubHelp home page GithubHelp logo

gotuya's Introduction

GoTuya ๐Ÿ”“๐ŸŒฉ๏ธ

A Go Api to control your Tuya devices through your Local Network (LAN)

Features:

  • ๐ŸŒง๐Ÿ™…โ€โ™‚๏ธ Works completely offline without any connection to the ๐Ÿ’ฉ and unsecure chinese clouds
  • ๐Ÿ”Œ Easily extendable: Control any Tuya device with ease
  • ๐Ÿ”ฌ Battle tested with a Tuya TCL A/C

Important

Currently only Tuya devices with Version 3.3 are supported

Note

This Go api wouldn't be possible without the amazing tuyapi project

Quickstart

Install the Package:

$ go get -u github.com/Binozo/GoTuya

Setup your Tuya Device

You will need the following data to control your Tuya device:

  • The device's ip in your local network
  • The deviceId
  • The localKey

To retrieve those values you have to follow those steps.

Implement the Api

Here is an example for an Air Conditioner:

package main

import (
	"fmt"
	"github.com/Binozo/GoTuya/pkg/ac"
	"time"
)

func main() {
	myTclAc := ac.CreateAC("192.168.178.30", "15580880bcaac262j6eg", "A2In><,:-{Hy:[%K7")
	isOn, err := myTclAc.IsOn()
	if err != nil {
		panic(err)
	}
	fmt.Println("A/C is on:", isOn)

	if !isOn {
		targetTemp := 20
		fmt.Printf("The A/C is not on. Starting cooling with %dยฐC...\n", targetTemp)
		if err := myTclAc.SetTemperature(targetTemp); err != nil {
			fmt.Println("Couldn't turn on A/C:", err.Error())
			return
		}
		fmt.Println("A/C has been turn on. Waiting for 5 seconds to cool")
		time.Sleep(time.Second * 5)

		fmt.Println("Turning off")
		if err := myTclAc.Power(false); err != nil {
			fmt.Println("Couldn't turn off A/C:", err.Error())
		}
	}
}

๐Ÿ”Œ Extending

To use this Api to connect to your tuya device take a look at the tuya package. The ac package is a wrapper for that.

Generally looking at the implementation of the ac device will help you implement your specific device.

Contributions are always welcome!

gotuya's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.