Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bae8cf9
Merge branch 'regional-tuya-servers'
basdelfos Aug 9, 2019
b214896
Bump version
basdelfos Aug 9, 2019
aff0378
Update readme
basdelfos Aug 9, 2019
54e6861
create initial light accessory
niksauer Aug 9, 2019
241699e
add light accessory source code
niksauer Aug 9, 2019
0c57118
only extend base accessory to avoid duplicate call handlers
niksauer Aug 9, 2019
1908652
fix duplicate accessory creation
niksauer Aug 9, 2019
d9c42e7
enable dynamic api payload
niksauer Aug 10, 2019
297ce8c
move to object based state updates
niksauer Aug 10, 2019
e797605
pass log to webapi
niksauer Aug 10, 2019
a139a41
define homekit compatible defaults, fix caching, retrieve color mode …
niksauer Aug 11, 2019
31a7472
change log level of state update method
niksauer Aug 11, 2019
02107be
update setDeviceState calls to use object-based payload
niksauer Aug 13, 2019
4336098
Fix for outlet/switch no update if manual off #17
basdelfos Aug 18, 2019
34a26ea
Bump version
basdelfos Aug 18, 2019
3a2700a
Merge remote-tracking branch 'niksauer/master' into niksauer
basdelfos Aug 18, 2019
7bb6d2d
Merged light accessory made by niksauer (thanks!)
basdelfos Aug 18, 2019
bdeccca
Removed to much logging (can be undone for debugging by uncommenting)
basdelfos Aug 18, 2019
35bf2a3
Added overruling device type in config
basdelfos Aug 18, 2019
1d47c46
Merge branch 'niksauer'
basdelfos Aug 18, 2019
1f96042
Bump version
basdelfos Aug 18, 2019
8d433e4
Fix not correct updating
basdelfos Aug 18, 2019
4de848f
Bump version
basdelfos Aug 18, 2019
11c41e1
Update tuyawebapi_test.js
basdelfos Aug 31, 2019
8ae0cc0
Update README.md
basdelfos Dec 26, 2019
533cefa
Update README.md
basdelfos Dec 26, 2019
3707eec
Update README.md
basdelfos Dec 26, 2019
bb0e48d
Update README.md
basdelfos Jun 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Announcement
[Milo526](https://github.com/milo526) has been so kindfull to take this repository to the next level, go see his repository on https://github.com/milo526/homebridge-tuya-web.

For futher development and bugfixing, I recommand to use his repository.

# homebridge-tuya-web

Homebridge plugin for Tuya devices using a cloud Tuya Web Api.
Expand Down Expand Up @@ -45,6 +50,32 @@ The `options` has these properties:
- `plaform`: The App where your account is registered. `tuya` for Tuya Smart, `smart_life` for Smart Life, `jinvoo_smart` for Jinvoo Smart. Defaults to `tuya`.
- `pollingInterval`: Optional. The frequency in **seconds** that the plugin polls the cloud to get device updates. When the devices are only controlled through Homebridge, you can set this to a low frequency (high interval nummer, e.g. 180 = 3 minutes). Defaults to 10.

## Overrule / default values

As of version 0.1.6 it is possible to override or set values to default. As of now only overruling device type is posible. See configuration below.

```javascript
{
"platform": "TuyaWebPlatform"
"name": "TuyaWebPlatform",
"options":
{
...
},
"defaults": [
{
"id": "<id>",
"device_type": "<device_type>"
}
]
}
```

The `defaults` has these properties:

- `id`: Required. The id for the device that is registered in the Android/iOS App.
- `device_type`: Optional. The device_type to be overruled. For now only device type `dimmer` is supported. This can be usefull for dimmers that are reported as `light` by the Tuya API and don't support hue and saturation.

## Supported device types

There is currently support for the following device types within this Homebridge plugin:
Expand Down Expand Up @@ -74,3 +105,22 @@ The source code also has some unit tests to test API calls. Run the following co
```
mocha test/tuyawebapi_test.js
```

## Version history

##### Version 0.1.7 - 2019-08-18

* Fixed not correct updating after reboot of Homebridge.

##### Version 0.1.6 - 2019-08-18

* Added light accessory (made by niksauer, thanks!!)
* Added overruling device type in config. Some dimmers are reported by Tuya API as `lights`. Dimmers don't have hue and saturation and therfor the device type has to be overruled to `dimmer`.

##### Version 0.1.5 - 2019-08-18

* Fixed issue #17 - Outlets and switches not turning off in Home app when turned off with other app.

##### Version 0.1.4 - 2019-08-09

* Switch to regional Tuya Web API server after authentication was successful (EU / China / USA).
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const SwitchAccessory = require('./lib/switch_accessory');
const OutletAccessory = require('./lib/outlet_accessory');
const DimmerAccessory = require('./lib/dimmer_accessory');
const LightAccessory = require('./lib/light_accessory');
const TuyaWebApi = require('./lib/tuyawebapi');

var Accessory, Service, Characteristic, UUIDGen;
Expand Down Expand Up @@ -39,7 +40,8 @@ class TuyaWebPlatform {
this.config.options.username,
this.config.options.password,
this.config.options.countryCode,
this.config.options.platform
this.config.options.platform,
this.log
);

this.accessories = new Map();
Expand Down Expand Up @@ -102,17 +104,30 @@ class TuyaWebPlatform {
}

addAccessory(device) {
const deviceType = device.dev_type || 'switch';
var deviceType = device.dev_type || 'switch';
this.log.info('Adding: %s (%s / %s)', device.name || 'unnamed', deviceType, device.id);

// Get UUID
const uuid = this.api.hap.uuid.generate(device.id);
const homebridgeAccessory = this.accessories.get(uuid);

// Is device type overruled in config defaults?
if (this.config.defaults) {
for (const def of this.config.defaults) {
if (def.id === device.id) {
deviceType = def.device_type || deviceType;
this.log('Device type is overruled in config to: ', deviceType);
}
}
}

// Construct new accessory
let deviceAccessory;
switch (deviceType) {
case 'light':
deviceAccessory = new LightAccessory(this, homebridgeAccessory, device);
this.accessories.set(uuid, deviceAccessory.homebridgeAccessory);
break;
case 'dimmer':
deviceAccessory = new DimmerAccessory(this, homebridgeAccessory, device);
this.accessories.set(uuid, deviceAccessory.homebridgeAccessory);
Expand Down
4 changes: 2 additions & 2 deletions lib/dimmer_accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DimmerAccessory extends BaseAccessory {

// Set device state in Tuya Web API
const value = state ? 1 : 0;
this.platform.tuyaWebApi.setDeviceState(this.deviceId, 'turnOnOff', value).then(() => {
this.platform.tuyaWebApi.setDeviceState(this.deviceId, 'turnOnOff', { value: value }).then(() => {
this.log.debug('[SET][%s] Characteristic.On: %s %s', this.homebridgeAccessory.displayName, state, value);
this.setCachedState(Characteristic.On, state);
callback();
Expand Down Expand Up @@ -87,7 +87,7 @@ class DimmerAccessory extends BaseAccessory {
// NOTE: For some strange reason, the set value for brightness is in percentage.

// Set device state in Tuya Web API
this.platform.tuyaWebApi.setDeviceState(this.deviceId, 'brightnessSet', percentage).then(() => {
this.platform.tuyaWebApi.setDeviceState(this.deviceId, 'brightnessSet', { value: percentage }).then(() => {
this.log.debug('[SET][%s] Characteristic.Brightness: %s percent', this.homebridgeAccessory.displayName, percentage);
this.setCachedState(Characteristic.Brightness, percentage);
callback();
Expand Down
Loading