jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
867 stars 157 forks source link

I can read DSP but don't write it #476

Closed Lutty76 closed 3 months ago

Lutty76 commented 3 months ago

Hi,

I have Tinytuya that work fine for some month, but today I have to make a new pairing to my ceiling fan.

After another pair, local key have changed :/ After more than one month, my cloud subscription has expired ...

I make a new account, new project, linked my tuya account. I got my device and new local key.

image

 {
        "category": "fsd",
        "sub": false,
        "uuid": "648310a8080288ae",
        "ip": "192.168.1.60",
        "version": "3.3",
        "biz_type": 0,
        "product_name": "",
        "mac": "cc:8c:bf:2f:ca:42",
        "product_id": "u5ovvhurbvynvspv",
        "sn": "100069929012CC",
        "key": "HIDDEN_MAYBE_USELESS",
        "model": "101",
        "icon": "https://images.tuyaeu.com/smart/icon/ay1564458733639x1LBu/7e84ea311049e256d357d89d74276448.png",
        "id": "bfc9ad3c786bed50aeh1k0",
        "name": "Light+Fan-new product"
    },

And I can read data from tinytuya

>>> d = tinytuya.OutletDevice(dev_id='bf971ef1763e3ace072cav',address='192.168.1.60',local_key='HIDDEN_MAYBE_USELESS',version=3.3);
>>> data = d.status();
>>> print('set_status() result %r' % data)
set_status() result {'dps': {'20': False, '21': 'white', '22': 10, '23': 0, '58': 10, '60': False, '62': 1, '63': 'reverse', '64': 0}}

But try to control device don't work... No error, just not working

>>> payload=d.generate_payload(tinytuya.CONTROL, {'20': True})
>>> d._send_receive(payload)
>>> data = d.status();
>>> print('set_status() result %r' % data)
set_status() result {'dps': {'20': False, '21': 'white', '22': 10, '23': 0, '58': 10, '60': False, '62': 1, '63': 'reverse', '64': 0}}

I have missing something ?

uzlonewolf commented 3 months ago

Hi @Lutty76 !

It shouldn't be necessary to use underscore functions like _send_receive; for what you're doing the preferred way is either d.turn_on(20) or d.set_value(20, True).

That said, I don't see why it's not working. What do the debug logs (tinytuya.set_debug(True) and then d.turn_on(20)) look like?

Lutty76 commented 3 months ago

This morning, that working fine... The old way (d.generate_payload) and your way (d.turn_on)

This morning I have pair again my device to my wifi.

It's an error from me, I keep previous ID of device, but it changes at each pairing ....

Sorry to open a ticket for nothing...

uzlonewolf commented 3 months ago

No worries, I'm glad you got it working.