Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Door, PIR and Temp sensors status #1

Open
wants to merge 85 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
d9f7cf2
On branch master
Xenomes Sep 18, 2020
7d313d0
Changes to be committed:
Xenomes Sep 18, 2020
89dc1d4
Changes to be committed:
Xenomes Sep 18, 2020
308f45b
Changes to be committed:
Xenomes Sep 18, 2020
c320491
Change some text.
Xenomes Sep 18, 2020
cfc1e7d
Update README.md
Xenomes Oct 7, 2020
863270f
Update README.md
Xenomes Oct 7, 2020
2c61124
modified: plugin.py
Xenomes Oct 7, 2020
4e98aec
modified: plugin.py
Xenomes Oct 7, 2020
bde3e3f
modified: README.md and plugin.py
Xenomes Oct 7, 2020
926602b
Merge branch 'development' of https://github.com/Xenomes/Domoticz-TUY…
Xenomes Oct 7, 2020
b2f883f
Update README.md
Xenomes Oct 28, 2020
d1c0767
Update README.md
Xenomes Oct 28, 2020
a552243
Update README.md
Xenomes Dec 8, 2020
22d2555
Update README.md
Xenomes Dec 8, 2020
e2b44eb
Update plugin.py
Xenomes Jan 13, 2021
c70a56d
Update README.md
Xenomes Jan 13, 2021
ba7d6dc
Update plugin.py
Xenomes Jan 13, 2021
342addc
Fixed update time api to Domoticz from 10 min to 1 min
Xenomes Mar 21, 2021
1950c54
Update plugin.py
Xenomes Mar 31, 2021
1779cef
Update README.md
Xenomes Mar 31, 2021
1e839c1
Update plugin.py
Xenomes Mar 31, 2021
0949c80
Update plugin.py
Xenomes Mar 31, 2021
a98dcf7
Merge branch 'master' into development
Xenomes Apr 1, 2021
a1b27c5
Merge pull request #8 from Xenomes/development
Xenomes Apr 1, 2021
fb02723
Update README.md
Xenomes Apr 1, 2021
bd662ec
Update plugin.py
Xenomes Apr 2, 2021
5052da7
Update plugin.py
Xenomes Apr 3, 2021
f754a03
Update plugin.py
Xenomes Apr 3, 2021
9b30481
Update plugin.py
Xenomes Apr 3, 2021
45a137d
Update plugin.py
Xenomes Apr 3, 2021
336a2da
Update plugin.py
Xenomes Apr 3, 2021
6e1e312
Update plugin.py
Xenomes Apr 3, 2021
1174bc6
Update README.md
Xenomes Apr 3, 2021
ac38bad
Added fix for error Tuyaapi time-out
Xenomes Apr 16, 2021
0d7c446
Merge branch 'master' of https://github.com/Xenomes/Domoticz-TUYA-Plugin
Xenomes Apr 16, 2021
488ab05
Little fix
Xenomes Apr 17, 2021
58bac14
Bug fixing!
Xenomes Apr 21, 2021
916cfb9
Added fix for 0 device detection
Xenomes Apr 22, 2021
c61ecbc
Changed the detected scene's switch type to push button.
Xenomes May 2, 2021
f3c74f1
Update README.md
Xenomes May 2, 2021
965b6d0
Changed the detected scene's switch type to push button.
Xenomes May 2, 2021
9c2df82
Update plugin.py
Xenomes Jun 24, 2021
6d92b15
Update plugin.py
Xenomes Jun 24, 2021
0fbfb18
Update plugin.py
Xenomes Jun 24, 2021
a38198b
Update plugin.py
Xenomes Jun 24, 2021
c075ed6
Update plugin.py
Xenomes Jul 7, 2021
2ce03d0
Update plugin.py
Xenomes Jul 7, 2021
669241c
Update README.md
Xenomes Jul 7, 2021
cfeaeab
Update plugin.py
Xenomes Jul 9, 2021
400781d
Update README.md
Xenomes Jul 9, 2021
1b8fa09
Update plugin.py
Xenomes Jul 10, 2021
4a5c61d
Update plugin.py
Xenomes Jul 10, 2021
1eaeedd
Update plugin.py
Xenomes Jul 10, 2021
2475c0d
Update plugin.py
Xenomes Jul 10, 2021
2dd5270
Update plugin.py
Xenomes Jul 11, 2021
7e51644
Update plugin.py
Xenomes Jul 11, 2021
6a87d2b
Update plugin.py
Xenomes Jul 11, 2021
a4481e8
Update README.md
Xenomes Jul 12, 2021
e5ab107
Update plugin.py
Xenomes Jul 12, 2021
4c9b5a3
Merge pull request #14 from Xenomes/patch-BarryT
Xenomes Jul 12, 2021
2805c5d
Update plugin.py
Xenomes Oct 12, 2021
9fdfdb7
Update plugin.py
Xenomes Oct 12, 2021
2f96392
Update plugin.py
Xenomes Oct 13, 2021
63aa2ea
modified: plugin.py
Xenomes Oct 13, 2021
01895fe
modified: plugin.py
Xenomes Oct 13, 2021
fa943c4
modified: plugin.py
Xenomes Oct 15, 2021
618b030
modified: README.md
Xenomes Oct 15, 2021
e19254d
Merge pull request #17 from Xenomes/manjh
Xenomes Oct 15, 2021
2d1f3ee
Update README.md
Xenomes Oct 15, 2021
20bf6f0
Update README.md
Xenomes Oct 15, 2021
c29275d
Update plugin.py
Xenomes Nov 12, 2022
77845a1
Update README.md
Xenomes Nov 12, 2022
274a158
Update README.md
Xenomes Nov 12, 2022
c58647d
Merge pull request #31 from Xenomes/update-for-domoticz-2022.2
Xenomes Nov 12, 2022
57622d6
Update for cover
Xenomes Mar 9, 2023
61e0eef
Update for covers
Xenomes Mar 9, 2023
773283d
fix typo
Xenomes Mar 10, 2023
aac54da
test fix
Xenomes Apr 16, 2023
5b93b54
test fix
Xenomes Apr 16, 2023
fce5322
Update for blinds/cover
Xenomes Apr 18, 2023
7196585
Update README.md
Xenomes Jun 8, 2023
33b1866
Do not send unneeded updates for devices that are not available
joro75 Jun 17, 2023
0f3a5fc
Merge pull request #48 from joro75/ReducedSensorChanges
Xenomes Jun 28, 2023
8c270ad
Update README.md
Xenomes Jul 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .drone.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .vscode/settings.json

This file was deleted.

25 changes: 0 additions & 25 deletions LICENSE

This file was deleted.

49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -8,7 +12,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) Colour for lights (⚠ RGBW(W) lights must be on a colour for correct detection ⚠)
* Supports scene activation

## Installation
Expand All @@ -17,7 +21,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 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
Expand All @@ -27,14 +32,9 @@ 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.
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

Expand All @@ -45,23 +45,28 @@ 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 |
| 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 |
| 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 |
| 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:

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.
## Note

This clone contains several critical fixes. Check commits.
I can only support devices or with similar functions that I have myself. Thank you for your understanding.

## How to check whether the API this library using can control your device?
# Original project:

- 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:[email protected]) to support your device in their
`/homeassistant` API
- Remove the updated script, so your credentials won't leak
Fork from https://github.com/guino/tuyaha to make a standalone project.
8 changes: 8 additions & 0 deletions fakeDomoticz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def Log(s):
print(s)

def Error(s):
print(s)

def Debug(s):
print(s)
118 changes: 93 additions & 25 deletions plugin.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
#
# Author: Wagner Oliveira ([email protected])
#
# Contributed: Xenomes ([email protected])
#
"""
<plugin key="tuya" name="TUYA" author="Wagner Oliveira" version="1.0.0" wikilink="http://www.domoticz.com/wiki/plugins/plugin.html" externallink="https://github.com/guino/Domoticz-TUYA">
<plugin key="tuya" name="TUYA" author="Wagner Oliveira contributed Xenomes" version="1.0.16" wikilink="" externallink="https://github.com/Xenomes/Domoticz-TUYA-Plugin.git">
<description>
<h2>TUYA Plugin</h2><br/>
Support forum: <a href="https://www.domoticz.com/forum/viewtopic.php?f=65&amp;t=33145">https://www.domoticz.com/forum/viewtopic.php?f=65&amp;t=33145</a><br/>
Support forum Dutch: <a href="https://contactkring.nl/phpbb/viewtopic.php?f=60&amp;t=846">https://contactkring.nl/phpbb/viewtopic.php?f=60&amp;t=846</a><br/>
<br/>
<h2>TUYA Plugin v.1.0.16</h2><br/>
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.
<h3>Features</h3>
<ul style="list-style-type:square">
<li>Auto-detection of devices on network</li>
<li>On/Off control, state and available status display</li>
<li>Dimmer/RGB Color setting for Lights</li>
<li>Dimmer/RGBWW Color setting for Lights</li>
<li>Scene activation support</li>
</ul>
<h3>Devices</h3>
Expand Down Expand Up @@ -48,7 +53,10 @@
</params>
</plugin>
"""
import Domoticz
try:
import Domoticz
except ImportError:
import fakeDomoticz as Domoticz
import threading
import socket
import html
Expand All @@ -65,16 +73,23 @@ class BasePlugin:
last_update = 0

def __init__(self):
self.tuya._discovery_interval = 600
self.tuya._query_interval = 30
self.tuya._force_discovery = True
return

def onStart(self):
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 - 10
Domoticz.Log("Waiting " + str(t) + " seconds to connect TuyaApi (Tuya Plug-in)")
time.sleep(10.0)
Domoticz.Log("TUYA plugin started")
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"
Expand Down Expand Up @@ -110,7 +125,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)
Expand All @@ -120,39 +135,60 @@ 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())
Domoticz.Log('On Called')
elif Command == 'Off':
if dev_type == 'scene':
dev.activate()
elif dev_type == 'cover':
dev.open_cover()
else:
dev.turn_off();
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)
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(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))
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()
Expand All @@ -164,10 +200,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 (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 < 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,))
Expand All @@ -181,9 +217,14 @@ 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.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()
Expand All @@ -199,14 +240,32 @@ 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") == '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") == '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()
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:
# 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()
# 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()
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":
Expand All @@ -219,8 +278,17 @@ def handleThread(self):
# Update device
if dev.state() == False:
UpdateDevice(unit, 0, 'Off', not dev.available())
elif dev.state() == True:
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:
UpdateDevice(unit, 1, 'On', not dev.available())
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())

except Exception as err:
Domoticz.Error("handleThread: "+str(err)+' line '+format(sys.exc_info()[-1].tb_lineno))
Expand Down
Loading