From d9f7cf25ad2b7bee3dc2ab2f380e5b3737e6aada Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 18 Sep 2020 07:03:58 +0200 Subject: [PATCH 01/77] On branch master Your branch is up to date with 'origin/master'. Changes to be committed: deleted: LICENSE deleted: setup.py deleted: tuyaha/__init__.py deleted: tuyaha/devices/__init__.py deleted: tuyaha/devices/base.py deleted: tuyaha/devices/climate.py deleted: tuyaha/devices/cover.py deleted: tuyaha/devices/factory.py deleted: tuyaha/devices/fan.py deleted: tuyaha/devices/light.py deleted: tuyaha/devices/lock.py deleted: tuyaha/devices/remote.py deleted: tuyaha/devices/scene.py deleted: tuyaha/devices/switch.py deleted: tuyaha/tuyaapi.py Changes not staged for commit: modified: README.md modified: plugin.py --- LICENSE | 25 ----- setup.py | 23 ----- tuyaha/__init__.py | 2 - tuyaha/devices/__init__.py | 0 tuyaha/devices/base.py | 61 ------------ tuyaha/devices/climate.py | 116 ----------------------- tuyaha/devices/cover.py | 25 ----- tuyaha/devices/factory.py | 28 ------ tuyaha/devices/fan.py | 48 ---------- tuyaha/devices/light.py | 90 ------------------ tuyaha/devices/lock.py | 12 --- tuyaha/devices/remote.py | 0 tuyaha/devices/scene.py | 12 --- tuyaha/devices/switch.py | 29 ------ tuyaha/tuyaapi.py | 188 ------------------------------------- 15 files changed, 659 deletions(-) delete mode 100644 LICENSE delete mode 100644 setup.py delete mode 100644 tuyaha/__init__.py delete mode 100644 tuyaha/devices/__init__.py delete mode 100644 tuyaha/devices/base.py delete mode 100644 tuyaha/devices/climate.py delete mode 100644 tuyaha/devices/cover.py delete mode 100644 tuyaha/devices/factory.py delete mode 100644 tuyaha/devices/fan.py delete mode 100644 tuyaha/devices/light.py delete mode 100644 tuyaha/devices/lock.py delete mode 100644 tuyaha/devices/remote.py delete mode 100644 tuyaha/devices/scene.py delete mode 100644 tuyaha/devices/switch.py delete mode 100644 tuyaha/tuyaapi.py diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 5942556..0000000 --- a/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright for portions of project tuyaha are held by Tuya Inc., 2018 as part -of project tuyapy. All other copyright for project tuyaha are held by -Pavlo Annekov, 2019. - -MIT License - -Copyright (c) 2019 Pavlo Annekov - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/setup.py b/setup.py deleted file mode 100644 index 182989a..0000000 --- a/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -# coding=utf-8 -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="tuyaha", - version="0.0.6", - author="Pavlo Annekov and original Tuya authors", - author_email="paul.annekov@gmail.com", - description="A Python library that implements a Tuya API endpoint that was specially designed for Home Assistant", - long_description=long_description, - long_description_content_type="text/markdown", - packages=setuptools.find_packages(), - url="https://github.com/PaulAnnekov/tuyaha", - license="MIT", - classifiers=( - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ), -) diff --git a/tuyaha/__init__.py b/tuyaha/__init__.py deleted file mode 100644 index 84688e2..0000000 --- a/tuyaha/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -"""Init file for test""" -from .tuyaapi import TuyaApi diff --git a/tuyaha/devices/__init__.py b/tuyaha/devices/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tuyaha/devices/base.py b/tuyaha/devices/base.py deleted file mode 100644 index 313c8d4..0000000 --- a/tuyaha/devices/base.py +++ /dev/null @@ -1,61 +0,0 @@ -import time - - -class TuyaDevice: - def __init__(self, data, api): - self.api = api - self.data = data.get("data") - self.obj_id = data.get("id") - self.obj_type = data.get("ha_type") - self.obj_name = data.get("name") - self.dev_type = data.get("dev_type") - self.icon = data.get("icon") - - def name(self): - return self.obj_name - - def state(self): - state = self.data.get("state") - if state == "true": - return True - else: - return False - - def device_type(self): - return self.dev_type - - def object_id(self): - return self.obj_id - - def object_type(self): - return self.obj_type - - def available(self): - return self.data.get("online") - - def iconurl(self): - return self.icon - - def update(self): - """Avoid get cache value after control.""" - time.sleep(0.5) - success, response = self.api.device_control( - self.obj_id, "QueryDevice", namespace="query" - ) - if success: - self.data = response["payload"]["data"] - return True - return - - def __repr__(self): - module = self.__class__.__module__ - if module is None or module == str.__class__.__module__: - module = "" - else: - module += "." - return '<{module}{clazz}: "{name}" ({obj_id})>'.format( - module=module, - clazz=self.__class__.__name__, - name=self.obj_name, - obj_id=self.obj_id - ) diff --git a/tuyaha/devices/climate.py b/tuyaha/devices/climate.py deleted file mode 100644 index 942392b..0000000 --- a/tuyaha/devices/climate.py +++ /dev/null @@ -1,116 +0,0 @@ -from tuyaha.devices.base import TuyaDevice - - -class TuyaClimate(TuyaDevice): - def temperature_unit(self): - return self.data.get("temp_unit") - - def current_humidity(self): - pass - - def target_humidity(self): - pass - - def current_operation(self): - return self.data.get("mode") - - def operation_list(self): - return self.data.get("support_mode") - - def current_temperature(self): - return self.data.get("current_temperature") - - def target_temperature(self): - return self.data.get("temperature") - - def target_temperature_step(self): - return 0.5 - - def current_fan_mode(self): - """Return the fan setting.""" - fan_speed = self.data.get("windspeed") - if fan_speed is None: - return None - if fan_speed == "1": - return "low" - elif fan_speed == "2": - return "medium" - elif fan_speed == "3": - return "high" - return fan_speed - - def fan_list(self): - """Return the list of available fan modes.""" - return ["low", "medium", "high"] - - def current_swing_mode(self): - """Return the fan setting.""" - return None - - def swing_list(self): - """Return the list of available swing modes.""" - return None - - def min_temp(self): - return self.data.get("min_temper") - - def max_temp(self): - return self.data.get("max_temper") - - def min_humidity(self): - pass - - def max_humidity(self): - pass - - def set_temperature(self, temperature): - """Set new target temperature.""" - self.api.device_control( - self.obj_id, "temperatureSet", {"value": float(temperature)} - ) - - def set_humidity(self, humidity): - """Set new target humidity.""" - raise NotImplementedError() - - def set_fan_mode(self, fan_mode): - """Set new target fan mode.""" - self.api.device_control(self.obj_id, "windSpeedSet", {"value": fan_mode}) - - def set_operation_mode(self, operation_mode): - """Set new target operation mode.""" - self.api.device_control(self.obj_id, "modeSet", {"value": operation_mode}) - - def set_swing_mode(self, swing_mode): - """Set new target swing operation.""" - raise NotImplementedError() - - def support_target_temperature(self): - if self.data.get("temperature") is not None: - return True - else: - return False - - def support_mode(self): - if self.data.get("mode") is not None: - return True - else: - return False - - def support_wind_speed(self): - if self.data.get("windspeed") is not None: - return True - else: - return False - - def support_humidity(self): - if self.data.get("humidity") is not None: - return True - else: - return False - - def turn_on(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "1"}) - - def turn_off(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "0"}) diff --git a/tuyaha/devices/cover.py b/tuyaha/devices/cover.py deleted file mode 100644 index 85ad409..0000000 --- a/tuyaha/devices/cover.py +++ /dev/null @@ -1,25 +0,0 @@ -from tuyaha.devices.base import TuyaDevice - - -class TuyaCover(TuyaDevice): - def state(self): - state = self.data.get("state") - return state - - def open_cover(self): - """Open the cover.""" - self.api.device_control(self.obj_id, "turnOnOff", {"value": "1"}) - - def close_cover(self): - """Close cover.""" - self.api.device_control(self.obj_id, "turnOnOff", {"value": "0"}) - - def stop_cover(self): - """Stop the cover.""" - self.api.device_control(self.obj_id, "startStop", {"value": "0"}) - - def support_stop(self): - support = self.data.get("support_stop") - if support is None: - return False - return support diff --git a/tuyaha/devices/factory.py b/tuyaha/devices/factory.py deleted file mode 100644 index 0ad3de6..0000000 --- a/tuyaha/devices/factory.py +++ /dev/null @@ -1,28 +0,0 @@ -from tuyaha.devices.climate import TuyaClimate -from tuyaha.devices.cover import TuyaCover -from tuyaha.devices.fan import TuyaFanDevice -from tuyaha.devices.light import TuyaLight -from tuyaha.devices.lock import TuyaLock -from tuyaha.devices.scene import TuyaScene -from tuyaha.devices.switch import TuyaSwitch - - -def get_tuya_device(data, api): - dev_type = data.get("dev_type") - devices = [] - - if dev_type == "light": - devices.append(TuyaLight(data, api)) - elif dev_type == "climate": - devices.append(TuyaClimate(data, api)) - elif dev_type == "scene": - devices.append(TuyaScene(data, api)) - elif dev_type == "fan": - devices.append(TuyaFanDevice(data, api)) - elif dev_type == "cover": - devices.append(TuyaCover(data, api)) - elif dev_type == "lock": - devices.append(TuyaLock(data, api)) - elif dev_type == "switch": - devices.append(TuyaSwitch(data, api)) - return devices diff --git a/tuyaha/devices/fan.py b/tuyaha/devices/fan.py deleted file mode 100644 index 27117d5..0000000 --- a/tuyaha/devices/fan.py +++ /dev/null @@ -1,48 +0,0 @@ -from tuyaha.devices.base import TuyaDevice - - -class TuyaFanDevice(TuyaDevice): - def state(self): - state = self.data.get("state") - if state == "true": - return True - else: - return False - - def speed(self): - return self.data.get("speed") - - def speed_list(self): - speed_list = [] - speed_level = self.data.get("speed_level") - for i in range(speed_level): - speed_list.append(str(i + 1)) - return speed_list - - def oscillating(self): - return self.data.get("direction") - - def set_speed(self, speed): - self.api.device_control(self.obj_id, "windSpeedSet", {"value": speed}) - - def oscillate(self, oscillating): - if oscillating: - command = "swingOpen" - else: - command = "swingClose" - self.api.device_control(self.obj_id, command) - - def turn_on(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "1"}) - - def turn_off(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "0"}) - - def support_oscillate(self): - if self.oscillating() is None: - return False - else: - return True - - def support_direction(self): - return False diff --git a/tuyaha/devices/light.py b/tuyaha/devices/light.py deleted file mode 100644 index 9913073..0000000 --- a/tuyaha/devices/light.py +++ /dev/null @@ -1,90 +0,0 @@ -from tuyaha.devices.base import TuyaDevice - - -class TuyaLight(TuyaDevice): - def state(self): - state = self.data.get("state") - if state == "true": - return True - else: - return False - - def brightness(self): - work_mode = self.data.get("color_mode") - if work_mode == "colour" and "color" in self.data: - brightness = int(self.data.get("color").get("brightness") * 255 / 100) - else: - brightness = self.data.get("brightness") - return brightness - - def _set_brightness(self, brightness): - work_mode = self.data.get("color_mode") - if work_mode == "colour": - self.data["color"]["brightness"] = brightness - else: - self.data["brightness"] = brightness - - def support_color(self): - if self.data.get("color") is None: - return False - else: - return True - - def support_color_temp(self): - if self.data.get("color_temp") is None: - return False - else: - return True - - def hs_color(self): - if self.data.get("color") is None: - return None - else: - work_mode = self.data.get("color_mode") - if work_mode == "colour": - color = self.data.get("color") - return color.get("hue"), color.get("saturation") - else: - return 0.0, 0.0 - - def color_temp(self): - if self.data.get("color_temp") is None: - return None - else: - return self.data.get("color_temp") - - def min_color_temp(self): - return 10000 - - def max_color_temp(self): - return 1000 - - def turn_on(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "1"}) - - def turn_off(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "0"}) - - def set_brightness(self, brightness): - """Set the brightness(0-255) of light.""" - value = int(brightness * 100 / 255) - self.api.device_control(self.obj_id, "brightnessSet", {"value": value}) - - def set_color(self, color): - """Set the color of light.""" - hsv_color = {} - hsv_color["hue"] = color[0] - hsv_color["saturation"] = color[1] / 100 - if len(color) < 3: - hsv_color["brightness"] = int(self.brightness()) / 255.0 - else: - hsv_color["brightness"] = color[2] - # color white - if hsv_color["saturation"] == 0: - hsv_color["hue"] = 0 - self.api.device_control(self.obj_id, "colorSet", {"color": hsv_color}) - - def set_color_temp(self, color_temp): - self.api.device_control( - self.obj_id, "colorTemperatureSet", {"value": color_temp} - ) diff --git a/tuyaha/devices/lock.py b/tuyaha/devices/lock.py deleted file mode 100644 index 3524947..0000000 --- a/tuyaha/devices/lock.py +++ /dev/null @@ -1,12 +0,0 @@ -from tuyaha.devices.base import TuyaDevice - - -class TuyaLock(TuyaDevice): - def state(self): - state = self.data.get("state") - if state == "true": - return True - elif state == "false": - return False - else: - return None diff --git a/tuyaha/devices/remote.py b/tuyaha/devices/remote.py deleted file mode 100644 index e69de29..0000000 diff --git a/tuyaha/devices/scene.py b/tuyaha/devices/scene.py deleted file mode 100644 index 4f8622e..0000000 --- a/tuyaha/devices/scene.py +++ /dev/null @@ -1,12 +0,0 @@ -from tuyaha.devices.base import TuyaDevice - - -class TuyaScene(TuyaDevice): - def available(self): - return True - - def activate(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "1"}) - - def update(self): - return True diff --git a/tuyaha/devices/switch.py b/tuyaha/devices/switch.py deleted file mode 100644 index 1e6d784..0000000 --- a/tuyaha/devices/switch.py +++ /dev/null @@ -1,29 +0,0 @@ -import time - -from tuyaha.devices.base import TuyaDevice - - -class TuyaSwitch(TuyaDevice): - def state(self): - state = self.data.get("state") - if state is None: - return None - return state - - def turn_on(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "1"}) - - def turn_off(self): - self.api.device_control(self.obj_id, "turnOnOff", {"value": "0"}) - - # workaround for https://github.com/PaulAnnekov/tuyaha/issues/3 - def update(self): - """Avoid get cache value after control.""" - time.sleep(0.5) - devices = self.api.discovery() - if not devices: - return - for device in devices: - if device["id"] == self.obj_id: - self.data = device["data"] - return True diff --git a/tuyaha/tuyaapi.py b/tuyaha/tuyaapi.py deleted file mode 100644 index c96d04c..0000000 --- a/tuyaha/tuyaapi.py +++ /dev/null @@ -1,188 +0,0 @@ -import json -import logging -import time - -import requests -from requests.exceptions import ConnectionError as RequestsConnectionError -from requests.exceptions import HTTPError as RequestsHTTPError - -from tuyaha.devices.factory import get_tuya_device - -TUYACLOUDURL = "https://px1.tuya{}.com" -DEFAULTREGION = "us" - -REFRESHTIME = 60 * 60 * 12 - -_LOGGER = logging.getLogger(__name__) - - -class TuyaSession: - - username = "" - password = "" - countryCode = "" - bizType = "" - accessToken = "" - refreshToken = "" - expireTime = 0 - devices = [] - region = DEFAULTREGION - - -SESSION = TuyaSession() - - -class TuyaApi: - def init(self, username, password, countryCode, bizType=""): - SESSION.username = username - SESSION.password = password - SESSION.countryCode = countryCode - SESSION.bizType = bizType - - if username is None or password is None: - return None - else: - self.get_access_token() - self.discover_devices() - return SESSION.devices - - def get_access_token(self): - try: - response = requests.post( - (TUYACLOUDURL + "/homeassistant/auth.do").format(SESSION.region), - data={ - "userName": SESSION.username, - "password": SESSION.password, - "countryCode": SESSION.countryCode, - "bizType": SESSION.bizType, - "from": "tuya", - }, - ) - response.raise_for_status() - except RequestsConnectionError as ex: - raise TuyaNetException from ex - except RequestsHTTPError as ex: - if response.status_code >= 500: - raise TuyaServerException from ex - - response_json = response.json() - if response_json.get("responseStatus") == "error": - message = response_json.get("errorMsg") - if message == "error": - raise TuyaAPIException("get access token failed") - else: - raise TuyaAPIException(message) - - SESSION.accessToken = response_json.get("access_token") - SESSION.refreshToken = response_json.get("refresh_token") - SESSION.expireTime = int(time.time()) + response_json.get("expires_in") - areaCode = SESSION.accessToken[0:2] - if areaCode == "AY": - SESSION.region = "cn" - elif areaCode == "EU": - SESSION.region = "eu" - else: - SESSION.region = "us" - - def check_access_token(self): - if SESSION.username == "" or SESSION.password == "": - raise TuyaAPIException("can not find username or password") - if SESSION.accessToken == "" or SESSION.refreshToken == "": - self.get_access_token() - elif SESSION.expireTime <= REFRESHTIME + int(time.time()): - self.refresh_access_token() - - def refresh_access_token(self): - data = "grant_type=refresh_token&refresh_token=" + SESSION.refreshToken - response = requests.get( - (TUYACLOUDURL + "/homeassistant/access.do").format(SESSION.region) - + "?" - + data - ) - response_json = response.json() - if response_json.get("responseStatus") == "error": - raise TuyaAPIException("refresh token failed") - - SESSION.accessToken = response_json.get("access_token") - SESSION.refreshToken = response_json.get("refresh_token") - SESSION.expireTime = int(time.time()) + response_json.get("expires_in") - - def poll_devices_update(self): - self.check_access_token() - return self.discover_devices() - - def discovery(self): - response = self._request("Discovery", "discovery") - if response and response["header"]["code"] == "SUCCESS": - return response["payload"]["devices"] - return None - - def discover_devices(self): - devices = self.discovery() - if not devices: - return None - SESSION.devices = [] - for device in devices: - SESSION.devices.extend(get_tuya_device(device, self)) - return devices - - def get_devices_by_type(self, dev_type): - device_list = [] - for device in SESSION.devices: - if device.device_type() == dev_type: - device_list.append(device) - return device_list - - def get_all_devices(self): - return SESSION.devices - - def get_device_by_id(self, dev_id): - for device in SESSION.devices: - if device.object_id() == dev_id: - return device - return None - - def device_control(self, devId, action, param=None, namespace="control"): - if param is None: - param = {} - response = self._request(action, namespace, devId, param) - if response and response["header"]["code"] == "SUCCESS": - success = True - else: - success = False - return success, response - - def _request(self, name, namespace, devId=None, payload={}): - header = {"name": name, "namespace": namespace, "payloadVersion": 1} - payload["accessToken"] = SESSION.accessToken - if namespace != "discovery": - payload["devId"] = devId - data = {"header": header, "payload": payload} - response = requests.post( - (TUYACLOUDURL + "/homeassistant/skill").format(SESSION.region), json=data - ) - if not response.ok: - _LOGGER.warning( - "request error, status code is %d, device %s", - response.status_code, - devId, - ) - return - response_json = response.json() - if response_json["header"]["code"] != "SUCCESS": - _LOGGER.debug( - "control device error, error code is " + response_json["header"]["code"] - ) - return response_json - - -class TuyaAPIException(Exception): - pass - - -class TuyaNetException(Exception): - pass - - -class TuyaServerException(Exception): - pass From 7d313d0a1e333781d3d6e68f10d16abc49939156 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 18 Sep 2020 07:06:33 +0200 Subject: [PATCH 02/77] Changes to be committed: deleted: .drone.yml deleted: .vscode/settings.json Changes not staged for commit: modified: README.md modified: plugin.py --- .drone.yml | 17 ----------------- .vscode/settings.json | 10 ---------- 2 files changed, 27 deletions(-) delete mode 100644 .drone.yml delete mode 100644 .vscode/settings.json diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 167f0f1..0000000 --- a/.drone.yml +++ /dev/null @@ -1,17 +0,0 @@ -kind: pipeline -name: default - -steps: -- name: publish - image: plugins/pypi - settings: - username: - from_secret: pypi_username - password: - from_secret: pypi_password - distributions: - - sdist - - bdist_wheel - when: - ref: - - refs/tags/*.*.* diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ce69d6e..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "cSpell.words": [ - "annekov", - "pavlo", - "tuya", - "tuyacloudurl", - "tuyaha", - "tuyapy" - ] -} \ No newline at end of file From 89dc1d46446e0a079d395c742fa3282352adeea2 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 18 Sep 2020 07:08:21 +0200 Subject: [PATCH 03/77] Changes to be committed: modified: README.md modified: plugin.py --- README.md | 22 +++++----------------- plugin.py | 34 +++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b069ce1..7363fe5 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* Run: ```git clone https://github.com/guino/tuyaha.git``` +* The plugin requierd Python library tuyaha ```pip3 install tuyaha``` +* Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. ## Updating @@ -45,23 +46,10 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.2 | Update light support added temperature control | | 1.0.1 | Support for SmartLife and Jinvoo Apps | | 1.0.0 | Initial upload version | -# Includes 'tuyaha' project: +# Original project: -Cloned from the abandoned package [tuyapy](https://pypi.org/project/tuyapy/) v0.1.3. This package implements a Tuya -API endpoint that was specially designed for Home Assistant. - -This clone contains several critical fixes. Check commits. - -## How to check whether the API this library using can control your device? - -- Copy [this script](https://github.com/PaulAnnekov/tuyaha/blob/master/tools/debug_discovery.py) to your PC with Python - installed or to https://repl.it/ -- Set/update config inside and run it -- Check if your devices are listed - - If they are - open an issue and provide the output - - If they are not - don't open an issue. Ask [Tuya support](mailto:support@tuya.com) to support your device in their - `/homeassistant` API -- Remove the updated script, so your credentials won't leak +Cloned from https://github.com/guino/tuyaha to make a standalone project. diff --git a/plugin.py b/plugin.py index 5762f59..a296b51 100644 --- a/plugin.py +++ b/plugin.py @@ -1,9 +1,12 @@ + # Domoticz TUYA Plugin # # Author: Wagner Oliveira (wbbo@hotmail.com) # +# Contributed: Xenomes (xenomes@outlook.com) +# """ - +

TUYA Plugin


This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. @@ -137,11 +140,19 @@ def onCommand(self, Unit, Command, Level, Hue): # Convert RGB to Hue+Saturation rgb = json.loads(Hue) h, s = rgb_to_hs(rgb.get("r"), rgb.get("g"), rgb.get("b")) + mode = rgb.get("m") + t = rgb.get("t") Domoticz.Debug("color="+str(rgb)+" h="+str(h)+" s="+str(s)) # If color changed if Devices[Unit].Color != Hue: - dev.set_color( [ h*360, s*100 ] ) - Domoticz.Debug("Set color called") + if mode == 3: + dev.set_color( [ h*360, s*100 ] ) + Domoticz.Debug("Set color called") + if mode == 2: + temp = round(1000+(9000/255*(255-t))) + Domoticz.Debug("temp = " + str(temp)) + dev.set_color_temp( temp ) + Domoticz.Debug("Set white called") # If level changed if Devices[Unit].sValue != str(Level): dev.set_brightness(round(Level*2.55)) @@ -199,10 +210,23 @@ def handleThread(self): unit = nextUnit() dev_type = dev.device_type() if dev_type == "light": - if dev.data.get("color_mode") is None: + if dev.data.get("color_mode") is not None and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + # Light Color and White temperature contol + Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=4, Switchtype=7, DeviceID=dev.object_id()).Create() + elif dev.data.get("color_mode") is not None and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + # Light Color control + Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create() + elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + # Light White temperature control + Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=8, Switchtype=7, DeviceID=dev.object_id()).Create() + elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + # Light Brightness control + Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=3, Switchtype=7, DeviceID=dev.object_id()).Create() + elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is None and dev.data.get("brightness") is None: + # Light On/Off control Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=7, Image=0, DeviceID=dev.object_id()).Create() else: - Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create() + Domoticz.Debug("No controls found for your light device!") elif dev_type == "climate": Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=0, Image=16, DeviceID=dev.object_id()).Create() elif dev_type == "scene": From 308f45bc70317d578517e1b7d404e236585811e7 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 18 Sep 2020 07:13:54 +0200 Subject: [PATCH 04/77] Changes to be committed: modified: README.md --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 7363fe5..144660f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* The plugin requierd Python library tuyaha ```pip3 install tuyaha``` +* The plugin required Python library tuyaha and requests ```pip3 install tuyaha requests``` * Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. @@ -28,11 +28,6 @@ To update: * Run: ```git pull``` * Restart Domoticz. -## Alternate Install/Update: - -* Simply create a directory under domoticz/plugins directory like 'TUYA' and download/copy the plugin.py file and tuyaha directory (with all its contents) into it. -* Restart Domoticz. - ## Configuration Enter your username and password for your app account along with your country code (1=US/Canada, 55=Brazil, etc). The initial setup of your devices should be done with the app and this plugin will detect/use the same settings and automatically find/add the devices into Domoticz. From c3204912cd8463bb6bfd6c4880794a8fb00ba927 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 18 Sep 2020 07:17:40 +0200 Subject: [PATCH 05/77] Change some text. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 144660f..27269ec 100644 --- a/README.md +++ b/README.md @@ -47,4 +47,5 @@ Devices detected are created in the 'Devices' tab, to use them you need to click # Original project: -Cloned from https://github.com/guino/tuyaha to make a standalone project. +Fork from https://github.com/guino/tuyaha to make a standalone project. + From cfc1e7d65a4f53123a80b67699f775c162359fa7 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Oct 2020 20:40:05 +0200 Subject: [PATCH 06/77] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 27269ec..7be76bc 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* The plugin required Python library tuyaha and requests ```pip3 install tuyaha requests``` +* The plugin required Python library tuyaha and requests ```pip3 install tuyaha==0.0.7 requests``` * Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. From 863270f4b222fd3c3c3f8e421827730f820f7a1f Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Oct 2020 20:51:48 +0200 Subject: [PATCH 07/77] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7be76bc..27269ec 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* The plugin required Python library tuyaha and requests ```pip3 install tuyaha==0.0.7 requests``` +* The plugin required Python library tuyaha and requests ```pip3 install tuyaha requests``` * Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. From 2c61124ed4ec16730c66e93db22f56eb7b4059db Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Oct 2020 21:30:46 +0200 Subject: [PATCH 08/77] modified: plugin.py --- plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index a296b51..6ac41bc 100644 --- a/plugin.py +++ b/plugin.py @@ -6,7 +6,7 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - +

TUYA Plugin


This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. @@ -68,6 +68,7 @@ class BasePlugin: last_update = 0 def __init__(self): + self.pollinterval = 600 return def onStart(self): @@ -149,7 +150,7 @@ def onCommand(self, Unit, Command, Level, Hue): dev.set_color( [ h*360, s*100 ] ) Domoticz.Debug("Set color called") if mode == 2: - temp = round(1000+(9000/255*(255-t))) + temp = round(2700+((6500-2700)/255*(255-t))) Domoticz.Debug("temp = " + str(temp)) dev.set_color_temp( temp ) Domoticz.Debug("Set white called") From 4e98aecd4395d30e83d33d7c855eb4bbd6885941 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Oct 2020 22:14:53 +0200 Subject: [PATCH 09/77] modified: plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 6ac41bc..d98752a 100644 --- a/plugin.py +++ b/plugin.py @@ -68,7 +68,7 @@ class BasePlugin: last_update = 0 def __init__(self): - self.pollinterval = 600 + self.tuya._discovery_interval = 600 return def onStart(self): From bde3e3f78837c2e6c77bfe47d89e2599a022531b Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Oct 2020 22:21:02 +0200 Subject: [PATCH 10/77] modified: README.md and plugin.py --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7be76bc..4f3e136 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* The plugin required Python library tuyaha and requests ```pip3 install tuyaha==0.0.7 requests``` +* The plugin required Python library tuyaha and requests ```pip3 install tuyaha requests``` * Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. @@ -41,6 +41,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.3 | Update for tuyaha 0.0.8 | | 1.0.2 | Update light support added temperature control | | 1.0.1 | Support for SmartLife and Jinvoo Apps | | 1.0.0 | Initial upload version | From b2f883f6c2d939e4223798331091cc509e04b32f Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 28 Oct 2020 12:18:53 +0100 Subject: [PATCH 11/77] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4f3e136..dc58971 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Controls TUYA devices your network (mainly on/off switches and Lights). Tuya dev * Auto-detects devices on your account * Tested with lights and switches (but should control other devices on/off) * Cloud control only uses your user/password account with encrypted communications without requiring IP or device IDs or Keys to configure it -* Allows controlling Dimmer/RGB Color for lights +* Allows controlling Dimmer/RGB(WW) Color for lights * Supports scene activation ## Installation @@ -46,7 +46,10 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | 1.0.1 | Support for SmartLife and Jinvoo Apps | | 1.0.0 | Initial upload version | +## Note + +I can only support devices or with similar functions that I have myself. Thank you for your understanding. + # Original project: Fork from https://github.com/guino/tuyaha to make a standalone project. - From d1c0767e65abdd3efc4dbe7de4525cf41bf582d7 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 28 Oct 2020 12:20:42 +0100 Subject: [PATCH 12/77] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4f3e136..dc58971 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Controls TUYA devices your network (mainly on/off switches and Lights). Tuya dev * Auto-detects devices on your account * Tested with lights and switches (but should control other devices on/off) * Cloud control only uses your user/password account with encrypted communications without requiring IP or device IDs or Keys to configure it -* Allows controlling Dimmer/RGB Color for lights +* Allows controlling Dimmer/RGB(WW) Color for lights * Supports scene activation ## Installation @@ -46,7 +46,10 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | 1.0.1 | Support for SmartLife and Jinvoo Apps | | 1.0.0 | Initial upload version | +## Note + +I can only support devices or with similar functions that I have myself. Thank you for your understanding. + # Original project: Fork from https://github.com/guino/tuyaha to make a standalone project. - From a552243b9f0ff083046275e1f0681454208091e8 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Tue, 8 Dec 2020 21:37:32 +0100 Subject: [PATCH 13/77] Update README.md Add update for the tuyaha and requests library. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc58971..9294d87 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,14 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* The plugin required Python library tuyaha and requests ```pip3 install tuyaha requests``` +* The plugin required Python library tuyaha and requests ```sudo pip3 install tuyaha requests``` * Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. ## Updating To update: +* Upgrade the tuyaha and requests library ```sudo pip3 install tuyaha requests --upgrade``` * Go in your Domoticz directory using a command line and open the plugins directory then the Domoticz-TUYA directory. * Run: ```git pull``` * Restart Domoticz. From 22d2555ea6a3228ae60bb4e4ef74d998d8f5873f Mon Sep 17 00:00:00 2001 From: Xenomes Date: Tue, 8 Dec 2020 21:50:34 +0100 Subject: [PATCH 14/77] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9294d87..a0f3cf7 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | 1.0.1 | Support for SmartLife and Jinvoo Apps | | 1.0.0 | Initial upload version | +## My device is not listed in Tuya API response or contains incomplete state, what should I do? + +Write an email to tuyasmart@tuya.com and mention the tuyapy library and https://px1.tuya{}.com API endpoint. Usually they ignore incoming emails, but perhaps, if they get a lot of emails, they will start fixing the API. + ## Note I can only support devices or with similar functions that I have myself. Thank you for your understanding. From e2b44eb27a4533bbb3b2890e040a1d49cdbf9725 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 13 Jan 2021 19:40:08 +0100 Subject: [PATCH 15/77] Update plugin.py Add light device if no match found in the json. --- plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index d98752a..b65f82c 100644 --- a/plugin.py +++ b/plugin.py @@ -6,7 +6,7 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - +

TUYA Plugin


This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. @@ -227,6 +227,8 @@ def handleThread(self): # Light On/Off control Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=7, Image=0, DeviceID=dev.object_id()).Create() else: + # Light On/Off control + Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=7, Image=0, DeviceID=dev.object_id()).Create() Domoticz.Debug("No controls found for your light device!") elif dev_type == "climate": Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=0, Image=16, DeviceID=dev.object_id()).Create() From c70a56d38cd737fdb8df60bbd72fa9ff6d8ce802 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 13 Jan 2021 19:41:37 +0100 Subject: [PATCH 16/77] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a0f3cf7..b1f920f 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.4 | Add light device if no match found in the json | | 1.0.3 | Update for tuyaha 0.0.8 | | 1.0.2 | Update light support added temperature control | | 1.0.1 | Support for SmartLife and Jinvoo Apps | From ba7d6dc89ed0b821b98d3949d64df1bcb3171e1d Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 13 Jan 2021 20:01:21 +0100 Subject: [PATCH 17/77] Update plugin.py Add light device if no match found in the json. --- plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin.py b/plugin.py index b65f82c..9954933 100644 --- a/plugin.py +++ b/plugin.py @@ -6,15 +6,15 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + -

TUYA Plugin


+

TUYA Plugin v.1.0.4


This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

Features

  • Auto-detection of devices on network
  • On/Off control, state and available status display
  • -
  • Dimmer/RGB Color setting for Lights
  • +
  • Dimmer/RGBWW Color setting for Lights
  • Scene activation support

Devices

From 342addc50bce4a27af2595842fb62c02d22c2699 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 21 Mar 2021 20:17:26 +0100 Subject: [PATCH 18/77] Fixed update time api to Domoticz from 10 min to 1 min --- README.md | 1 + plugin.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b1f920f..8e21446 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.5 | Fixed update time api to Domoticz from 10 min to 1 min | | 1.0.4 | Add light device if no match found in the json | | 1.0.3 | Update for tuyaha 0.0.8 | | 1.0.2 | Update light support added temperature control | diff --git a/plugin.py b/plugin.py index 9954933..d07f785 100644 --- a/plugin.py +++ b/plugin.py @@ -6,9 +6,9 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + -

TUYA Plugin v.1.0.4


+

TUYA Plugin v.1.0.5


This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

Features

    @@ -69,6 +69,8 @@ class BasePlugin: def __init__(self): self.tuya._discovery_interval = 600 + self.tuya._query_interval = 30 + self.tuya._force_discovery = True return def onStart(self): @@ -177,8 +179,8 @@ def onDisconnect(self, Connection): def onHeartbeat(self): Domoticz.Debug("onHeartbeat called time="+str(time.time())) - # If it hasn't been at least 1 minute (corrected for ~2s runtime) since last update, skip it - if time.time() - self.last_update < 58: + # If it hasn't been at least 1 minute since last update, skip it + if time.time() - self.last_update < 60: return self.startup = False # Create/Start update thread @@ -193,8 +195,10 @@ def handleThread(self): if self.startup == True: self.devs = self.tuya.init(Parameters["Username"], Parameters["Password"], Parameters["Mode1"], Parameters["Mode2"]) else: - self.tuya.check_access_token() - self.tuya.poll_devices_update() + self.tuya._force_discovery = True + self.tuya.refresh_access_token() + self.tuya.discover_devices() + #self.tuya.poll_devices_update() self.devs = self.tuya.get_all_devices() # Set last update From 1950c54fce18b9c8de363d2dec7e6da5dca4b315 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 31 Mar 2021 21:39:50 +0200 Subject: [PATCH 19/77] Update plugin.py Change detection of RGB(WW) and White lights --- plugin.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugin.py b/plugin.py index d98752a..c86ba93 100644 --- a/plugin.py +++ b/plugin.py @@ -1,4 +1,3 @@ - # Domoticz TUYA Plugin # # Author: Wagner Oliveira (wbbo@hotmail.com) @@ -6,15 +5,15 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + -

    TUYA Plugin


    +

    TUYA Plugin v.1.0.6a


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

    Features

    • Auto-detection of devices on network
    • On/Off control, state and available status display
    • -
    • Dimmer/RGB Color setting for Lights
    • +
    • Dimmer/RGBWW Color setting for Lights
    • Scene activation support

    Devices

    @@ -69,6 +68,8 @@ class BasePlugin: def __init__(self): self.tuya._discovery_interval = 600 + self.tuya._query_interval = 30 + self.tuya._force_discovery = True return def onStart(self): @@ -177,8 +178,8 @@ def onDisconnect(self, Connection): def onHeartbeat(self): Domoticz.Debug("onHeartbeat called time="+str(time.time())) - # If it hasn't been at least 1 minute (corrected for ~2s runtime) since last update, skip it - if time.time() - self.last_update < 58: + # If it hasn't been at least 1 minute since last update, skip it + if time.time() - self.last_update < 60: return self.startup = False # Create/Start update thread @@ -193,8 +194,10 @@ def handleThread(self): if self.startup == True: self.devs = self.tuya.init(Parameters["Username"], Parameters["Password"], Parameters["Mode1"], Parameters["Mode2"]) else: - self.tuya.check_access_token() - self.tuya.poll_devices_update() + self.tuya._force_discovery = True + self.tuya.refresh_access_token() + self.tuya.discover_devices() + #self.tuya.poll_devices_update() self.devs = self.tuya.get_all_devices() # Set last update @@ -211,22 +214,24 @@ def handleThread(self): unit = nextUnit() dev_type = dev.device_type() if dev_type == "light": - if dev.data.get("color_mode") is not None and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + if dev.data.get("color_mode") is 'Colour' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: # Light Color and White temperature contol Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=4, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is not None and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") is 'Colour' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: # Light Color control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") is 'White' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: # Light White temperature control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=8, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") is 'White' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: # Light Brightness control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=3, Switchtype=7, DeviceID=dev.object_id()).Create() elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is None and dev.data.get("brightness") is None: # Light On/Off control Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=7, Image=0, DeviceID=dev.object_id()).Create() else: + # Light On/Off control + Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=7, Image=0, DeviceID=dev.object_id()).Create() Domoticz.Debug("No controls found for your light device!") elif dev_type == "climate": Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=0, Image=16, DeviceID=dev.object_id()).Create() From 1779cef12987a27d3bcf2ac8bcd9b49cbcf8c587 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 31 Mar 2021 21:47:51 +0200 Subject: [PATCH 20/77] Update README.md Added detection for White and RGB(WW) lights --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dc58971..ea977c5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Controls TUYA devices your network (mainly on/off switches and Lights). Tuya dev * Auto-detects devices on your account * Tested with lights and switches (but should control other devices on/off) * Cloud control only uses your user/password account with encrypted communications without requiring IP or device IDs or Keys to configure it -* Allows controlling Dimmer/RGB(WW) Color for lights +* Allows controlling Dimmer/RGB(WW) Color for lights (⚠ RGBW(W) lights mustbe on a color for correct detection ⚠) * Supports scene activation ## Installation @@ -17,13 +17,14 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* The plugin required Python library tuyaha and requests ```pip3 install tuyaha requests``` +* The plugin required Python library tuyaha and requests ```sudo pip3 install tuyaha requests``` * Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. ## Updating To update: +* Upgrade the tuyaha and requests library ```sudo pip3 install tuyaha requests --upgrade``` * Go in your Domoticz directory using a command line and open the plugins directory then the Domoticz-TUYA directory. * Run: ```git pull``` * Restart Domoticz. @@ -41,15 +42,18 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.6 | Added detection for White and RGB(WW) lights| +| 1.0.5 | Fixed update time api to Domoticz from 10 min to 1 min | +| 1.0.4 | Add light device if no match found in the json | | 1.0.3 | Update for tuyaha 0.0.8 | | 1.0.2 | Update light support added temperature control | | 1.0.1 | Support for SmartLife and Jinvoo Apps | | 1.0.0 | Initial upload version | -## Note +## My device is not listed in Tuya API response or contains incomplete state, what should I do? -I can only support devices or with similar functions that I have myself. Thank you for your understanding. +Write an email to tuyasmart@tuya.com and mention the tuyapy library and https://px1.tuya{}.com API endpoint. Usually they ignore incoming emails, but perhaps, if they get a lot of emails, they will start fixing the API. -# Original project: +## Note -Fork from https://github.com/guino/tuyaha to make a standalone project. +I can only support devices or with similar functions that I have myself. Thank you for your understanding. From 1e839c1394b2a5a3c84a513b350f8136a832e57d Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 31 Mar 2021 22:00:08 +0200 Subject: [PATCH 21/77] Update plugin.py --- plugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index c86ba93..83126b6 100644 --- a/plugin.py +++ b/plugin.py @@ -214,16 +214,16 @@ def handleThread(self): unit = nextUnit() dev_type = dev.device_type() if dev_type == "light": - if dev.data.get("color_mode") is 'Colour' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + if dev.data.get("color_mode") is 'colour' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: # Light Color and White temperature contol Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=4, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is 'Colour' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") is 'colour' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: # Light Color control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is 'White' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") is 'white' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: # Light White temperature control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=8, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is 'White' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") is 'white' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: # Light Brightness control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=3, Switchtype=7, DeviceID=dev.object_id()).Create() elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is None and dev.data.get("brightness") is None: From 0949c806966f6b9ba2df2e1b2edfc922c38779ce Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 31 Mar 2021 22:07:07 +0200 Subject: [PATCH 22/77] Update plugin.py --- plugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index 83126b6..6000763 100644 --- a/plugin.py +++ b/plugin.py @@ -214,16 +214,16 @@ def handleThread(self): unit = nextUnit() dev_type = dev.device_type() if dev_type == "light": - if dev.data.get("color_mode") is 'colour' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + if dev.data.get("color_mode") == 'colour' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: # Light Color and White temperature contol Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=4, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is 'colour' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") == 'colour' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: # Light Color control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is 'white' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") == 'white' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: # Light White temperature control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=8, Switchtype=7, DeviceID=dev.object_id()).Create() - elif dev.data.get("color_mode") is 'white' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: + elif dev.data.get("color_mode") == 'white' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: # Light Brightness control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=3, Switchtype=7, DeviceID=dev.object_id()).Create() elif dev.data.get("color_mode") is None and dev.data.get("color_temp") is None and dev.data.get("brightness") is None: From fb027239e64031bcb13b624cdaf38fb8a676e06a Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 1 Apr 2021 22:06:34 +0200 Subject: [PATCH 23/77] Update README.md Typo --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9398dff..257cf68 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,7 @@ Controls TUYA devices your network (mainly on/off switches and Lights). Tuya dev * Auto-detects devices on your account * Tested with lights and switches (but should control other devices on/off) * Cloud control only uses your user/password account with encrypted communications without requiring IP or device IDs or Keys to configure it -* Allows controlling Dimmer/RGB(WW) Color for lights - (⚠ RGBW(W) lights mustbe on a color for correct detection ⚠) +* Allows controlling Dimmer/RGB(WW) Color for lights (⚠ RGBW(W) lights must be on a colour for correct detection ⚠) * Supports scene activation ## Installation @@ -61,4 +60,4 @@ I can only support devices or with similar functions that I have myself. Thank y # Original project: -Fork from https://github.com/guino/tuyaha to make a standalone project. \ No newline at end of file +Fork from https://github.com/guino/tuyaha to make a standalone project. From bd662ecdbc308501b2b6de29c6b97e9a78f404b0 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 2 Apr 2021 12:25:36 +0200 Subject: [PATCH 24/77] Update plugin.py Added extra detection --- plugin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin.py b/plugin.py index c0cadd2..412d64d 100644 --- a/plugin.py +++ b/plugin.py @@ -220,6 +220,9 @@ def handleThread(self): elif dev.data.get("color_mode") == 'colour' and dev.data.get("color_temp") is None and dev.data.get("brightness") is not None: # Light Color control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create() + elif dev.data.get("color_mode") == 'colour' and dev.data.get("color_temp") is None and dev.data.get("brightness") is None: + # Light Color control + Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create() elif dev.data.get("color_mode") == 'white' and dev.data.get("color_temp") is not None and dev.data.get("brightness") is not None: # Light White temperature control Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=8, Switchtype=7, DeviceID=dev.object_id()).Create() From 5052da74c1ee46205e36f94c2d4eba584198e5ec Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 3 Apr 2021 09:50:11 +0200 Subject: [PATCH 25/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 412d64d..7487b96 100644 --- a/plugin.py +++ b/plugin.py @@ -5,7 +5,7 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - +

    TUYA Plugin v.1.0.6


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. From f754a03092feec249919df797c1dbbc55b31a4d0 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 3 Apr 2021 09:58:14 +0200 Subject: [PATCH 26/77] Update plugin.py --- plugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 7487b96..ba2267c 100644 --- a/plugin.py +++ b/plugin.py @@ -5,8 +5,11 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145 + Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846 +

    TUYA Plugin v.1.0.6


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

    Features

    From 9b304810428f3b06e94fc4f741ab41c96e04b243 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 3 Apr 2021 10:08:24 +0200 Subject: [PATCH 27/77] Update plugin.py --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index ba2267c..4eaf2a3 100644 --- a/plugin.py +++ b/plugin.py @@ -7,8 +7,8 @@ """ - Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145 - Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846 + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
    + Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

    TUYA Plugin v.1.0.6


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. From 45a137df90e2701990fa656acb9bbcf916de0c09 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 3 Apr 2021 10:28:57 +0200 Subject: [PATCH 28/77] Update plugin.py --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index 4eaf2a3..8b9b470 100644 --- a/plugin.py +++ b/plugin.py @@ -7,8 +7,8 @@ """ - Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
    - Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846
    + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65%26t=33145
    + Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60%26t=846

    TUYA Plugin v.1.0.6


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. From 336a2da2eba5b18610777d17ea5d694717a8dc7a Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 3 Apr 2021 10:37:34 +0200 Subject: [PATCH 29/77] Update plugin.py --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index 8b9b470..d2d3ea8 100644 --- a/plugin.py +++ b/plugin.py @@ -7,8 +7,8 @@ """ - Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65%26t=33145
    - Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60%26t=846
    + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65t=33145
    + Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60t=846

    TUYA Plugin v.1.0.6


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. From 6e1e31295ffe953cc7f5206efcdee14f3abb3312 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 3 Apr 2021 10:46:19 +0200 Subject: [PATCH 30/77] Update plugin.py --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index d2d3ea8..9e93846 100644 --- a/plugin.py +++ b/plugin.py @@ -7,8 +7,8 @@ """ - Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65t=33145
    - Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60t=846
    + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
    + Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

    TUYA Plugin v.1.0.6


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below. From 1174bc6d17ba2eefa6a6883c97aa0fb2750d8761 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 3 Apr 2021 19:29:49 +0200 Subject: [PATCH 31/77] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 257cf68..7c6bf1a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Controls TUYA devices your network (mainly on/off switches and Lights). Tuya dev * Auto-detects devices on your account * Tested with lights and switches (but should control other devices on/off) * Cloud control only uses your user/password account with encrypted communications without requiring IP or device IDs or Keys to configure it -* Allows controlling Dimmer/RGB(WW) Color for lights (⚠ RGBW(W) lights must be on a colour for correct detection ⚠) +* Allows controlling Dimmer/RGB(WW) Colour for lights (⚠ RGBW(W) lights must be on a colour for correct detection ⚠) * Supports scene activation ## Installation From ac38bad355ace572e8dff9cf201bbafb519a6ef2 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 16 Apr 2021 20:24:35 +0200 Subject: [PATCH 32/77] Added fix for error Tuyaapi time-out --- README.md | 1 + fakeDomoticz.py | 8 ++++++++ plugin.py | 25 +++++++++++++++---------- 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100755 fakeDomoticz.py mode change 100644 => 100755 plugin.py diff --git a/README.md b/README.md index 257cf68..1830948 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.7 | Added fix for error Tuyaapi time-out| | 1.0.6 | Added detection for White and RGB(WW) lights| | 1.0.5 | Fixed update time api to Domoticz from 10 min to 1 min | | 1.0.4 | Add light device if no match found in the json | diff --git a/fakeDomoticz.py b/fakeDomoticz.py new file mode 100755 index 0000000..9e9e30f --- /dev/null +++ b/fakeDomoticz.py @@ -0,0 +1,8 @@ +def Log(s): + print(s) + +def Error(s): + print(s) + +def Debug(s): + print(s) diff --git a/plugin.py b/plugin.py old mode 100644 new mode 100755 index 9e93846..b0b8c58 --- a/plugin.py +++ b/plugin.py @@ -10,7 +10,7 @@ Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
    Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

    -

    TUYA Plugin v.1.0.6


    +

    TUYA Plugin v.1.0.7


    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

    Features

      @@ -53,7 +53,10 @@ """ -import Domoticz +try: + import Domoticz +except ImportError: + import fakeDomoticz as Domoticz import threading import socket import html @@ -76,6 +79,8 @@ def __init__(self): return def onStart(self): + Domoticz.Log("Waiting 60 seconds to connect TuyaApi login timeout") + time.sleep(60) Domoticz.Log("TUYA plugin started") if Parameters["Mode6"] != "0": Domoticz.Debugging(int(Parameters["Mode6"])) @@ -151,13 +156,13 @@ def onCommand(self, Unit, Command, Level, Hue): # If color changed if Devices[Unit].Color != Hue: if mode == 3: - dev.set_color( [ h*360, s*100 ] ) - Domoticz.Debug("Set color called") + dev.set_color( [ h*360, s*100 ] ) + Domoticz.Debug("Set color called") if mode == 2: - temp = round(2700+((6500-2700)/255*(255-t))) - Domoticz.Debug("temp = " + str(temp)) - dev.set_color_temp( temp ) - Domoticz.Debug("Set white called") + temp = round(2700+((6500-2700)/255*(255-t))) + Domoticz.Debug("temp = " + str(temp)) + dev.set_color_temp( temp ) + Domoticz.Debug("Set white called") # If level changed if Devices[Unit].sValue != str(Level): dev.set_brightness(round(Level*2.55)) @@ -182,7 +187,7 @@ def onDisconnect(self, Connection): def onHeartbeat(self): Domoticz.Debug("onHeartbeat called time="+str(time.time())) # If it hasn't been at least 1 minute since last update, skip it - if time.time() - self.last_update < 60: + if time.time() - self.last_update < 61: return self.startup = False # Create/Start update thread @@ -194,6 +199,7 @@ def handleThread(self): try: Domoticz.Debug("in handlethread") # Initialize/Update devices from TUYA API + Domoticz.Log( "self.startup" + str(self.startup)) if self.startup == True: self.devs = self.tuya.init(Parameters["Username"], Parameters["Password"], Parameters["Mode1"], Parameters["Mode2"]) else: @@ -261,7 +267,6 @@ def handleThread(self): except Exception as err: Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno)) - global _plugin _plugin = BasePlugin() From 488ab05b4d2707724c81e876600875a1c2556a45 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 17 Apr 2021 16:59:49 +0200 Subject: [PATCH 33/77] Little fix --- plugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index b0b8c58..9ac2af6 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
      Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

      -

      TUYA Plugin v.1.0.7


      +

      TUYA Plugin v.1.0.7a


      This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

      Features

        @@ -199,12 +199,12 @@ def handleThread(self): try: Domoticz.Debug("in handlethread") # Initialize/Update devices from TUYA API - Domoticz.Log( "self.startup" + str(self.startup)) if self.startup == True: self.devs = self.tuya.init(Parameters["Username"], Parameters["Password"], Parameters["Mode1"], Parameters["Mode2"]) else: self.tuya._force_discovery = True - self.tuya.refresh_access_token() + self.tuya.get_access_token() + #self.tuya.refresh_access_token() self.tuya.discover_devices() #self.tuya.poll_devices_update() self.devs = self.tuya.get_all_devices() From 58bac148916350b20b7c8a95a66ef46ec8f6b42b Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 21 Apr 2021 22:36:46 +0200 Subject: [PATCH 34/77] Bug fixing! --- plugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin.py b/plugin.py index 9ac2af6..cf02292 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
        Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

        -

        TUYA Plugin v.1.0.7a


        +

        TUYA Plugin v.1.0.7b


        This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

        Features

          @@ -203,10 +203,10 @@ def handleThread(self): self.devs = self.tuya.init(Parameters["Username"], Parameters["Password"], Parameters["Mode1"], Parameters["Mode2"]) else: self.tuya._force_discovery = True - self.tuya.get_access_token() - #self.tuya.refresh_access_token() + time.sleep(0.5) + self.tuya.refresh_access_token() + time.sleep(0.5) self.tuya.discover_devices() - #self.tuya.poll_devices_update() self.devs = self.tuya.get_all_devices() # Set last update From 916cfb94c9dc1db5e36df63b32beb23ee5063f4f Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 22 Apr 2021 21:17:18 +0200 Subject: [PATCH 35/77] Added fix for 0 device detection --- README.md | 1 + plugin.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 06c7753..fb9f280 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.8 | Added fix for 0 device detection| | 1.0.7 | Added fix for error Tuyaapi time-out| | 1.0.6 | Added detection for White and RGB(WW) lights| | 1.0.5 | Fixed update time api to Domoticz from 10 min to 1 min | diff --git a/plugin.py b/plugin.py index cf02292..52a90da 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
          Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

          -

          TUYA Plugin v.1.0.7b


          +

          TUYA Plugin v.1.0.8


          This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

          Features

            @@ -202,12 +202,14 @@ def handleThread(self): if self.startup == True: self.devs = self.tuya.init(Parameters["Username"], Parameters["Password"], Parameters["Mode1"], Parameters["Mode2"]) else: - self.tuya._force_discovery = True - time.sleep(0.5) - self.tuya.refresh_access_token() - time.sleep(0.5) - self.tuya.discover_devices() - self.devs = self.tuya.get_all_devices() + Domoticz.Debug("Device count: " + str(len(Devices))) + if int(len(self.tuya.get_all_devices())) > 0: + self.tuya._force_discovery = True + time.sleep(0.5) + self.tuya.refresh_access_token() + time.sleep(0.5) + self.tuya.discover_devices() + self.devs = self.tuya.get_all_devices() # Set last update self.last_update = time.time() From c61ecbccda0ea4fbc16b4d164cc9c2561d81322d Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 2 May 2021 20:57:48 +0200 Subject: [PATCH 36/77] Changed the detected scene's switch type to push button. --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 52a90da..06bad42 100755 --- a/plugin.py +++ b/plugin.py @@ -250,7 +250,7 @@ def handleThread(self): elif dev_type == "climate": Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=0, Image=16, DeviceID=dev.object_id()).Create() elif dev_type == "scene": - Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=0, Image=9, DeviceID=dev.object_id()).Create() + Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=9, Image=9, DeviceID=dev.object_id()).Create() elif dev_type == "fan": Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=0, Image=7, DeviceID=dev.object_id()).Create() elif dev_type == "cover": From f3c74f139532ff0de14a0c4dfb6ecc13b51f2d1f Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 2 May 2021 21:15:51 +0200 Subject: [PATCH 37/77] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fb9f280..0281ba4 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.9 | Changed scene switch type to push button| | 1.0.8 | Added fix for 0 device detection| | 1.0.7 | Added fix for error Tuyaapi time-out| | 1.0.6 | Added detection for White and RGB(WW) lights| From 965b6d05569c2eb2e7cac0d0648840dcaab583a4 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 2 May 2021 21:17:04 +0200 Subject: [PATCH 38/77] Changed the detected scene's switch type to push button. --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index 06bad42..b73d518 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
            Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

            -

            TUYA Plugin v.1.0.8


            +

            TUYA Plugin v.1.0.9


            This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

            Features

              From 9c2df82ae5acce1102e95a4db9866eda29da9cbb Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 24 Jun 2021 20:01:53 +0200 Subject: [PATCH 39/77] Update plugin.py Device is offline error changed to log level --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index b73d518..556502a 100755 --- a/plugin.py +++ b/plugin.py @@ -123,7 +123,7 @@ def onCommand(self, Unit, Command, Level, Hue): return if not dev.available(): - Domoticz.Error('Command for DeviceID='+Devices[Unit].DeviceID+' but device is offline.') + Domoticz.Log('Command for DeviceID='+Devices[Unit].DeviceID+' but device is offline.') return Domoticz.Log('Sending command for DeviceID='+Devices[Unit].DeviceID) From 6d92b1545f458e5ca7621aeafc3a106de30fc430 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 24 Jun 2021 20:24:33 +0200 Subject: [PATCH 40/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 556502a..1207b88 100755 --- a/plugin.py +++ b/plugin.py @@ -119,7 +119,7 @@ def onCommand(self, Unit, Command, Level, Hue): # If we didn't find it, leave (probably disconnected at this time) if dev == None: - Domoticz.Error('Command for DeviceID='+Devices[Unit].DeviceID+' but device is not available.') + Domoticz.Log('Command for DeviceID='+Devices[Unit].DeviceID+' but device is not available.') return if not dev.available(): From 0fbfb1804aa2a95e03eb08f4e2d0e9e8c97d33ca Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 24 Jun 2021 20:58:20 +0200 Subject: [PATCH 41/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 1207b88..cbd5ded 100755 --- a/plugin.py +++ b/plugin.py @@ -107,7 +107,7 @@ def onMessage(self, Connection, Data): Domoticz.Debug("onMessage called") def onCommand(self, Unit, Command, Level, Hue): - Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level)) + # Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level)) # Find the device for the Domoticz unit number provided dev = None From a38198bb7598e70a1d8de24d6a15b734c6e77d05 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 24 Jun 2021 21:29:01 +0200 Subject: [PATCH 42/77] Update plugin.py --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index cbd5ded..556502a 100755 --- a/plugin.py +++ b/plugin.py @@ -107,7 +107,7 @@ def onMessage(self, Connection, Data): Domoticz.Debug("onMessage called") def onCommand(self, Unit, Command, Level, Hue): - # Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level)) + Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level)) # Find the device for the Domoticz unit number provided dev = None @@ -119,7 +119,7 @@ def onCommand(self, Unit, Command, Level, Hue): # If we didn't find it, leave (probably disconnected at this time) if dev == None: - Domoticz.Log('Command for DeviceID='+Devices[Unit].DeviceID+' but device is not available.') + Domoticz.Error('Command for DeviceID='+Devices[Unit].DeviceID+' but device is not available.') return if not dev.available(): From c075ed6160749a58e013ebe2bfc8439d75edfda7 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Jul 2021 22:03:20 +0200 Subject: [PATCH 43/77] Update plugin.py Added turn off for off-line devices. --- plugin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin.py b/plugin.py index 556502a..eb4218e 100755 --- a/plugin.py +++ b/plugin.py @@ -266,6 +266,10 @@ def handleThread(self): else: UpdateDevice(unit, 1, 'On', not dev.available()) + if dev.state() == True and not dev.available(): + UpdateDevice(unit, 0, 'Off', not dev.available()) + Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') + except Exception as err: Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno)) From 2ce03d0bbb8bfe1c9f76e8051c1c51053533f28a Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Jul 2021 22:05:55 +0200 Subject: [PATCH 44/77] Update plugin.py Added turn off for off-line devices. --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index eb4218e..58f7975 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
              Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

              -

              TUYA Plugin v.1.0.9


              +

              TUYA Plugin v.1.0.10


              This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

              Features

                From 669241c1d89a869abee70d8133582e37b47755f6 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 7 Jul 2021 22:07:05 +0200 Subject: [PATCH 45/77] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0281ba4..8cf6680 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.10 | Added turn off for off-line devices| | 1.0.9 | Changed scene switch type to push button| | 1.0.8 | Added fix for 0 device detection| | 1.0.7 | Added fix for error Tuyaapi time-out| From cfeaeabdd249117540b79b900e604a766b5fe0e5 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 9 Jul 2021 22:30:04 +0200 Subject: [PATCH 46/77] Update plugin.py Added stop for cover or blinds --- plugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index 58f7975..b42d8ac 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
                Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

                -

                TUYA Plugin v.1.0.10


                +

                TUYA Plugin v.1.0.11


                This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

                Features

                  @@ -146,6 +146,8 @@ def onCommand(self, Unit, Command, Level, Hue): else: dev.turn_off(); UpdateDevice(Unit, 0, 'Off', not dev.available()) + elif dev_type == 'cover' and Command == 'stop': + dev.stop_cover() elif Command == 'Set Color': # Convert RGB to Hue+Saturation rgb = json.loads(Hue) From 400781d5f6e48fb813fb2048f1145d12c16e32eb Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 9 Jul 2021 22:31:15 +0200 Subject: [PATCH 47/77] Update README.md Added stop for cover or blinds --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8cf6680..a4dd813 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,12 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | -| 1.0.10 | Added turn off for off-line devices| -| 1.0.9 | Changed scene switch type to push button| -| 1.0.8 | Added fix for 0 device detection| -| 1.0.7 | Added fix for error Tuyaapi time-out| -| 1.0.6 | Added detection for White and RGB(WW) lights| +| 1.0.11 | Added stop for cover or blinds | +| 1.0.10 | Added turn off for off-line devices | +| 1.0.9 | Changed scene switch type to push button | +| 1.0.8 | Added fix for 0 device detection | +| 1.0.7 | Added fix for error Tuyaapi time-out | +| 1.0.6 | Added detection for White and RGB(WW) lights | | 1.0.5 | Fixed update time api to Domoticz from 10 min to 1 min | | 1.0.4 | Add light device if no match found in the json | | 1.0.3 | Update for tuyaha 0.0.8 | From 1b8fa096c6824ede907a41d8d18bf95533219dcc Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 10 Jul 2021 15:38:49 +0200 Subject: [PATCH 48/77] Update plugin.py Fixed typo --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index b42d8ac..7fea3b1 100755 --- a/plugin.py +++ b/plugin.py @@ -146,7 +146,7 @@ def onCommand(self, Unit, Command, Level, Hue): else: dev.turn_off(); UpdateDevice(Unit, 0, 'Off', not dev.available()) - elif dev_type == 'cover' and Command == 'stop': + elif dev_type == 'cover' and Command == 'Stop': dev.stop_cover() elif Command == 'Set Color': # Convert RGB to Hue+Saturation From 4a5c61d40a20e734a3e26421c28ed24cb3c771c3 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 10 Jul 2021 20:44:15 +0200 Subject: [PATCH 49/77] Update plugin.py --- plugin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin.py b/plugin.py index 7fea3b1..7811d1d 100755 --- a/plugin.py +++ b/plugin.py @@ -268,6 +268,9 @@ def handleThread(self): else: UpdateDevice(unit, 1, 'On', not dev.available()) + if dev_type == "cover" and dev.state() <> 'Stop': + UpdateDevice(unit, 1, 'Stop', not dev.available()) + if dev.state() == True and not dev.available(): UpdateDevice(unit, 0, 'Off', not dev.available()) Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') From 1eaeeddfbba900c4b28ef904f8a45b5ec363820a Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 10 Jul 2021 20:48:25 +0200 Subject: [PATCH 50/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 7811d1d..6d12c21 100755 --- a/plugin.py +++ b/plugin.py @@ -268,7 +268,7 @@ def handleThread(self): else: UpdateDevice(unit, 1, 'On', not dev.available()) - if dev_type == "cover" and dev.state() <> 'Stop': + if dev_type == "cover" and dev.state() != 'Stop': UpdateDevice(unit, 1, 'Stop', not dev.available()) if dev.state() == True and not dev.available(): From 2475c0d27c3569071ebfc519926ee1d78a4a0ff5 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 10 Jul 2021 20:51:29 +0200 Subject: [PATCH 51/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 6d12c21..28b5149 100755 --- a/plugin.py +++ b/plugin.py @@ -268,7 +268,7 @@ def handleThread(self): else: UpdateDevice(unit, 1, 'On', not dev.available()) - if dev_type == "cover" and dev.state() != 'Stop': + if dev.device_type() == 'cover' and dev.state() != 'Stop': UpdateDevice(unit, 1, 'Stop', not dev.available()) if dev.state() == True and not dev.available(): From 2dd52700cb026253edbf04616104753464ae1122 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 11 Jul 2021 15:33:02 +0200 Subject: [PATCH 52/77] Update plugin.py Update 2 --- plugin.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugin.py b/plugin.py index 28b5149..a6d3747 100755 --- a/plugin.py +++ b/plugin.py @@ -265,11 +265,13 @@ def handleThread(self): # Update device if dev.state() == False: UpdateDevice(unit, 0, 'Off', not dev.available()) - else: + elif dev.state() == True: UpdateDevice(unit, 1, 'On', not dev.available()) + else: + Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' State update skiped. status = '+dev.state) - if dev.device_type() == 'cover' and dev.state() != 'Stop': - UpdateDevice(unit, 1, 'Stop', not dev.available()) + #if dev.device_type() == 'cover' and dev.state() != 'Stop': + # UpdateDevice(unit, 1, 'Stop', not dev.available()) if dev.state() == True and not dev.available(): UpdateDevice(unit, 0, 'Off', not dev.available()) From 7e516443a822f8fed85ea41057eece538557f314 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 11 Jul 2021 20:53:49 +0200 Subject: [PATCH 53/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index a6d3747..03e125a 100755 --- a/plugin.py +++ b/plugin.py @@ -268,7 +268,7 @@ def handleThread(self): elif dev.state() == True: UpdateDevice(unit, 1, 'On', not dev.available()) else: - Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' State update skiped. status = '+dev.state) + Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' State update skiped. status = '+dev.state()) #if dev.device_type() == 'cover' and dev.state() != 'Stop': # UpdateDevice(unit, 1, 'Stop', not dev.available()) From 6a87d2b37b258a31d6efaf3015d3c266db74f866 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 11 Jul 2021 21:10:39 +0200 Subject: [PATCH 54/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 03e125a..b1c7f4a 100755 --- a/plugin.py +++ b/plugin.py @@ -268,7 +268,7 @@ def handleThread(self): elif dev.state() == True: UpdateDevice(unit, 1, 'On', not dev.available()) else: - Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' State update skiped. status = '+dev.state()) + Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' State update skiped. status = '+str(dev.state())) #if dev.device_type() == 'cover' and dev.state() != 'Stop': # UpdateDevice(unit, 1, 'Stop', not dev.available()) From a4481e872210d00977fdeba15dc60a826479025d Mon Sep 17 00:00:00 2001 From: Xenomes Date: Mon, 12 Jul 2021 21:18:04 +0200 Subject: [PATCH 55/77] Update README.md Fix for cover or blinds status --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a4dd813..f25e9e2 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.12 | Fix for cover or blinds status | | 1.0.11 | Added stop for cover or blinds | | 1.0.10 | Added turn off for off-line devices | | 1.0.9 | Changed scene switch type to push button | From e5ab1078d5b71b19e0aec37093c8875753af8a34 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Mon, 12 Jul 2021 21:18:37 +0200 Subject: [PATCH 56/77] Update plugin.py Fix for cover or blinds status --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index b1c7f4a..7b94f0c 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
                  Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

                  -

                  TUYA Plugin v.1.0.11


                  +

                  TUYA Plugin v.1.0.12


                  This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

                  Features

                    From 2805c5d132a4376ce774847549b2da0c773ec2a6 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Tue, 12 Oct 2021 20:44:43 +0200 Subject: [PATCH 57/77] Update plugin.py --- plugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index 7b94f0c..ac48f18 100755 --- a/plugin.py +++ b/plugin.py @@ -10,7 +10,7 @@ Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
                    Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

                    -

                    TUYA Plugin v.1.0.12


                    +

                    TUYA Plugin v.1.0.13


                    This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

                    Features

                      @@ -273,9 +273,9 @@ def handleThread(self): #if dev.device_type() == 'cover' and dev.state() != 'Stop': # UpdateDevice(unit, 1, 'Stop', not dev.available()) - if dev.state() == True and not dev.available(): - UpdateDevice(unit, 0, 'Off', not dev.available()) - Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') + #if dev.state() == True and not dev.available(): + # UpdateDevice(unit, 0, 'Off', not dev.available()) + # Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') except Exception as err: Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno)) From 9fdfdb7da7b8a67c9eb7fc72db7af52684517c1e Mon Sep 17 00:00:00 2001 From: Xenomes Date: Tue, 12 Oct 2021 21:09:10 +0200 Subject: [PATCH 58/77] Update plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index ac48f18..5dcbd58 100755 --- a/plugin.py +++ b/plugin.py @@ -5,7 +5,7 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
                      Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846
                      From 2f963922380e9719cd44f552f7be38cd8ed8c16f Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 13 Oct 2021 20:20:31 +0200 Subject: [PATCH 59/77] Update plugin.py --- plugin.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugin.py b/plugin.py index 5dcbd58..b239550 100755 --- a/plugin.py +++ b/plugin.py @@ -85,9 +85,6 @@ def onStart(self): if Parameters["Mode6"] != "0": Domoticz.Debugging(int(Parameters["Mode6"])) DumpConfigToLog() - # Mark all existing devices as off/timed out initially (until they are discovered) - for u in Devices: - UpdateDevice(u, 0, 'Off', True) # If Mode2 is not set (previous version didn't use it), set it if Parameters["Mode2"] == "": Parameters["Mode2"] = "tuya" @@ -273,9 +270,9 @@ def handleThread(self): #if dev.device_type() == 'cover' and dev.state() != 'Stop': # UpdateDevice(unit, 1, 'Stop', not dev.available()) - #if dev.state() == True and not dev.available(): - # UpdateDevice(unit, 0, 'Off', not dev.available()) - # Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') + if dev.state() == True and not dev.available(): + UpdateDevice(unit, 0, 'Off', not dev.available()) + Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') except Exception as err: Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno)) From 63aa2ea534f677cf76a56634d03802b4ad3f87a3 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 13 Oct 2021 20:29:23 +0200 Subject: [PATCH 60/77] modified: plugin.py --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index b239550..cbceca3 100755 --- a/plugin.py +++ b/plugin.py @@ -184,10 +184,10 @@ def onDisconnect(self, Connection): Domoticz.Debug("onDisconnect called") def onHeartbeat(self): - Domoticz.Debug("onHeartbeat called time="+str(time.time())) # If it hasn't been at least 1 minute since last update, skip it if time.time() - self.last_update < 61: return + Domoticz.Debug("onHeartbeat called time="+str(time.time())) self.startup = False # Create/Start update thread self.updateThread = threading.Thread(name="TUYAUpdateThread", target=BasePlugin.handleThread, args=(self,)) From 01895fe077154c471d86f86950a6c6caa3633592 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Wed, 13 Oct 2021 21:09:21 +0200 Subject: [PATCH 61/77] modified: plugin.py --- plugin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index cbceca3..a3a89aa 100755 --- a/plugin.py +++ b/plugin.py @@ -79,8 +79,14 @@ def __init__(self): return def onStart(self): - Domoticz.Log("Waiting 60 seconds to connect TuyaApi login timeout") - time.sleep(60) + Domoticz.Log("Waiting 60 seconds to connect TuyaApi login error timeout") + t = 60 + t_end = time.time() + t + while time.time() < t_end: + t = t - 1 + Domoticz.Log("Waiting " + str(t) + " seconds to connect TuyaApi (Tuya Plug-in)") + time.sleep(1.0) + Domoticz.Log("TUYA plugin started") if Parameters["Mode6"] != "0": Domoticz.Debugging(int(Parameters["Mode6"])) From fa943c4c7342fcc41d1001561fd4edb594eb2638 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 15 Oct 2021 22:20:45 +0200 Subject: [PATCH 62/77] modified: plugin.py --- plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin.py b/plugin.py index a3a89aa..132b004 100755 --- a/plugin.py +++ b/plugin.py @@ -83,10 +83,9 @@ def onStart(self): t = 60 t_end = time.time() + t while time.time() < t_end: - t = t - 1 + t = t - 10 Domoticz.Log("Waiting " + str(t) + " seconds to connect TuyaApi (Tuya Plug-in)") - time.sleep(1.0) - + time.sleep(10.0) Domoticz.Log("TUYA plugin started") if Parameters["Mode6"] != "0": Domoticz.Debugging(int(Parameters["Mode6"])) @@ -282,6 +281,7 @@ def handleThread(self): except Exception as err: Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno)) + global _plugin _plugin = BasePlugin() From 618b03069c8114b1ac37313b6cd7f1f13a6bfa62 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 15 Oct 2021 22:28:53 +0200 Subject: [PATCH 63/77] modified: README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f25e9e2..08f17d4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ To update: ## Configuration -Enter your username and password for your app account along with your country code (1=US/Canada, 55=Brazil, etc). The initial setup of your devices should be done with the app and this plugin will detect/use the same settings and automatically find/add the devices into Domoticz. +Enter your username and password for your app account along with your country code (1=US/Canada, 55=Brazil, etc), keep the setti'Data Timeout' disabled. The initial setup of your devices should be done with the app and this plugin will detect/use the same settings and automatically find/add the devices into Domoticz. ## Usage @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.13 | Disabled turn off devices at startup | | 1.0.12 | Fix for cover or blinds status | | 1.0.11 | Added stop for cover or blinds | | 1.0.10 | Added turn off for off-line devices | From 2d1f3ee4ebfad5503e381c539d0bda5a5a416787 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 15 Oct 2021 22:32:41 +0200 Subject: [PATCH 64/77] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08f17d4..b3e7266 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ To update: ## Configuration -Enter your username and password for your app account along with your country code (1=US/Canada, 55=Brazil, etc), keep the setti'Data Timeout' disabled. The initial setup of your devices should be done with the app and this plugin will detect/use the same settings and automatically find/add the devices into Domoticz. +Enter your username and password for your app account along with your country code (1=US/Canada, 55=Brazil, etc), keep the setting 'Data Timeout' disabled. The initial setup of your devices should be done with the app and this plugin will detect/use the same settings and automatically find/add the devices into Domoticz. ## Usage From 20bf6f0796b2db6aa983bc51e7e8e20b6cb70bd6 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 15 Oct 2021 22:33:39 +0200 Subject: [PATCH 65/77] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3e7266..ff6b65e 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | -| 1.0.13 | Disabled turn off devices at startup | +| 1.0.13 | Disabled turn devices offline at startup | | 1.0.12 | Fix for cover or blinds status | | 1.0.11 | Added stop for cover or blinds | | 1.0.10 | Added turn off for off-line devices | From c29275d89b40a5f9ea8ea1227240bdff10bfe274 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 12 Nov 2022 11:20:22 +0100 Subject: [PATCH 66/77] Update plugin.py changed blinds control. --- plugin.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugin.py b/plugin.py index 132b004..baf3e29 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
                      Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

                      -

                      TUYA Plugin v.1.0.13


                      +

                      TUYA Plugin v.1.0.14


                      This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

                      Features

                        @@ -135,21 +135,23 @@ def onCommand(self, Unit, Command, Level, Hue): if Command == 'On': if dev_type == 'scene': dev.activate() - elif dev_type == 'cover': - dev.close_cover() else: dev.turn_on() UpdateDevice(Unit, 1, 'On', not dev.available()) elif Command == 'Off': if dev_type == 'scene': dev.activate() - elif dev_type == 'cover': - dev.open_cover() else: dev.turn_off(); UpdateDevice(Unit, 0, 'Off', not dev.available()) - elif dev_type == 'cover' and Command == 'Stop': - dev.stop_cover() + elif dev_type == 'cover': + if Command == 'Open': + dev.open_cover() + elif Command == 'Stop': + dev.stop_cover() + elif Command == 'Close': + dev.close_cover() + UpdateDevice(Unit, 1, 'On', not dev.available()) elif Command == 'Set Color': # Convert RGB to Hue+Saturation rgb = json.loads(Hue) From 77845a1d747cae4a2e2f4cf10e6277d21baa840d Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 12 Nov 2022 11:23:29 +0100 Subject: [PATCH 67/77] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ff6b65e..efded08 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.14 | Change blinds/cover control for Domoticz 2022.2 | | 1.0.13 | Disabled turn devices offline at startup | | 1.0.12 | Fix for cover or blinds status | | 1.0.11 | Added stop for cover or blinds | From 274a158929e4ccda06dcc76ea5c16ee5500b62d2 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sat, 12 Nov 2022 14:55:08 +0100 Subject: [PATCH 68/77] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index ff6b65e..b5e4bb6 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,6 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | 1.0.1 | Support for SmartLife and Jinvoo Apps | | 1.0.0 | Initial upload version | -## My device is not listed in Tuya API response or contains incomplete state, what should I do? - -Write an email to tuyasmart@tuya.com and mention the tuyapy library and https://px1.tuya{}.com API endpoint. Usually they ignore incoming emails, but perhaps, if they get a lot of emails, they will start fixing the API. - ## Note I can only support devices or with similar functions that I have myself. Thank you for your understanding. From 57622d6ac555ce9f028ed1853dc2f3b920f61bb9 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 9 Mar 2023 21:40:31 +0100 Subject: [PATCH 69/77] Update for cover --- plugin.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index baf3e29..3ef276e 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
                        Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

                        -

                        TUYA Plugin v.1.0.14


                        +

                        TUYA Plugin v.1.0.15


                        This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

                        Features

                          @@ -147,12 +147,14 @@ def onCommand(self, Unit, Command, Level, Hue): elif dev_type == 'cover': if Command == 'Open': dev.open_cover() + UpdateDevice(Unit, 1, 'Open', not dev.available()) elif Command == 'Stop': dev.stop_cover() + UpdateDevice(Unit, 0, 'Stop', not dev.available()) elif Command == 'Close': dev.close_cover() - UpdateDevice(Unit, 1, 'On', not dev.available()) - elif Command == 'Set Color': + UpdateDevice(Unit, 0, 'Close', not dev.available()) +elif Command == 'Set Color': # Convert RGB to Hue+Saturation rgb = json.loads(Hue) h, s = rgb_to_hs(rgb.get("r"), rgb.get("g"), rgb.get("b")) From 61e0eef0812ac6ad1483b2cdfc6a3f636a1fcd4b Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 9 Mar 2023 21:41:33 +0100 Subject: [PATCH 70/77] Update for covers --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b1fb531..71377c5 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.15 | Update for blinds/cover | | 1.0.14 | Change blinds/cover control for Domoticz 2022.2 | | 1.0.13 | Disabled turn devices offline at startup | | 1.0.12 | Fix for cover or blinds status | From 773283df64ba83de61987d3730985907a51b2ba9 Mon Sep 17 00:00:00 2001 From: Xenomes Date: Fri, 10 Mar 2023 14:03:35 +0100 Subject: [PATCH 71/77] fix typo --- plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin.py b/plugin.py index 3ef276e..1eea043 100755 --- a/plugin.py +++ b/plugin.py @@ -142,7 +142,7 @@ def onCommand(self, Unit, Command, Level, Hue): if dev_type == 'scene': dev.activate() else: - dev.turn_off(); + dev.turn_off() UpdateDevice(Unit, 0, 'Off', not dev.available()) elif dev_type == 'cover': if Command == 'Open': @@ -154,7 +154,7 @@ def onCommand(self, Unit, Command, Level, Hue): elif Command == 'Close': dev.close_cover() UpdateDevice(Unit, 0, 'Close', not dev.available()) -elif Command == 'Set Color': + elif Command == 'Set Color': # Convert RGB to Hue+Saturation rgb = json.loads(Hue) h, s = rgb_to_hs(rgb.get("r"), rgb.get("g"), rgb.get("b")) @@ -285,7 +285,7 @@ def handleThread(self): except Exception as err: Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno)) - + global _plugin _plugin = BasePlugin() From aac54da381c1417e8eb5fe93f3320e4aa43f11ac Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 16 Apr 2023 19:07:25 +0200 Subject: [PATCH 72/77] test fix --- plugin.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugin.py b/plugin.py index 1eea043..dc64da5 100755 --- a/plugin.py +++ b/plugin.py @@ -144,16 +144,16 @@ def onCommand(self, Unit, Command, Level, Hue): else: dev.turn_off() UpdateDevice(Unit, 0, 'Off', not dev.available()) - elif dev_type == 'cover': - if Command == 'Open': - dev.open_cover() - UpdateDevice(Unit, 1, 'Open', not dev.available()) - elif Command == 'Stop': - dev.stop_cover() - UpdateDevice(Unit, 0, 'Stop', not dev.available()) - elif Command == 'Close': - dev.close_cover() - UpdateDevice(Unit, 0, 'Close', not dev.available()) + # elif dev_type == 'cover': + if Command == 'Open': + dev.open_cover() + UpdateDevice(Unit, 1, 'Open', not dev.available()) + elif Command == 'Stop': + dev.stop_cover() + UpdateDevice(Unit, 0, 'Stop', not dev.available()) + elif Command == 'Close': + dev.close_cover() + UpdateDevice(Unit, 0, 'Close', not dev.available()) elif Command == 'Set Color': # Convert RGB to Hue+Saturation rgb = json.loads(Hue) From 5b93b54f0d38f5b97380a825b4b8064e82c9676f Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 16 Apr 2023 19:18:18 +0200 Subject: [PATCH 73/77] test fix --- plugin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin.py b/plugin.py index dc64da5..d3a00bd 100755 --- a/plugin.py +++ b/plugin.py @@ -138,22 +138,27 @@ def onCommand(self, Unit, Command, Level, Hue): else: dev.turn_on() UpdateDevice(Unit, 1, 'On', not dev.available()) + Domoticz.Log('On Called') elif Command == 'Off': if dev_type == 'scene': dev.activate() else: dev.turn_off() UpdateDevice(Unit, 0, 'Off', not dev.available()) + Domoticz.Log('Off Called') # elif dev_type == 'cover': if Command == 'Open': dev.open_cover() UpdateDevice(Unit, 1, 'Open', not dev.available()) + Domoticz.Log('Open Called') elif Command == 'Stop': dev.stop_cover() UpdateDevice(Unit, 0, 'Stop', not dev.available()) + Domoticz.Log('Stop Called') elif Command == 'Close': dev.close_cover() UpdateDevice(Unit, 0, 'Close', not dev.available()) + Domoticz.Log('CLose Called') elif Command == 'Set Color': # Convert RGB to Hue+Saturation rgb = json.loads(Hue) @@ -177,11 +182,13 @@ def onCommand(self, Unit, Command, Level, Hue): Domoticz.Debug("Set bright called") # Update status of Domoticz device Devices[Unit].Update(nValue=1, sValue=str(Level), TimedOut=Devices[Unit].TimedOut, Color=Hue) + Domoticz.Log('Set Color Called') elif Command == 'Set Level': # Set new level dev.set_brightness(round(Level*2.55)) # Update status of Domoticz device UpdateDevice(Unit, 1 if Devices[Unit].Type == 241 else 2, str(Level), Devices[Unit].TimedOut) + Domoticz.Log('Set Level Called') # Set last update self.last_update = time.time() From fce532209337aa74d794bd4c6df3e8dd267ecb4d Mon Sep 17 00:00:00 2001 From: Xenomes Date: Tue, 18 Apr 2023 22:09:04 +0200 Subject: [PATCH 74/77] Update for blinds/cover --- README.md | 1 + plugin.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71377c5..f7f2471 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Devices detected are created in the 'Devices' tab, to use them you need to click | Version | Information| | ----- | ---------- | +| 1.0.16 | Update for blinds/cover | | 1.0.15 | Update for blinds/cover | | 1.0.14 | Change blinds/cover control for Domoticz 2022.2 | | 1.0.13 | Disabled turn devices offline at startup | diff --git a/plugin.py b/plugin.py index d3a00bd..68e240a 100755 --- a/plugin.py +++ b/plugin.py @@ -5,12 +5,12 @@ # Contributed: Xenomes (xenomes@outlook.com) # """ - + Support forum: https://www.domoticz.com/forum/viewtopic.php?f=65&t=33145
                          Support forum Dutch: https://contactkring.nl/phpbb/viewtopic.php?f=60&t=846

                          -

                          TUYA Plugin v.1.0.15


                          +

                          TUYA Plugin v.1.0.16


                          This plugin is meant to control TUYA devices (mainly on/off switches and LED lights). TUYA devices may come with different brands and different Apps such as Smart Life or Jinvoo Smart, so select the corresponding App you're using below.

                          Features

                            From 71965850b6d321b320667a00d7bb2e95d1d4a89d Mon Sep 17 00:00:00 2001 From: Xenomes Date: Thu, 8 Jun 2023 22:20:44 +0200 Subject: [PATCH 75/77] Update README.md Install and Update updated --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index f7f2471..343f138 100644 --- a/README.md +++ b/README.md @@ -17,14 +17,13 @@ Python version 3.4 or higher required & Domoticz version 3.9446 or greater. To install: * Go in your Domoticz directory using a command line and open the plugins directory. -* The plugin required Python library tuyaha and requests ```sudo pip3 install tuyaha requests``` +* The plugin required Python library tuyaha and requests ```sudo pip3 install tuyaha requests==2.23.0``` * Run: ```git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git``` * Restart Domoticz. ## Updating To update: -* Upgrade the tuyaha and requests library ```sudo pip3 install tuyaha requests --upgrade``` * Go in your Domoticz directory using a command line and open the plugins directory then the Domoticz-TUYA directory. * Run: ```git pull``` * Restart Domoticz. From 33b1866a83255b1b30508e325a02f209657987fa Mon Sep 17 00:00:00 2001 From: John de Rooij Date: Sat, 17 Jun 2023 14:44:47 +0200 Subject: [PATCH 76/77] Do not send unneeded updates for devices that are not available --- plugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin.py b/plugin.py index 68e240a..6c1db49 100755 --- a/plugin.py +++ b/plugin.py @@ -279,17 +279,17 @@ def handleThread(self): if dev.state() == False: UpdateDevice(unit, 0, 'Off', not dev.available()) elif dev.state() == True: - UpdateDevice(unit, 1, 'On', not dev.available()) + if dev.available(): + UpdateDevice(unit, 1, 'On', not dev.available()) + else: + UpdateDevice(unit, 0, 'Off', not dev.available()) + Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') else: Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' State update skiped. status = '+str(dev.state())) #if dev.device_type() == 'cover' and dev.state() != 'Stop': # UpdateDevice(unit, 1, 'Stop', not dev.available()) - if dev.state() == True and not dev.available(): - UpdateDevice(unit, 0, 'Off', not dev.available()) - Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.') - except Exception as err: Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno)) From 8c270ad01706d8847ed4757fa1bf3c677f2ecb1c Mon Sep 17 00:00:00 2001 From: Xenomes Date: Sun, 7 Jul 2024 19:45:32 +0200 Subject: [PATCH 77/77] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 343f138..016d197 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ +# This plugin is no longer supported. For better device support, see https://github.com/Xenomes/Domoticz-TinyTUYA-Plugin + + # Domoticz-TUYA-Plugin + TUYA Plugin for Domoticz home automation Controls TUYA devices your network (mainly on/off switches and Lights). Tuya devices come in many brands and may come with different apps such as Smart Life or Jinvoo Smart, so select the matching App when configuring the plugin.