Tuya LOCAL with energy monitoring and without tuya-convert

Thank you so much you fix my problem witch. Not seeing the second switch.
I used the update of the integration (v.1.0.1)
It works perfect. THANK YOU… THANK YOU…
This works good for 2 Gang switches…
You are the best!!! :+1: :+1: :+1:

  • platform: localtuya
    host: 10.0.0.229
    local_key: xxxxxxxxxxxxxxxxx
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxx
    name: tuya_dining
    friendly_name: tuya_dining
    protocol_version: 3.3
    switches:
    sw01:
    name: tuya_dining_light
    friendly_name: Dining Room Light
    id: 1
    sw02:
    name: tuya_dining_fan
    friendly_name: Dining Room Fan
    id: 2
    #####################################################################
  • platform: localtuya
    host: 10.0.0.35
    local_key: xxxxxxxxxxxxxxxxx
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxx
    name: tuya_living
    friendly_name: tuya_living
    protocol_version: 3.3
    switches:
    sw01:
    name: tuya_living_light
    friendly_name: Living Room Light
    id: 1
    sw02:
    name: tuya_living_fan
    friendly_name: Living Room Fan
    id: 2
2 Likes

@ranski1999 well… I’d call this an unintentional fix :smiley: , it was not meant to fix your problem but I’m really glad it did. It appears that some devices (like yours) wanted to set the dps as null in the request for each id of each gang of the switch, while v.1.0.0 was only setting to null the dps “1”. The same happens for the devices who need this for the voltage/current data, this release should now work for everybody without patching the code.
Bye!

1 Like

took some time to read this whole chain…now question from newbie…whats the easiest way for me to start doing this as couple different methods were used?

Any change to get these methods someday integrated to HA without having to do everything manually?

1 Like

I don’t know which is the easiest way since I still haven’t tried the Node-red method, but my impression is that the localtuya integration should be easier to setup, you just have to add the custom repository. The hard part (for both methods) is to get the devId and localKey of your devices, there are several ways to obtain them, you just have to find the method that suits you best.
I don’t think these methods will be integrated in HA unless some skilled developer takes them in charge, and also because the support (for localtuya) is currently limited to a couple of devices (covers and switches/smart plugs) and it lacks the support for a lot of other devices (light bulbs, etc…).
Hope the above answers your question, bye!

1 Like

Only had to struggle for a whole day but I got it to work :blush:

1 Like

Hello, @rospogrigio

Thanks for Your work and module for Home Assistant.
I have bought 4 Smart Plugs which are connected to Tuya. Is was build on W600 (not esp8266) and there is no any methods to flash to esphome.
But with Your localtuya-homeassistant I have successfully intergrate Smart Plugs with Power Monitor and have blocked all traffic to chinese servers on MikroTik.

Device ID and Device Key was obtained via Bluestacks with Root and Smart Life v 3.3.0

2 Likes

Hello, I am brand new to home assistant and love the idea of controlling my tuya dimmer switches locally. Using localtuya, I can get them to show up as entities in home assistant, but I cannot get or change their status. I keep running into “This entity does not have a unique ID, therefore its settings cannot be managed from the UI.” I feel like I am missing something and would appreciate any help with this problem.

@OfWonder If you are adding your switches through confi.yaml you can’t manage your entities through the UI. There is no error here, just a message letting you know that is how it will be.

Sagar,

How do I change the state of the light switch? In the video linked below, he uses Lovelace to turn his switch on and off.

Error while setting up localtuya platform for switch
Traceback (most recent call last):
File “/home/homeassistant/.homeassistant/custom_components/localtuya/pytuya/init.py”, line 24, in
import Crypto
ModuleNotFoundError: No module named ‘Crypto’

I have a Gosund smart power strip (3 sockets + 3 usb), but I can’t get it to work.
After inserting the localtuya folder (from the @rospogrigio repository), finding the keys and entering this code in the switch.yaml file, home assistant does not see any of these entity.
The power strip work with this method?

  - platform: localtuya
    host: 192.168.0.88
    local_key: !secret mylocalkey
    device_id: !secret mydeviceid
    name: ciabatta_smart
    friendly_name: ciabatta_smart
    protocol_version: 3.1
    switches:
      sw01:
        name: presa_1
        friendly_name: Presa 1
        id: 1
        current: 18
        current_consumption: 19
        voltage: 20
      sw02:
        name: presa_2
        friendly_name: Presa 2
        id: 2  
      sw03:
        name: presa_3
        friendly_name: Presa 3
        id: 3  
      sw04:
        name: switch_usb1
        friendly_name: USB Plug
        id: 7  

Update: This is the error in the log:

Error while setting up localtuya platform for switch

Traceback (most recent call last):
  File "/config/custom_components/localtuya/switch.py", line 160, in __get_status
    status = self._device.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 324, in status
    data = self._send_receive(payload)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 194, in _send_receive
    raise e
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 191, in _send_receive
    s.connect((self.address, self.port))
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/switch.py", line 104, in setup_platform
    TuyaDevice(
  File "/config/custom_components/localtuya/switch.py", line 210, in __init__
    self._status = self._device.status()
  File "/config/custom_components/localtuya/switch.py", line 191, in status
    self._cached_status = self.__get_status()
  File "/config/custom_components/localtuya/switch.py", line 168, in __get_status
    raise ConnectionError("Failed to update status .")
ConnectionError: Failed to update status .
1 Like

The problem is that “timed out” message: the device does not respond for a lot of time (30s as far as I remember). This is probably due to one of these situations:

  1. wrong deviceId/localKey : double check these values
  2. (less likely) faulty connection: try to move the device closer to the access point and see if it works
  3. the device uses a different communication protocol: I see you are using 3.1, try to set 3.3 (which is the default and I believe, mostly used). If neither works, maybe the Tuya guys have defined a new protocol so some changes in the code might be needed.

I have ordered a smart power strip too, I will receive it at the end of September hopefully: if I bump in the same problems I will try to fix them and give feedback.
Bye,
rospogrigio

1 Like

Ok, It’s work thanks @rospogrigio. I change the wrong parameter (IP and protocol) and now working.
ciabatta

consumption data are updated with a delay of about fifteen seconds, but that’s just fine, volts and watts are correct.
For those who use the rospogrigio repo, the instructions in the video linked by OfWonder are correct and easy to apply.

  1. install android emulator for pc
  2. install Es File Explorer
  3. install Smart Life version 3.6.1
  4. Extract the keys and put them in configuration.yaml or dedicated files
  5. GO
3 Likes

@byxil I see most peoiple using this for sockets. Has anyone gotten it to work with light switches? My switches are linked below, and I just cannot get them to work. If anyone could give me some pointers on this I would really appreciate it.

Switch Link: https://www.amazon.com/gp/product/B07K67D43J/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

from the link you put, it seems to me a normal dimmable switch, does it also have consumption?
if it does not have consumption, you can try to insert it in the home assistant with the official tuya integration, from Settings, Integrations, new integration, tuya

I was wondering the same thing… I tried adding a light since there is a light.py in the integration, but didn’t get very far. @rospogrigio do you know if the light integration should be working?

@byxil I can get them to function with the official Tuya integration, but I would really like local control without the need to remove them from the walls to flash them all with Tasmota.

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.

If your devices require to work with the “light” integration instead of “switch”, I am afraid that you or somebody else needs to adapt my work for that. I forked from milesperhour and never touched the light.py code since I don’t have any of those devices so I could not test if the code works; and also in pytuya there are some references that need to be adapted. I also noticed that light.py still refers to the old version of pytuya (7.0.4, now should be 7.0.8).
Sorry for not being more helpful but as you can imagine it’s hard to code without the hardware to test.

1 Like

Mmm, this is strange. I have some covers (different from yours), and took a long time to make them work but finally did the job. I also couldn’t make them work with tuya-cli, I get a ‘json obj data unvalid’ error, so I had to try something else to make them work.
Yours should definitely work with my localtuya, we just need to figure out what’s going wrong. Your enhanced debug is very clear and it looks that your request is well formed, however the device does not respond and you get a timeout: we need to investigate why this is happening, since the configuration seems correct and you get it working with tuya-cli setting protocol=3.3.
I believe you are very close to make it working, if you want I can send you a little command line script that I use to debug and write code that may help you debug faster, since you don’t need to reboot HomeAssistant every time. It might be helpful also for @OfWonder but he would need to edit a lot for lights to work.
Let me know, bye
rospogrigio

1 Like