TuyaDevice

Represents a Tuya device.

new TuyaDevice(options: Object)

Extends EventEmitter

Parameters
options (Object)
Name Description
options.ip String? IP of device
options.port Number (default 6668) port of device
options.id String ID of device
options.key String encryption key of device
options.productKey String product key of device
options.version Number (default 3.1) protocol version
options.persistentConnection Boolean (default false) whether or not to use a persistent socket with heartbeat packets
Example
const tuya = new TuyaDevice({id: 'xxxxxxxxxxxxxxxxxxxx',
                             key: 'xxxxxxxxxxxxxxxx',
                             persistentConnection: true})
Instance Members
resolveId(options?)
resolveIds(options)
get(options?)
set(options)
connect()
disconnect()
isConnected()

Events

Events that TuyAPI emits.

Events

Events that TuyAPI emits.

TuyaDevice#error

Emitted on socket error, usually a result of a connection timeout. Also emitted on parsing errors.

TuyaDevice#error
Properties
error (Error) : error event

TuyaDevice#connected

Emitted when socket is connected to device. This event may be emitted multiple times within the same script, so don't use this as a trigger for your initialization code.

TuyaDevice#connected

TuyaDevice#data

Emitted when data is returned from device.

TuyaDevice#data
Properties
data (Object) : received data
commandByte (Number) : commandByte of result (e.g. 7=requested response, 8=proactive update from device)

TuyaDevice#disconnected

Emitted when a socket is disconnected from device. Not an exclusive event: error and disconnected may be emitted at the same time if, for example, the device goes off the network.

TuyaDevice#disconnected