polyedre / tuya-lan

A custom component to Home Assistant to integrate Tuya without the use of tuya servers
MIT License
11 stars 1 forks source link

Only support smart plugs, what about others ? #1

Closed polyedre closed 4 years ago

polyedre commented 5 years ago

This repo only support smart plug and is specific for retrieving monitored data about power consumption, how can I add support for other devices ?

polyedre commented 5 years ago

As this library rely on python-tuya, the best is to try manually to get your device working.

  1. Get your local_key and your device_id
  2. Try to get status
    >>> import pytuya
    >>> device = pytuya.OutletDevice('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE')
    >>> device.status()
  3. Try to set status to understand how it works When the feature you want is possible manually, you can add support by writing a fan.py, switch.py, etc module I think you can take inspiration on sensor.py even if this is not the best piece of code

Other inspiration: https://github.com/home-assistant/home-assistant/pull/11000/files https://github.com/home-assistant/home-assistant/pull/15399/files

RXM307 commented 5 years ago

Both of my devices are timing out locally, they work fine via the App (I've even put my phone in airport mode, as I've read many devices only allow 1 connection)

import pytuya device = pytuya.OutletDevice('xxxxxxxxx', 'xxx.xx.xxx.xxx', 'xxxxxx') device.status() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/site-packages/pytuya/init.py", line 256, in status data = self._send_receive(payload) File "/usr/local/lib/python3.7/site-packages/pytuya/init.py", line 166, in _send_receive data = s.recv(1024) socket.timeout: timed out

polyedre commented 5 years ago

Yes, you need to close the app if you want to use this API :)

RXM307 commented 5 years ago

Still cannot access, even with the App Closed or even without the mobile device on the wifi

polyedre commented 5 years ago

You can check if you receive broadcast from the device. When it is not in communication with a device, it sends UDP packets to port 6666 using broadcast. Try nc -lup 6666 (make sure the app is closed)

RXM307 commented 5 years ago

Nope had this running while i was out of the house the other day and nothing.....

RXM307 commented 4 years ago

Interestingly I now have my devices working locally with this custom component https://github.com/stast1/localtuya how this differs to yours I don't know as it is also using pytuya, so this issue can be closed unless you are going to add this support for yourself.

polyedre commented 4 years ago

Very strange, because the part that wasn't working for you seemed to be the pytuya part !