Hi @rospogrigio (or anyone else), I have been trying to get your fork of localtuya to work with my cover device, which is an automatic roller shade (see https://www.aliexpress.com/item/4001045079168.html?). I am a novice coder myself, so i’ve taken just about every step I know how to try and get the cover to work, but to no avail. I also don’t see anyone else on here that’s posted about setting up a cover. Any help would be greatly appreciated.
I have successfully extracted the Key & ID. I am also able to communicate with the device using tuya-cli. I can both get the data and set the data with no issues. This makes me confident that there are no issues with my device, and it should be possible to communicate with it using your localtuya fork. For reference, I can run the following command using tuya-cli to get the following dps data:
tuya-cli get --id xxxxxxxxxxxxxxxxxxxx --key xxxxxxxxxxxxxxxx --protocol-version 3.3 --all
dps: {
'1': 'close',
'2': 40,
'3': 100,
'5': false,
'7': 'closing',
'8': 'cancel',
'9': 0,
'10': 0,
'11': 38610
Setting ‘2’ allows me to control the position, from 0 to 100.
However, I am unable to get the cover connected with localtuya. First, I did make one change to “cover.py” to align with the device’s dps.
dps[config.get(CONF_ID)]=None
dps["1"]=None
dps["2"]=None
dps["3"]=None
dps["5"]=None
dps["7"]=None
dps["8"]=None
dps["9"]=None
dps["10"]=None
dps["11"]=None
Next, here is my config file:
#Enable local tuya integration https://github.com/rospogrigio/localtuya-homeassistant
cover:
- platform: localtuya
host: 192.168.1.29
local_key: xxxxxxxxxxxxxxxx
device_id: xxxxxxxxxxxxxxxxxxxx
name: left_blind_local
friendly_name: Left Blind Local
protocol_version: 3.3
id: 1
I also added extensive logging throughout cover.py and __init__.py
, which I hope can be helpful in trying to diagnose this problem. Here are my logs:
2020-09-01 23:20:46 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for localtuya which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-09-01 23:20:47 INFO (MainThread) [homeassistant.components.cover] Setting up cover.localtuya
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] custom_components.localtuya.pytuya version 7.0.8
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] Python 3.8.3 (default, Jul 10 2020, 18:54:27)
[GCC 9.3.0] on linux
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] Using PyCrypto (3, 9, '8')
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] Using PyCrypto from '/usr/local/lib/python3.8/site-packages/Crypto/__init__.py'
2020-09-01 23:20:47 INFO (SyncWorker_8) [custom_components.localtuya.cover] ('xxxxxxxxxxxxxxxxxxxx', '192.168.1.29')
2020-09-01 23:20:47 INFO (SyncWorker_8) [custom_components.localtuya.cover] trying def status(self)
2020-09-01 23:20:47 INFO (SyncWorker_8) [custom_components.localtuya.cover] self._cached_status after sleep =
2020-09-01 23:20:47 INFO (SyncWorker_8) [custom_components.localtuya.cover] self.__get_status after sleep = <bound method TuyaCoverCache.__get_status of <custom_components.localtuya.cover.TuyaCoverCache object at 0xaf25edc0>>
2020-09-01 23:20:47 INFO (SyncWorker_8) [custom_components.localtuya.cover] about to attempt status=self._device.status()
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] logger debug running from def status(self)
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] status() entry (dev_type is device22)
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] json_payload=b'{"devId":"xxxxxxxxxxxxxxxxxxxx","uid":"xxxxxxxxxxxxxxxxxxxx","t":"1599027647","dps":{"1":null,"2":null,"3":null,"5":null,"7":null,"8":null,"9":null,"10":null,"11":null}}'
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] payload is b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\xc73.3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H7L6\xf0\xd4\xcc\x11f\x8e\xbaI\xd1\xf1\x19%\x89m\xe8cB\xd6\x9cI\t8#\x8b\x1f\x1a\x07\x91c*d\xf3oI\xdc\x836\x15\x08J\x8a\x87RX4\x92\xd8q\x10\xc2\x00\xa8\xc8\xb0\xb1\xf6\x81Td\xce\'G(\x82|z"\xfd*\xc3\x17\x18\x16\xf5w\x0f\x0b]\x9dDU+]SB\xcb\x1b\x17\xe0\r=\xcc\xce\x8f;\x8b\n\x85\xc1\xab"\x92\xc7\xe9\x86~j-\xf4\xe8\xd1T\x17\x83\xd7\x9b\x80iwP\x9f\xcbMD\xd1\xbe\xfc//7\x84G\xb6W_\x07\xc2\xbf\ns\x1eG\xa7x\xfb\xbc+N\xb7\xd8\xd3TLu\x981\xcc\xab\xc6o\xceg\xd4\xba@"C\x96N\xbd\xc8\x00\xb8\x85\xac/\x00\x00\xaaU'
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] debugging from _send_receive try
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] s variable set to = <socket.socket fd=40, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('192.168.1.56', 34174)>
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.connection_timeout is 10)
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.address is 192.168.1.29)
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.port is 6668)
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to connect using address and port
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to send payload from try b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\xc73.3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H7L6\xf0\xd4\xcc\x11f\x8e\xbaI\xd1\xf1\x19%\x89m\xe8cB\xd6\x9cI\t8#\x8b\x1f\x1a\x07\x91c*d\xf3oI\xdc\x836\x15\x08J\x8a\x87RX4\x92\xd8q\x10\xc2\x00\xa8\xc8\xb0\xb1\xf6\x81Td\xce\'G(\x82|z"\xfd*\xc3\x17\x18\x16\xf5w\x0f\x0b]\x9dDU+]SB\xcb\x1b\x17\xe0\r=\xcc\xce\x8f;\x8b\n\x85\xc1\xab"\x92\xc7\xe9\x86~j-\xf4\xe8\xd1T\x17\x83\xd7\x9b\x80iwP\x9f\xcbMD\xd1\xbe\xfc//7\x84G\xb6W_\x07\xc2\xbf\ns\x1eG\xa7x\xfb\xbc+N\xb7\xd8\xd3TLu\x981\xcc\xab\xc6o\xceg\xd4\xba@"C\x96N\xbd\xc8\x00\xb8\x85\xac/\x00\x00\xaaU'
2020-09-01 23:20:47 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to try for data=s.recv(1024)
2020-09-01 23:20:57 WARNING (MainThread) [homeassistant.components.cover] Setup of cover platform localtuya is taking over 10 seconds.
2020-09-01 23:20:57 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] failed to receive data, raising e exception
2020-09-01 23:20:58 WARNING (MainThread) [homeassistant.components.switch] Setup of switch platform tplink is taking over 10 seconds.
2020-09-01 23:20:58 INFO (SyncWorker_8) [custom_components.localtuya.cover] about to attempt status=self._device.status()
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] logger debug running from def status(self)
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] status() entry (dev_type is device22)
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] json_payload=b'{"devId":"xxxxxxxxxxxxxxxxxxxx","uid":"xxxxxxxxxxxxxxxxxxxx","t":"1599027658","dps":{"1":null,"2":null,"3":null,"5":null,"7":null,"8":null,"9":null,"10":null,"11":null}}'
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] payload is b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\xc73.3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H7L6\xf0\xd4\xcc\x11f\x8e\xbaI\xd1\xf1\x19%\x89m\xe8cB\xd6\x9cI\t8#\x8b\x1f\x1a\x07\x91c*d\xf3oI\xdc\x836\x15\x08J\x8a\x87RX4\x92\xd8q\x10\xc2\x00\xa8\xc8\xb0\xb1\xf6\x81Td\xce\xf7\x02Ww\x8clo\x99,\xc4\xb6d\xf5\xb5\xd1\xe1\x0b]\x9dDU+]SB\xcb\x1b\x17\xe0\r=\xcc\xce\x8f;\x8b\n\x85\xc1\xab"\x92\xc7\xe9\x86~j-\xf4\xe8\xd1T\x17\x83\xd7\x9b\x80iwP\x9f\xcbMD\xd1\xbe\xfc//7\x84G\xb6W_\x07\xc2\xbf\ns\x1eG\xa7x\xfb\xbc+N\xb7\xd8\xd3TLu\x981\xcc\xab\xc6o\xceg\xd4\xba@"C\x96N\xbd\xc8\x00\xfd\xaf-\x99\x00\x00\xaaU'
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] debugging from _send_receive try
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] s variable set to = <socket.socket fd=40, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('192.168.1.56', 34396)>
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.connection_timeout is 10)
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.address is 192.168.1.29)
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.port is 6668)
2020-09-01 23:20:58 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to connect using address and port
2020-09-01 23:20:59 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.upnp
2020-09-01 23:20:59 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to send payload from try b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\xc73.3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H7L6\xf0\xd4\xcc\x11f\x8e\xbaI\xd1\xf1\x19%\x89m\xe8cB\xd6\x9cI\t8#\x8b\x1f\x1a\x07\x91c*d\xf3oI\xdc\x836\x15\x08J\x8a\x87RX4\x92\xd8q\x10\xc2\x00\xa8\xc8\xb0\xb1\xf6\x81Td\xce\xf7\x02Ww\x8clo\x99,\xc4\xb6d\xf5\xb5\xd1\xe1\x0b]\x9dDU+]SB\xcb\x1b\x17\xe0\r=\xcc\xce\x8f;\x8b\n\x85\xc1\xab"\x92\xc7\xe9\x86~j-\xf4\xe8\xd1T\x17\x83\xd7\x9b\x80iwP\x9f\xcbMD\xd1\xbe\xfc//7\x84G\xb6W_\x07\xc2\xbf\ns\x1eG\xa7x\xfb\xbc+N\xb7\xd8\xd3TLu\x981\xcc\xab\xc6o\xceg\xd4\xba@"C\x96N\xbd\xc8\x00\xfd\xaf-\x99\x00\x00\xaaU'
2020-09-01 23:20:59 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to try for data=s.recv(1024)
2020-09-01 23:21:09 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] failed to receive data, raising e exception
2020-09-01 23:21:10 INFO (SyncWorker_8) [custom_components.localtuya.cover] about to attempt status=self._device.status()
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] logger debug running from def status(self)
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] status() entry (dev_type is device22)
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] json_payload=b'{"devId":"xxxxxxxxxxxxxxxxxxxx","uid":"xxxxxxxxxxxxxxxxxxxx","t":"1599027670","dps":{"1":null,"2":null,"3":null,"5":null,"7":null,"8":null,"9":null,"10":null,"11":null}}'
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] payload is b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\xc73.3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H7L6\xf0\xd4\xcc\x11f\x8e\xbaI\xd1\xf1\x19%\x89m\xe8cB\xd6\x9cI\t8#\x8b\x1f\x1a\x07\x91c*d\xf3oI\xdc\x836\x15\x08J\x8a\x87RX4\x92\xd8q\x10\xc2\x00\xa8\xc8\xb0\xb1\xf6\x81Td\xcel!k\x82\xa5\xd7 \x92\xc9\xdd\xf9\x12,\xc1\xb8\x02\x0b]\x9dDU+]SB\xcb\x1b\x17\xe0\r=\xcc\xce\x8f;\x8b\n\x85\xc1\xab"\x92\xc7\xe9\x86~j-\xf4\xe8\xd1T\x17\x83\xd7\x9b\x80iwP\x9f\xcbMD\xd1\xbe\xfc//7\x84G\xb6W_\x07\xc2\xbf\ns\x1eG\xa7x\xfb\xbc+N\xb7\xd8\xd3TLu\x981\xcc\xab\xc6o\xceg\xd4\xba@"C\x96N\xbd\xc8\x00;\xdb\xa8\xe4\x00\x00\xaaU'
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] debugging from _send_receive try
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] s variable set to = <socket.socket fd=40, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('192.168.1.56', 34490)>
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.connection_timeout is 10)
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.address is 192.168.1.29)
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] self.port is 6668)
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to connect using address and port
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to send payload from try b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\xc73.3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H7L6\xf0\xd4\xcc\x11f\x8e\xbaI\xd1\xf1\x19%\x89m\xe8cB\xd6\x9cI\t8#\x8b\x1f\x1a\x07\x91c*d\xf3oI\xdc\x836\x15\x08J\x8a\x87RX4\x92\xd8q\x10\xc2\x00\xa8\xc8\xb0\xb1\xf6\x81Td\xcel!k\x82\xa5\xd7 \x92\xc9\xdd\xf9\x12,\xc1\xb8\x02\x0b]\x9dDU+]SB\xcb\x1b\x17\xe0\r=\xcc\xce\x8f;\x8b\n\x85\xc1\xab"\x92\xc7\xe9\x86~j-\xf4\xe8\xd1T\x17\x83\xd7\x9b\x80iwP\x9f\xcbMD\xd1\xbe\xfc//7\x84G\xb6W_\x07\xc2\xbf\ns\x1eG\xa7x\xfb\xbc+N\xb7\xd8\xd3TLu\x981\xcc\xab\xc6o\xceg\xd4\xba@"C\x96N\xbd\xc8\x00;\xdb\xa8\xe4\x00\x00\xaaU'
2020-09-01 23:21:10 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] about to try for data=s.recv(1024)
2020-09-01 23:21:20 DEBUG (SyncWorker_8) [custom_components.localtuya.pytuya] failed to receive data, raising e exception
2020-09-01 23:21:21 ERROR (SyncWorker_8) [custom_components.localtuya.cover] Failed to update status of device 192.168.1.29
2020-09-01 23:21:22 ERROR (MainThread) [homeassistant.components.cover] Error while setting up localtuya platform for cover
Traceback (most recent call last):
File "/config/custom_components/localtuya/cover.py", line 117, in __get_status
status = self._device.status()
File "/config/custom_components/localtuya/pytuya/__init__.py", line 338, in status
data = self._send_receive(payload)
File "/config/custom_components/localtuya/pytuya/__init__.py", line 226, in _send_receive
raise e
File "/config/custom_components/localtuya/pytuya/__init__.py", line 211, in _send_receive
data = s.recv(1024)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 184, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/localtuya/cover.py", line 89, in setup_platform
TuyaDevice(
File "/config/custom_components/localtuya/cover.py", line 169, in __init__
self._status = self._device.status()
File "/config/custom_components/localtuya/cover.py", line 152, in status
self._cached_status = self.__get_status()
File "/config/custom_components/localtuya/cover.py", line 126, in __get_status
raise ConnectionError("Failed to update status .")
ConnectionError: Failed to update status .
A few more pieces of information:
I’m running Home Assistant w/Supervisor on a Raspberry Pi 4
My Raspberry Pi’s IP is 192.168.1.56
My cover device’s IP is 192.168.1.29
The requisite port (6668) is open
Again, any help would be so greatly appreciated.