Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is current code able to support gateway? #70

Closed
darek-margas opened this issue Nov 7, 2021 · 24 comments
Closed

Is current code able to support gateway? #70

darek-margas opened this issue Nov 7, 2021 · 24 comments

Comments

@darek-margas
Copy link
Contributor

darek-margas commented Nov 7, 2021

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?

@make-all make-all added the enhancement New feature or request label Nov 7, 2021
@make-all
Copy link
Owner

make-all commented Nov 7, 2021

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.

@darek-margas
Copy link
Contributor Author

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
Copy link
Contributor Author

I managed to alter localtuya to get it working.

@darek-margas
Copy link
Contributor Author

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.

@LesTR
Copy link
Contributor

LesTR commented Nov 27, 2022

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.

@make-all
Copy link
Owner

make-all commented Dec 3, 2022

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

@illuzn
Copy link
Contributor

illuzn commented Dec 12, 2022

@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.

@LesTR
Copy link
Contributor

LesTR commented Dec 19, 2022

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

@make-all
Copy link
Owner

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.

@CiaoBelli87
Copy link

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

@make-all
Copy link
Owner

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..."

@lovaselek
Copy link

lovaselek commented Feb 2, 2023

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
Copy link

lovaselek commented Feb 14, 2023

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!

@LesTR
Copy link
Contributor

LesTR commented Feb 14, 2023

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.

@make-all
Copy link
Owner

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.

@LesTR
Copy link
Contributor

LesTR commented Feb 14, 2023

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.

@make-all make-all added the subdevice Requires subdevice support label Feb 18, 2023
@meceo
Copy link

meceo commented Mar 23, 2023

@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.

@spanzetta
Copy link

spanzetta commented Apr 22, 2023

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

@darek-margas
Copy link
Contributor Author

darek-margas commented Apr 24, 2023

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

@felipecrs
Copy link
Contributor

I believe currently the best option is:

https://github.com/leeyuentuen/localtuya

@spanzetta
Copy link

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
Copy link

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?

@darek-margas
Copy link
Contributor Author

@make-all make-all added the awaiting confirmation Wating for confirmation the issue is solved label Apr 29, 2023
@make-all make-all added the unreleased Will be in next release label Apr 29, 2023
@make-all
Copy link
Owner

Support was added with PR #651

@make-all make-all removed enhancement New feature or request awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release subdevice Requires subdevice support labels May 7, 2023
@make-all make-all closed this as completed May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants