tinytuya icon indicating copy to clipboard operation
tinytuya copied to clipboard

Multiple DPS

Open vvmichielvv opened this issue 4 years ago • 1 comments

Hi,

I was wondering how to set multiple DPS in one request? F.e. i want to turn on a dimmer and set the dimming value in the same request. The devices support the following format i got from Googling around:

{multiple: true,data: {'1': true,'2': 50}}

Any thoughts?

Thanks!!

vvmichielvv avatar Jan 31 '21 10:01 vvmichielvv

Great question! I think there may be a feature request here for a simple combined function call... hum...

You could use set_value(dps_index,value) but would need to do that for each DPS value (2 calls for your example). To send it in one packet, you can build the payload yourself and send it using this:

import tinytuya

# Connect to the device
d=tinytuya.OutletDevice(DEVICEID, DEVICEIP, DEVICEKEY)
d.set_version(3.3)

# Generate the payload to send - add all the DPS values you want to change here
payload=d.generate_payload(tinytuya.CONTROL, {'1': True, '2': 50})

# Send the payload to the device
d._send_receive(payload)

NOTE: For some devices, it will not like this and you will get a timeout when you try to send the payload. Those devices require you to send two separate commands. My Gosund dimmer switch is one of those and requires that I send two commands, one for '1' for on/off and one for '3' for the dimmer. Also, keep in mind that the DPS value range for brightness may not be a 1-100, it could be 25-255 or 10-1000. At least that is the case for my devices (my Gosund is 25-255). The above code snip I ran against my smartbulbs without any problem (they accepted multiple DPS values).

jasonacox avatar Feb 01 '21 01:02 jasonacox