Tuya switch

Looks like this is fixed in 0.98.4. Thanks…

Like this switch:

  • platform: localtuya
    host: 192.168.1.15
    local_key: ####your local key####
    device_id: ######your device id######
    name: tuyalocal_Stairwell
    id: 01
  • platform: localtuya
    host: 192.168.1.15
    local_key: ####your local key####
    device_id: ######your device id######
    name: tuyalocal_LoungeZone2
    id: 02
  • platform: localtuya
    host: 192.168.1.15
    local_key: ####your local key####
    device_id: ######your device id######
    name: tuyalocal_LoungeZone1
    id: 03

Hi guys,
both variants does not work I’m afraid.

Stanislav, your variant does not initialise. This is in logs:

homeassistant.components.switch] Setup of platform localtuya is taking over 10 seconds.                               
2019-09-06 14:59:33 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform localtuya        

Christian, in your variant I see both switches, but they simply do not work :frowning:

Any more ideas, guys?

Sorry. This is not my code. I only posted a link.

It works in this way:

- platform: localtuya1gang
    host: 192.168.1.15
    local_key: ####your local key####
    device_id:######your device id######
    name: switch_one
    protocol_version: 3.3
    id: 1
  - platform: localtuya1gang
    host: 192.168.1.15
     local_key: ####your local key####
    device_id:######your device id######
    name: switch_two
    protocol_version: 3.3
    id: 2

Thanks, anyway!

By the way, I added an outlet into the config. However, it did not work. I changed the protocol to 3.1 for this outlet, and it works now.

Thanks to previous efforts on this, I have added a light component using pytuya for local control, available here: https://github.com/Alfiegerner/localtuya

I only have white with temperature bulbs, so no RGBW, but it should be easy enough from the code where to add. Added test.py top allow debugging.

Also worth noting my bulbs operate up to 1000 for brightness for colour temp, so had to change pytuya.

1 Like

@Alfiegerner Thanks for the component light! It worked for me, but only with the standard pytuya library.

Its possible if I use as a cover to see the status ? If the curtain is open or close?

thanks

Great!

For anyone else trying it, I think the important bit is to look at the output of the print command in state for each DPS key using test.py (checking with different brightness etc set from tuya app), then amend the DPS values and brightness etc accordingly. E.g For me brightness key was 23, and max brightness 1000, in standard pytuya brightness key is 3 and max brightness 255.

I added a slightly fixed light.ry to my repository https://github.com/stast1/localtuya
This works, but sometimes there are errors updating the brightness and color temperature. If someone can fix this, I will be grateful. Thank.

Has anyone tried to merge the component into home assistant yet? Or is this still too unstable for that?
I don’t have any tuya devices myself yet, i love the cheap price but i hate the latency cloud control adds.

Can’t get it to work

   - platform: localtuya
     host: 10.0.0.41
     local_key: 7392005e57014485
     device_id: bff339668eb83f6350kkah
     name: tuya_01
     protocol_version: 3.3

Just errors in the log

Try
protocol_version: 3.1

No help


Update for light.tuya_01 fails
3:14 PM custom_components/localtuya/light.py (ERROR) - message first occured at 2:30 PM and shows up 86 times
Unexpected status() payload=b'\xce\xc5\xd8\xf3\x18\xec{\xaa\x07\xd2\xcc8U\xf8\\f\x07]\x07\x06c8\xb1\xbd2\xdb\xcf\x13-\xff\xe0Z'
3:14 PM custom_components/localtuya/pytuya/__init__.py (ERROR) - message first occured at 2:30 PM and shows up 86 times

@SergeS - Hi - thanks for the code. I have a 4 socket + 1 USB extension. The IDs for the sockets are 1,2,3,4 and the USB is 7.

#Local Tuya CC
- platform: localtuya
  host: 192.168.0.41
  local_key: 111111111111111111111
  device_id: 222222222222222222
  name: Desk Extension 1
  id: 1
- platform: localtuya
  host: 192.168.0.41
  local_key: 111111111111111111111
  device_id: 222222222222222222
  name: Desk Extension 2
  id: 2
- platform: localtuya
  host: 192.168.0.41
  local_key: 111111111111111111111
  device_id: 222222222222222222
  name: Desk Extension 3
  id: 3
- platform: localtuya
  host: 192.168.0.41
  local_key: 111111111111111111111
  device_id: 222222222222222222
  name: Desk Extension 4
  id: 4
- platform: localtuya
  host: 192.168.0.41
  local_key: 111111111111111111111
  device_id: 222222222222222222
  name: Desk Extension USB
  id: 7

The weird problem I have is that only FOUR of the FIVE switches will work. After restart one of the five randomly goes “Entity not available: switch.desk_extension_X”

Is FOUR the limit for the localtuya switch? IS it the USB causing the problem?

I have had a look at the code but, with my very limited coding skill, couldn’t see anything there.

Log Details (ERROR)
Mon Oct 14 2019 23:11:28 GMT+0400 (Самарское стандартное время)
Error while setting up platform localtuya
Traceback (most recent call last):
File “/config/custom_components/localtuya/switch.py”, line 87, in __get_status
status = self._device.status()
File “/config/custom_components/localtuya/pytuya/init.py”, line 281, in status
data = self._send_receive(payload)
File “/config/custom_components/localtuya/pytuya/init.py”, line 177, in _send_receive
s.connect((self.address, self.port))
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 150, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File “/usr/local/lib/python3.7/asyncio/tasks.py”, line 442, in wait_for
return fut.result()
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/localtuya/switch.py”, line 68, in setup_platform
config.get(CONF_VOLTAGE)
File “/config/custom_components/localtuya/switch.py”, line 129, in init
self._status = self._device.status()
File “/config/custom_components/localtuya/switch.py”, line 111, in status
self._cached_status = self.__get_status()
File “/config/custom_components/localtuya/switch.py”, line 91, in __get_status
raise ConnectionError(“Failed to update status.”)
ConnectionError: Failed to update status.

How do I fix this error?

switch:

  • platform: localtuya
    host: 192.168.0.100
    local_key: c91255f37209855e
    device_id: 858580502462ab27aefe
    name: tuya_01
    protocol_version: 3.3

How to adjust scan interval from 10 minutes for power monitor ? I’m using stast’s plugin.

Hi Everyone -

could someone please point me to how to pull my local_key & device_id?
Unfortunately, I do not have access to an android phone…

Thanks!

If you have a Windows computer, you can install bluestacks.