tuya-local icon indicating copy to clipboard operation
tuya-local copied to clipboard

Is current code able to support gateway?

Open darek-margas opened this issue 3 years ago • 4 comments

I've got some unique gateway for irrigation but it works as zigbee (except it is not zigbee). I've tested it with tuya-cli and it works perfectly if I specify cid for child device. Thing is - would it be possible to pass cid over this code?

darek-margas avatar Nov 07 '21 07:11 darek-margas

I'll need to look into what this entails further. Most likely it will need some upstream changes to the tinytuya library, as the current documentation does not mention gateways at all.

make-all avatar Nov 07 '21 23:11 make-all

I think it is just payload. There is some clue in localtuya repo in "zigbee gateway" branch. What that would need is optional CID field added to initial config window and then it has to pass CID pretty much as they tried in localtuya. I've heard for set command to succeed ID must be from child device but that is all about initial fields.

Tuya API shows gateway as this:

[ { name: 'Tuya Alfresco', id: 'XXXX as ID for gateway', key: 'KEY' }, { name: 'Hollman Wi Fi Hub', id: 'XXXX as id for child device', key: 'KEY', subDevices: [ { name: 'WX1 Tap', id: 'XXXX tap ID', cid: '131' }, { name: 'Wi-Fi Socket', id: 'XXX another ID', cid: '13B' } ] },

tuya-cli get --ip 192.168.0.1 --id XXXX tap ID --key KEY --cid 131 --full --protocol-version 3.3 { dps: { '101': 0, '102': 0, '103': 5, '105': '2', '106': '3', '107': 12, '108': true, '113': '72', '114': '24', '115': false, '116': false, '117': true, '119': '1', '120': 0, '125': false, '127': 'HOL9-018-023-000-000' }, cid: '131' }

darek-margas avatar Nov 08 '21 01:11 darek-margas

I managed to alter localtuya to get it working.

darek-margas avatar Nov 21 '21 14:11 darek-margas

I looked today at tinytuya. It seems the same trick will work, section to change is in init, lines 350-400. Without changes there it won't work.

darek-margas avatar Dec 04 '21 11:12 darek-margas

Hi @make-all and @darek-margas , Just FYI:

I added support for devices connected to zigbee gateway into tinytuya. I'm preparing PR which adds support for tuya-local, right now I made some changes in my fork and it looks good. I'll open PR when it is ready.

LesTR avatar Nov 27 '22 14:11 LesTR

tinytuya library is now updated to 1.9.1, so the support for making changes to support hubs is available in the underlying library.

This will be useful also for #170

make-all avatar Dec 03 '22 13:12 make-all

@LesTR I'm putting up my hand if you need a beta tester. I've got some Tuya Zigbee irrigation valves that I would love to get working with this.

illuzn avatar Dec 12 '22 03:12 illuzn

Hi @illuzn, my changes were broken after https://github.com/jasonacox/tinytuya/pull/226 and I still don't have time to fix it. Hopefully, I'll find some time next week.

LesTR avatar Dec 19 '22 09:12 LesTR

Since I have made lots of conflicting changes over the past couple of releases, I took the opportunity to rebase your main branch in https://github.com/make-all/tuya-local/tree/LesTR/main

But I don't have any suitable devices for testing, so I can't judge whether it is actually working or not. But I did fix the config and tests that you added so at least those pass now.

make-all avatar Jan 15 '23 13:01 make-all

Hi there, tried LesTR integration with the Holman WX1 water valve without luck. Log list attached image

CiaoBelli87 avatar Jan 21 '23 07:01 CiaoBelli87

I just rebased that branch again, as there are a number of fixes in main over the past week, including I think a fix for the "Detected blocking call..."

make-all avatar Jan 21 '23 08:01 make-all

Hi, I failed to configure tuya local from the LesTR integration. I have a "Tuya ZigBee Gateway Bridge Wireless Smart Hub" with 10 "AUBESS Tuya ZigBee Temperature Humidity Sensor" paired with the Smart Life app.

I tested with tinytuya python package ver 1.10.1 and works the requests for temperature and humidity values.

I created a configuration file for the AUBESS temperature/humidity sensor:

name: Temperature Humidity Sensor
products:
  - id: xr3htd96
primary_entity:
  entity: sensor
  name: Current temperature
  class: temperature
  dps:
    - id: 1
      type: integer
      name: sensor
      unit: C
      class: measurement
      mapping:
        - scale: 10
secondary_entities:
  - entity: sensor
    name: Current humidity
    class: humidity
    dps:
      - id: 2
        type: integer
        name: sensor
        unit: "%"
        class: measurement
        mapping:
            - scale: 10
  - entity: sensor
    name: Battery
    class: battery
    category: diagnostic
    dps:
      - id: 4
        name: sensor
        type: integer

I replaced the contents in custom_components/tuya_local folder from this branch. Log list: image Detailed error: image

The id after the KeyError ist from Sub device ID from new integration page. The tinytuya version used by Home Assistant: 1.9.1 The previously configured Wi-Fi device integrations only works after I delete them and re-integrate them.

I don't know if the gateway should be added separately as a device, or if only the devices should be added to the integrations, I couldn't find a description for this. However, I was not able to add the gateway separately.

Thank you for your time and consideration.

Best regards, lovaselek

lovaselek avatar Feb 02 '23 22:02 lovaselek

Hi, I managed to find the source of my problem:

I changed the lines in device.py, I added keys to the function call parameters(changed parameter order in tinytuya lib), and I added the version to the parent device (my gateway device works only with version 3.3).

        if cid is not None:
            _LOGGER.info(f"Creating sub device {cid} from gateway {dev_id}.")
            parent = tinytuya.Device(dev_id, address=address, local_key=local_key, persist=True, version=protocol_version if protocol_version != "auto" else None)
            tuya_device_id = cid
            local_key = None
        self._api = tinytuya.Device(
            tuya_device_id,
            address=address,
            local_key=local_key,
            cid=cid,
            parent=parent,
        )

It works perfectly with the Aubeus zigbee temperature and humidity sensor config file from my previous post.

image

Have a nice day!

lovaselek avatar Feb 14 '23 21:02 lovaselek

Hi @lovaselek , that's correct, and I can confirm it fixed getting data from my Zigbee temperature sensors. My fork is updated with this change but not rebased on top of the main branch.

But there is still some issue because I'm not able to get data from other devices behind the same gateway which was working before - switch and thermostat. Most probably, it has something to do with persistent connection to the gateway.

Sorry, I've been really busy for the last 2 months, really hard to find some time to fix this. Hopefully, it will be better soon.

LesTR avatar Feb 14 '23 22:02 LesTR

I did add an option to disable the persistent connection a few versions ago, so if you can update your branch again, it should be easy to test if the persistent connection is the cause. Looking at the code in tinytuya, they redirect to the parent device, so should be sharing the same persistent connection, but if this is not working for some reason, it may cause sub devices to block each other due to the limited number of connections tuya devices can handle. Maybe we need to do something in the integration to ensure the parent device is the same object for all sub devices.

make-all avatar Feb 14 '23 22:02 make-all

Maybe we need to do something in the integration to ensure the parent device is the same object for all sub devices.

That's exactly my concern. I'll try to rebase my branch and do some tests, but probably not sooner than during this weekend.

LesTR avatar Feb 14 '23 22:02 LesTR

@LesTR any luck with the rebase of your branch? Adding Bluetooth devices through the gateway depends on this issue's progress. I can help with testing as I own the bridge with Bluetooth subdevices currently integrated with HA using tuya cloud.

meceo avatar Mar 23 '23 11:03 meceo

Hi, I have a ningbo hct-611 wifi water timer which works with a Bluetooth/Wifi gateway and is managed by Tuya(Smartlife) app with no problem. I tried to integrate it using Local Tuya with no success.. Is there a way to integrate it with Tuya-local? Is there someone that already succeeded? Thanks in advance

Ningbo-Hanci-Electrical-HCT-611-Wireless-Water-Timer.jpg

spanzetta avatar Apr 22 '23 20:04 spanzetta

Is there someone that already succeeded?

Some time ago I modified my fork of localtuya to support similar tap working with UHF gateway which appears like zigbee one just uses 900MHz band. It does work for me as it is the only Tuya I kept (all the rest I either flashed or transplanted). Someone else made fork from mine and fixed double tap issue showing same state for multiple taps. So, it does work there and may for you as well. The downside is that whole fork is off very old localtuya. I proposed similar change here but it was declined as it required modification of underlying module.
image

darek-margas avatar Apr 24 '23 03:04 darek-margas

I believe currently the best option is:

https://github.com/leeyuentuen/localtuya

felipecrs avatar Apr 24 '23 04:04 felipecrs

I believe currently the best option is:

https://github.com/leeyuentuen/localtuya

I am already using this one but I wasn't able to make it working with my water timer (even specifying manually the Pids). tried to ask help but didn't get any.. that's why I am looking at some alternatives

spanzetta avatar Apr 24 '23 04:04 spanzetta

Is there someone that already succeeded?

Some time ago I modified my fork of localtuya to support similar tap working with UHF gateway which appears like zigbee one just uses 900MHz band. It does work for me as it is the only Tuya I kept (all the rest I either flashed or transplanted). Someone else made fork from mine and fixed double tap issue showing same state for multiple taps. So, it does work there and may for you as well. The downside is that whole fork is off very old localtuya. I proposed similar change here but it was declined as it required modification of underlying module.
image

Where can I find those modified fork exactly?

spanzetta avatar Apr 24 '23 04:04 spanzetta

Here is more at forum: https://community.home-assistant.io/t/holman-wifi-tap-timers-intergration/313920/140 Here is my fork: https://github.com/darek-margas/localtuya

darek-margas avatar Apr 24 '23 05:04 darek-margas

Support was added with PR #651

make-all avatar Apr 29 '23 14:04 make-all