Skip to content

Commit 48322a2

Browse files
committed
Merge branch 'feature/advanced_options' into develop_1.7.0
2 parents 177937e + cbf1293 commit 48322a2

8 files changed

Lines changed: 163 additions & 106 deletions

File tree

ADVANCED_OPTIONS.md

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@
22

33
**During the beta version, the options are unstable, may get changed during updates.**
44

5-
The main function of `deviceOverrides` is to convert "non-standard schema" to "standard schema", making device compatible with this plugin.
5+
The main function of `deviceOverrides` is to convert "non-standard schema" to "standard schema", making the device compatible with this plugin.
66

7-
Before config, you may need to:
8-
- Have basic programming skills of JavaScript (Only used in `onGet`/`onSet` handler).
9-
- Understand the meaning of device schema (aka Data Type): [Tuya IoT Development Platform > Cloud Development > Standard Instruction Set > Data Type](https://developer.tuya.com/en/docs/iot/datatypedescription?id=K9i5ql2jo7j1k)
10-
- Find your device product's "Standard Instruction Set" and "Standard Status Set" documentation under [Tuya IoT Development Platform > Cloud Development > Standard Instruction Set](https://developer.tuya.com/en/docs/iot/datatypedescription?id=K9i5ql6waswzq)
11-
- Get your device's detail information from `/path/to/persist/TuyaDeviceList.xxx.json` (Full path can be found from logs).
12-
- Find the "wrong schema", then convert to the "correct schema" from product documentation.
7+
Before configuring, you may need to:
8+
- Have basic programming skills in JavaScript (Only used in `onGet`/`onSet` handlers).
9+
- Understand the concept of device schema (also known as Data Type): [Tuya IoT Development Platform > Cloud Development > Standard Instruction Set > Data Type](https://developer.tuya.com/en/docs/iot/datatypedescription?id=K9i5ql2jo7j1k)
10+
- Find the "Standard Instruction Set" and "Standard Status Set" documentation for your device product under [Tuya IoT Development Platform > Cloud Development > Standard Instruction Set](https://developer.tuya.com/en/docs/iot/datatypedescription?id=K9i5ql6waswzq)
11+
- Obtain detailed information about your device from `/path/to/persist/TuyaDeviceList.xxx.json` (the full path can be found from logs).
12+
- Identify the "incorrect schema" and convert it to the "correct schema" according to the product documentation.
1313

1414

1515
### Configuration
1616

17-
- `options.deviceOverrides` - **optional**: An array of device overriding config objects.
18-
- `options.deviceOverrides[].id` - **required**: Device ID, Product ID, Scene ID, or `global`.
19-
<!--
20-
- `options.deviceOverrides[].accessoryCategory` - **optional**: Accessory Category ID. Overriding this property can change accessory's icon. See: [Homebridge Plugin Documentation > Categories](https://developers.homebridge.io/#/categories)
21-
-->
22-
- `options.deviceOverrides[].category` - **optional**: Device category code. See [SUPPORTED_DEVICES.md](./SUPPORTED_DEVICES.md). Also you can use `hidden` to hide device, product, or scene. **⚠️Overriding this property may leads to unexpected behaviors and exceptions. Please remove accessory cache after change this.**
23-
24-
- `options.deviceOverrides[].schema` - **optional**: An array of schema overriding config objects, used for describing datapoint(DP). When your device have non-standard DP, you need to transform them manually with config.
25-
- `options.deviceOverrides[].schema[].oldCode` - **required**: Original DP code.
26-
- `options.deviceOverrides[].schema[].code` - **required**: New DP code.
27-
- `options.deviceOverrides[].schema[].type` - **optional**: New DP type. One of the `Boolean`, `Integer`, `Enum`, `String`, `Json`, `Raw`.
28-
- `options.deviceOverrides[].schema[].property` - **optional**: New DP property object. For `Integer` type, the object should contains `min`, `max`, `scale`, `step`; For `Enum` type, the object should contains `range`. For detail information, please see `TuyaDeviceSchemaProperty` in [TuyaDevice.ts](./src/device/TuyaDevice.ts).
29-
- `options.deviceOverrides[].schema[].onGet` - **optional**: An one-line JavaScript code convert old value to new value. The function is called with two arguments: `device`, `value`.
30-
- `options.deviceOverrides[].schema[].onSet` - **optional**: An one-line JavaScript code convert new value to old value. The function is called with two arguments: `device`, `value`. return `undefined` means skip send this command.
17+
`options.deviceOverrides` is an **optional** array of device overriding config objects, which is used for converting "non-standard schema" to "standard schema", making the device compatible with this plugin. The structure of each element in the array is described as follows:
18+
19+
- `id` - **required**: Device ID, Product ID, Scene ID, or `global`.
20+
- `category` - **optional**: Device category code. See [SUPPORTED_DEVICES.md](./SUPPORTED_DEVICES.md). Also you can use `hidden` to hide the device, product, or scene. **⚠️Overriding this property may lead to unexpected behaviors and exceptions, so please remove the accessory cache after making changes.**
21+
- `schema` - **optional**: An array of schema overriding config objects, used for describing datapoint (DP). When your device has non-standard DP, you need to transform them manually with configuration. Each element in the schema array is described as follows:
22+
- `code` - **required**: DP code.
23+
- `newCode` - **optional**: New DP code.
24+
- `type` - **optional**: New DP type. One of `Boolean`, `Integer`, `Enum`, `String`, `Json`, or `Raw`.
25+
- `property` - **optional**: New DP property object. For `Integer` type, the object should contain `min`, `max`, `scale`, and `step`. For `Enum` type, the object should contain `range`. For more information, see `TuyaDeviceSchemaProperty` in [TuyaDevice.ts](./src/device/TuyaDevice.ts).
26+
- `onGet` - **optional**: A one-line JavaScript code to convert the old value to the new value. The function is called with two arguments: `device` and `value`.
27+
- `onSet` - **optional**: A one-line JavaScript code to convert the new value to the old value. The function is called with two arguments: `device` and `value`. Returning `undefined` means to skip sending the command.
28+
- `hidden` - **optional**: Whether to hide the schema. Defaults to `false`.
29+
3130

3231
## Examples
3332

@@ -61,6 +60,7 @@ Just the same way as changing category code.
6160
}
6261
```
6362

63+
6464
### Offline as off
6565

6666
If you want to display off status when device is offline:
@@ -71,7 +71,6 @@ If you want to display off status when device is offline:
7171
"deviceOverrides": [{
7272
"id": "{device_id}",
7373
"schema": [{
74-
"oldCode": "{dp_code}",
7574
"code": "{dp_code}",
7675
"onGet": "(device.online && value)"
7776
}]
@@ -80,6 +79,7 @@ If you want to display off status when device is offline:
8079
}
8180
```
8281

82+
8383
### Change DP code
8484

8585
```js
@@ -97,6 +97,7 @@ If you want to display off status when device is offline:
9797
}
9898
```
9999

100+
100101
### Convert from enum DP to boolean DP
101102

102103
A example of convert `open`/`close` into `true`/`false`.
@@ -107,8 +108,7 @@ A example of convert `open`/`close` into `true`/`false`.
107108
"deviceOverrides": [{
108109
"id": "{device_id}",
109110
"schema": [{
110-
"oldCode": "{old_dp_code}",
111-
"code": "{new_dp_code}",
111+
"code": "{dp_code}",
112112
"type": "Boolean",
113113
"onGet": "(value === 'open') ? true : false;",
114114
"onSet": "(value === true) ? 'open' : 'close';"
@@ -118,6 +118,7 @@ A example of convert `open`/`close` into `true`/`false`.
118118
}
119119
```
120120

121+
121122
### Adjust integer DP ranges
122123

123124
Some odd thermostat stores double of the real value to keep the decimal part (0.5°C).
@@ -146,7 +147,6 @@ Here's the example config:
146147
"deviceOverrides": [{
147148
"id": "{device_id}",
148149
"schema": [{
149-
"oldCode": "temp_set",
150150
"code": "temp_set",
151151
"onGet": "(value * 5);",
152152
"onSet": "(value / 5);",
@@ -164,6 +164,7 @@ Here's the example config:
164164

165165
After transform value using `onGet` and `onSet`, and new range in `property`, it should be working now.
166166

167+
167168
### Reverse curtain motor's on/off state
168169

169170
Most curtain motor have "reverse mode" setting in the Tuya App, if you don't have this, you can reverse `percent_control`/`position` and `percent_state` in the plugin config:
@@ -175,12 +176,10 @@ Most curtain motor have "reverse mode" setting in the Tuya App, if you don't hav
175176
"deviceOverrides": [{
176177
"id": "{device_id}",
177178
"schema": [{
178-
"oldCode": "percent_control",
179179
"code": "percent_control",
180180
"onGet": "(100 - value)",
181181
"onSet": "(100 - value)"
182182
}, {
183-
"oldCode": "percent_state",
184183
"code": "percent_state",
185184
"onGet": "(100 - value)",
186185
"onSet": "(100 - value)"
@@ -190,6 +189,7 @@ Most curtain motor have "reverse mode" setting in the Tuya App, if you don't hav
190189
}
191190
```
192191

192+
193193
### Skip send on/off command when touching brightness/speed slider
194194

195195
Some products (dimmer, fan) having issue when sending brightness/speed command with on/off command together. Here's an example of skip on/off command.
@@ -201,7 +201,6 @@ Some products (dimmer, fan) having issue when sending brightness/speed command w
201201
"deviceOverrides": [{
202202
"id": "{device_id}",
203203
"schema": [{
204-
"oldCode": "switch_led",
205204
"code": "switch_led",
206205
"onSet": "(value === device.status.find(status => status.code === 'switch_led').value) ? undefined : value"
207206
}]
@@ -210,6 +209,7 @@ Some products (dimmer, fan) having issue when sending brightness/speed command w
210209
}
211210
```
212211

212+
213213
### Convert Fahrenheit to Celsius
214214

215215
F = 1.8 * C + 32
@@ -223,7 +223,6 @@ C = (F - 32) / 1.8
223223
"deviceOverrides": [{
224224
"id": "{device_id}",
225225
"schema": [{
226-
"oldCode": "temp_current",
227226
"code": "temp_current",
228227
"onGet": "Math.round((value - 32) / 1.8);",
229228
"onSet": "Math.round(1.8 * value + 32);"

0 commit comments

Comments
 (0)