Represents a Tuya device.
Parameters
options
Object options for constructing a TuyaDeviceoptions.type
String type of device (optional, default'outlet'
)options.ip
String? IP of deviceoptions.port
Number port of device (optional, default6668
)options.id
String ID of deviceoptions.uid
String UID of device (optional, default''
)options.key
String encryption key of deviceoptions.version
Number protocol version (optional, default3.1
)
Examples
const tuya = new TuyaDevice({id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'})
const tuya = new TuyaDevice([
{id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'},
{id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'}])
Resolves IDs stored in class to IPs. If you didn't pass IPs to the constructor, you must call this before doing anything else.
Returns Promise<Boolean> true if IPs were found and devices are ready to be used
Gets a device's current status. Defaults to returning only the value of the first result, but by setting {schema: true} you can get everything.
Parameters
options
Object? optional options for getting data
Examples
// get status for device with one property
tuya.get().then(status => console.log(status))
// get status for specific device with one property
tuya.get({id: 'xxxxxxxxxxxxxxxxxxxx'}).then(status => console.log(status))
// get all available data from device
tuya.get({schema: true}).then(data => console.log(data))
Returns Promise<Object> returns boolean if no options are provided, otherwise returns object of results
Sets a property on a device.
Parameters
options
Object options for setting properties
Examples
// set default property on default device
tuya.set({set: true}).then(() => console.log('device was changed'))
// set custom property on non-default device
tuya.set({id: 'xxxxxxxxxxxxxxxxxxxx', 'dps': 2, set: true}).then(() => console.log('device was changed'))
Returns Promise<Boolean> returns true
if the command succeeded