-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathsend_raw_dps.py
31 lines (23 loc) · 1.15 KB
/
send_raw_dps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# TinyTuya Example
# -*- coding: utf-8 -*-
"""
TinyTuya - Example to send raw DPS values to Tuya devices
You could also use set_value(dps_index,value) but would need to do that for each DPS value.
To send it in one packet, you build the payload yourself and send it using something simliar
to this example.
Note: Some devices will not accept multiple commands and 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.
Author: Jason A. Cox
For more information see https://github.com/jasonacox/tinytuya
"""
import tinytuya
# Connect to the device - replace with real values
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})
# Optionally you can set separate gwId, devId and uid values
# payload=d.generate_payload(tinytuya.CONTROL, data={'1': True, '2': 50}, gwId=DEVICEID, devId=DEVICEID, uid=DEVICEID)
# Send the payload to the device
d._send_receive(payload)