Local Tuya - Control Tuya devices locally (Fork from localtuya)

Hello everyone, I was trying to solve an error of original localtuya, thought that this version will help me, but still the error appears, have someone encountered it? How have you solved it?

Logger: custom_components.localtuya.common
Source: custom_components/localtuya/core/pytuya/__init__.py:288
Integration: Local Tuya (documentation, issues)
First occurred: 16:15:35 (2 occurrences)
Last logged: 16:15:40

[bf3...6f9] Failed to connect to 192.168.1.240: [Errno 113] Connect call failed ('192.168.1.240', 6668)
[bfb...yvv] Failed to connect to 192.168.1.241: [Errno 113] Connect call failed ('192.168.1.241', 6668)

The main problem it`s not a an error itself, but in a connection losing with tuya sockets, they just go unavailable for several minutes and then just return online, I blocked their connection to the internet btw.

UPD:

It crashed :slight_smile:

Logger: custom_components.localtuya.core.pytuya
Source: custom_components/localtuya/core/pytuya/__init__.py:1105
Integration: Local Tuya (documentation, issues)
First occurred: 17:51:01 (1 occurrences)
Last logged: 17:51:01

[bf3...6f9] Failed to get status:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 500, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/locks.py", line 387, in acquire
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1105, in detect_available_dps
    data = await self.status(cid=cid)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1024, in status
    status: dict = await self.exchange(command=DP_QUERY, nodeID=cid)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 998, in exchange
    msg = await self.dispatcher.wait_for(seqno, payload.cmd)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 609, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 502, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

Sorry, I see it now. I have Tuya BLE integration install but it throws an error
Config flow could not be loaded: {“message”:“Invalid handler specified”}

Does this integration rely on the HA host to have Bluetooth?

Here is a couple of hints/help

Tuya BLE integration, includes fingerbot - #95 by ajproenca.
Fix for similar issue seems to come soon
fix: Compatibility with HA 2024.1 - import consts from core by michalbundyra · Pull Request #96 · PlusPlus-ua/ha_tuya_ble · GitHub.
The orig Topic for your integration
Tuya BLE integration, includes fingerbot.
And Forum search for same
Search results for 'Tuya BLE integration' - Home Assistant Community.

Sorry can’t be of more help, i actually runs my HA on a laptop, with bluetooth, so i used the native bluetooth integration, until i ditched the bluetooth devices ( bad reception, draining batteries, dropping out, nothing but problems :smile:

Good afternoon,

My name is Richard, living in the Netherlands.
I have been working with Home Assistant for a few months now. In itself, I’m doing fine with installing the usual integrations.

But now the following: I bought a smart TV lift, and I would like to integrate it so that I can create an automation when the TV is turned on and the lift rises. This concerns this model: MyWall TV Lift Medium HP63-1 - Beugels en Meer

With the normal Tuya integration, the device is recognized, after the name it says (unsupported). Device was added without entities. So this was not an option. I continued looking for a solution and then came across the local-tuya integration.

The local-tuya integration has been installed. I have carefully followed the documentation instructions. Adding the device goes well.

1

Auto configure does not work:
2

Then I continued with the manual configuration. Chosen for the ‘cover’ entity, as in my opinion it most closely matches the type of device.
4

I can’t go any further from here. I have tried many combinations and things, but without success. However, at one point there was a response that the lift was going up, but that suddenly stopped working.

What else I was able to find on the tuya API explorer site (get instruction set) is the following:

{
“result”: {
“category”: “zndsj”,
“functions”: [
{
“code”: “move”,
“desc”: “{“range”:[“move_up”,“move_down”,“move_left”,“move_right”,“move_default”,“cancel”]}”,
“name”: “运行控制”,
“type”: “Enum”,
“values”: “{“range”:[“move_up”,“move_down”,“move_left”,“move_right”,“move_default”,“cancel”]}”
},
{
“code”: “memory”,
“desc”: “{“range”:[“mem1”,“mem2”,“mem3”,“recall1”,“recall2”,“recall3”,“cancel”]}”,
“name”: “位置记忆”,
“type”: “Enum”,
“values”: “{“range”:[“mem1”,“mem2”,“mem3”,“recall1”,“recall2”,“recall3”,“cancel”]}”
}
],
“status”: [
{
“code”: “move”,
“name”: “运行控制”,
“type”: “Enum”,
“values”: “{“range”:[“move_up”,“move_down”,“move_left”,“move_right”,“move_default”,“cancel”]}”
},
{
“code”: “model_no”,
“name”: “型号”,
“type”: “String”,
“values”: “{“maxlen”:255}”
},
{
“code”: “memory”,
“name”: “位置记忆”,
“type”: “Enum”,
“values”: “{“range”:[“mem1”,“mem2”,“mem3”,“recall1”,“recall2”,“recall3”,“cancel”]}”
},
{
“code”: “fault_code_report”,
“name”: “故障码上报”,
“type”: “Bitmap”,
“values”: “{“label”:[“fault_code_1”,“fault_code_2”],“maxlen”:2}”
}
]
},
“success”: true,
“t”: 1707395295815,
“tid”: “8874b9f2c67d11eea1957edaaa357452”
}

If anyone could help me with this, that would be great! I would like to hear from you!

Thank you

Greetings,
Richard

The issue isn’t in add the device manually or the category not added into auto configuration, It’s how we can let home assistant handle this kinda of devices. for example HA cover platform supports 3 commands open, close and stop and your device has more so the only platform that I can think of is “select” by adding your 101 ID using “select” platform and map the values to something like this.

move_up: Move Up
move_down: Move Down
move_left: Move Left
move_right: Move Right
move_default: What is this
cancel: Stop

Does this fork support IR blasters (remotes)? I have a Tuya IR blaster, but can’t use it with the original component, so I found this when looking at the forks in the ‘network’ on GitHub.
The original has this unmerged PR: Add IR Button Support by ynsgnr · Pull Request #1597 · rospogrigio/localtuya · GitHub
Thanks!

Man, this is great. I can’t thank you enough for providing the solution in one go. It works perfectly now.

The only thing I wish is that I could operate the lift like a cover. Now I have to select the command from a list:

Would love to have this in the way you operate a cover.

Thank you very much, really happy with this solution!

Richard

I think you can create template-buttons, for the different defined “values” now that you got the select to work correct

Thanks for your reply, for now that’s to complicated to figure out by my own. Could you guys help me in the right direction? Where to start?

Thanks everybody!

1 Like

In iot.tuya you can fetch some more info from your device, in api-explore (left pane) go through the menu, just for curiosity :slightly_smiling_face: , but maybe the
Device Control
and
Device Control(standard instruction set)

As for templating, im not an expert either
But with the knowledge of the specific instruction, i.e move up (if tha’t a selection you currently have) maybe Developer/Tools#States also can help you here.

i was thinking a button(maybe custom:button-card) … on_tap or on_hold = move_up /move down
Same for the other functions
I’ve seen quite a few which have made their own cards, same as they do for i.e mediaplayers/remote-controls and similar
Use the search function in this forum, and if you can’t find similar functions, then open a new Topic , with as much info/details you can provide, an your “example-card” as you would like/have tried to create
( Maybe there is already service_calls for your current functions )

Installation worked like a charm and auto discovery worked perfectly. Thanks so much for the plugin.
For others that come this way - this worked perfectly for the devices that I have

  1. Wipro Smart Switch 4N Module 2
  2. Wipro RGBCW_ SMART Garnet light bulb
  3. Wipro 16Amp Smart Plug
  4. arcnics® - 16A (Heavy) Smart WiFi Retrofit Switch
  5. Finery 3 Node WiFi Smart Switch Retrofit Kit
1 Like

I ran into issues with localtuya (spotlight being unavailable even when I could detect it on iot.tuya and my tuya app).
Removed that integration and added this (could not have both due to name conflict), and the device was detected right off the bat. Thank you.

Considering I am new to HA (and not a dev of any kind either), I have been reading up a ton. For newer stumblers here:

I enabled the cloud API option so hass-localtuya could detect the already added devices. Once everything was in order (devices working correctly), I added the tuya device to my blocklist to disable internet access to the spotlight and disabled cloud API in localtuya config.

Seems everything is in order so far.

1 Like

Update: 3.2.5 should supports IR Remotes it works similar to BroadLink remote.
learn commands using learn_command service and use via send_command service.

Usage: https://youtu.be/lWCHZm9xWno?t=189

Note: If connecting to the device fails due to no dps found and you are sure of “protocol_version” insert 0 in manual dps field.

3 Likes

Thanks to @umu_ugg - the IR remote is now supported. I can turn on my dumb AC with a cheap IR blaster. :clap:

1 Like

Do you have more details on how this works? Ie where to look for templates?

I’m trying to setup the WIFI Dual Meter (PJ1103A, product id: z95s7p3z54xbsjnl). The original localtuya was able to talk to the device but all entities had to be manually configured without any info even though there is a device configuration for it. With your version of localtuya, I still have to manually configure the entities but the DP ID is populated with the variable name which helps in knowing what each thing is.
This is the same device as mentioned in this issue. It looks like some people are able to get it working but my instance doesn’t automatically recognize all of the entities, only one entity.

This is what is automatically setup:

1 Like

The templates are supposed to be manually made which is the hard way but it mainly used to export the already configured devices. so if you have device you can export it as template and use it later to setup same or similar devices. it seems you have cloud setup so you should either rely on “automatic” or “manually” unless you already has template which it seems not.

If the automatic doesn’t added all entities then it seems your device isn’t fully added in database. if you can post the “device diagnostic” I can add it, you can download it from device page.

Thanks, I ended up trying the make-all fork and it brought everything in automatically. Below are the configs for this device:

I just wanted to say a big thank you!!

I was having a few issues with the original local Tuya, and as a quality of life change, the auto configuration is a godsend!

1 Like

Hello,
First of all thanks for your work. I had a question concerning Smart Scene Switch button I bought from Aliexpress. They are all Zigbee devices and I had them set in homeassistant through localtuya but i can not manage to create automation on a button click. all i have on tgrigger is the "option changed " like from single click to double click or from double click to long press etc
So how do i set just an automation for single click? I tested to set from single click to single click but it doesnt work (normal because when its already on single click if you use the button for another click the state doesn’t change)

1 Like

Don’t use the entities as a trigger in automation instead use the events triggers.
https://xzetsubou.github.io/hass-localtuya/ha_events/#__tabbed_1_2

1 Like