tinytuya.OutletDevice

class tinytuya.OutletDevice(dev_id, address=None, local_key='', dev_type='default', connection_timeout=5, version=3.1, persist=False, cid=None, node_id=None, parent=None, connection_retry_limit=5, connection_retry_delay=5, port=6668, max_simultaneous_dps=0)

Bases: Device

Represents a Tuya based Smart Plug or Switch.

Methods provided by this class

set_dimmer([percentage, value, dps_id, nowait])

Set dimmer value

Methods inherited from parent class

__init__(dev_id[, address, local_key, ...])

Represents a Tuya device.

add_dps_to_request(dp_indicies)

Add a datapoint (DP) to be included in requests.

cache_clear()

cached_status([historic, nowait])

Return device last status if a persistent connection is open.

close()

detect_available_dps()

Return which datapoints are supported by the device.

find(did)

Mainly here for backwards compatibility.

generate_payload(command[, data, gwId, ...])

Generate the payload to send.

heartbeat([nowait])

Send a keep-alive HEART_BEAT command to keep the TCP connection open.

product()

Request AP_CONFIG Product Info from device.

receive()

Poll device to read any payload in the buffer.

send(payload)

Send single buffer payload.

set_dpsUsed(dps_to_request)

set_multiple_values(data[, nowait])

Set multiple indexes at the same time

set_retry(retry)

set_sendWait(s)

set_socketNODELAY(nodelay)

set_socketPersistent(persist)

set_socketRetryDelay(delay)

set_socketRetryLimit(limit)

set_socketTimeout(s)

set_status(on[, switch, nowait])

Set status of the device to 'on' or 'off'.

set_timer(num_secs[, dps_id, nowait])

Set a timer.

set_value(index, value[, nowait])

Set int value of any index.

set_version(version)

status([nowait])

Return device status.

subdev_query([nowait])

Query for a list of sub-devices and their status

turn_off([switch, nowait])

Turn the device off

turn_on([switch, nowait])

Turn the device on

updatedps([index, nowait])

Request device to update index.

__init__(dev_id, address=None, local_key='', dev_type='default', connection_timeout=5, version=3.1, persist=False, cid=None, node_id=None, parent=None, connection_retry_limit=5, connection_retry_delay=5, port=6668, max_simultaneous_dps=0)

Represents a Tuya device.

Parameters:

dev_id (str) – The device id.

Keyword Arguments:
  • address (str, optional) – The network address.

  • local_key (str, optional) – The encryption key. Defaults to None.

  • cid (str, optional) – Optional sub-device id. Default to None.

  • node_id (str, optional) – alias for cid

  • parent (XenonDevice, optional) – gateway device this device is a child of

port

The port to connect to.

Type:

int

add_dps_to_request(dp_indicies)

Add a datapoint (DP) to be included in requests.

cache_clear()
cached_status(historic=False, nowait=False)

Return device last status if a persistent connection is open.

Parameters:

nowait (bool) – If cached status is is not available, either call status() (when nowait=False) or immediately return None (when nowait=True)

Response:
json if cache is available, else

json from status() if nowait=False, or None if nowait=True

close()
detect_available_dps()

Return which datapoints are supported by the device.

static find(did)

Mainly here for backwards compatibility. Calling tinytuya.find_device() directly is recommended.

Parameters:

for (did = The specific Device ID you are looking)

Response:

(ip, version)

generate_payload(command, data=None, gwId=None, devId=None, uid=None, rawData=None, reqType=None)

Generate the payload to send.

Parameters:
  • command (str) – The type of command. This is one of the entries from payload_dict

  • data (dict, optional) – The data to send. This is what will be passed via the ‘dps’ entry

  • gwId (str, optional) – Will be used for gwId

  • devId (str, optional) – Will be used for devId

  • uid (str, optional) – Will be used for uid

heartbeat(nowait=True)

Send a keep-alive HEART_BEAT command to keep the TCP connection open.

Devices only send an empty-payload response, so no need to wait for it.

Parameters:

nowait (bool) – True to send without waiting for response.

product()

Request AP_CONFIG Product Info from device. [BETA]

receive()

Poll device to read any payload in the buffer. Timeout results in None returned.

send(payload)

Send single buffer payload.

Parameters:

payload (bytes) – Data to send.

set_dimmer(percentage=None, value=None, dps_id=3, nowait=False)

Set dimmer value

Parameters:
  • percentage (int) – percentage dim 0-100

  • value (int) – direct value for switch 0-255

  • dps_id (int) – DPS index for dimmer value

  • nowait (bool) – True to send without waiting for response.

set_dpsUsed(dps_to_request)
set_multiple_values(data, nowait=False)

Set multiple indexes at the same time

Parameters:
  • data (dict) – array of index/value pairs to set

  • nowait (bool) – True to send without waiting for response.

set_retry(retry)
set_sendWait(s)
set_socketNODELAY(nodelay)
set_socketPersistent(persist)
set_socketRetryDelay(delay)
set_socketRetryLimit(limit)
set_socketTimeout(s)
set_status(on, switch=1, nowait=False)

Set status of the device to ‘on’ or ‘off’.

Parameters:
  • on (bool) – True for ‘on’, False for ‘off’.

  • switch (int) – The switch to set

  • nowait (bool) – True to send without waiting for response.

set_timer(num_secs, dps_id=0, nowait=False)

Set a timer.

Parameters:
  • num_secs (int) – Number of seconds

  • dps_id (int) – DPS Index for Timer

  • nowait (bool) – True to send without waiting for response.

set_value(index, value, nowait=False)

Set int value of any index.

Parameters:
  • index (int) – index to set

  • value (int) – new value for the index

  • nowait (bool) – True to send without waiting for response.

set_version(version)
status(nowait=False)

Return device status.

subdev_query(nowait=False)

Query for a list of sub-devices and their status

turn_off(switch=1, nowait=False)

Turn the device off

turn_on(switch=1, nowait=False)

Turn the device on

updatedps(index=None, nowait=False)

Request device to update index.

Parameters:
  • index (array) – list of dps to update (ex. [4, 5, 6, 18, 19, 20])

  • nowait (bool) – True to send without waiting for response.