Created TuyaMCU Configurations (markdown)

blakadder 2019-10-25 13:51:15 +02:00
parent aee5db51c5
commit c4ab5e4e9e
1 changed files with 370 additions and 0 deletions

370
TuyaMCU-Configurations.md Normal file

@ -0,0 +1,370 @@
## Identification of FunctionIDs and DpIds
As mentioned, the hardware is controlled by an MCU. The Wi-Fi module sends commands to MCU over serial to control the hardware. Each hardware component has a DpId which can have different functions on each model. See [this list](tuya-protocols) for *possible* combinations.
We need to identify these DpIds:
1. Go to `Configure` -> `Console` option in Tasmota web interface.
2. Use command `weblog 4` to enable verbose logging in web interface.
3. Observe the log. After every 9-10 seconds you should see log messages such as:
```
TYA: Heartbeat
TYA: RX Packet: "55aa0107000501010001000f"
TYA: FnId=0 is set for dpId=1
TYA: RX Packet: "55aa01070005020100010010"
TYA: FnId=0 is set for dpId=2
TYA: RX Packet: "55aa01070005030100010011"
TYA: FnId=0 is set for dpId=3
TYA: RX Packet: "55aa01070005040100010012"
TYA: FnId=0 is set for dpId=4
TYA: RX Packet: "55aa0107000807020004000000001c"
TYA: FnId=0 is set for dpId=7
TYA: RX Packet: "55aa0107000808020004000000001d"
TYA: FnId=0 is set for dpId=8
TYA: RX Packet: "55aa0107000809020004000000001e"
TYA: FnId=0 is set for dpId=9
TYA: RX Packet: "55aa010700080a020004000000001f"
TYA: FnId=0 is set for dpId=0
TYA: RX Packet: "55aa0107000865020004000000007a"
TYA: FnId=0 is set for dpId=101
TYA: RX Packet: "55aa0107000866020004000000007b"
TYA: FnId=0 is set for dpId=102
TYA: RX Packet: "55aa0107000867020004000000007c"
TYA: FnId=0 is set for dpId=103
TYA: RX Packet: "55aa0107000868020004000009870d"
TYA: FnId=0 is set for dpId=104
```
4. The function ids are printed as `TYA: FnId=0 is set for dpId=XXX` We will use these `XXX` ids in the guide ahead
### Setting up a Dimmer
We need to configure four functions of a dimmer:
1. Dimming DpId
2. Dimming Range
3. Power metering if supported.
4. Dimming less than 10%
#### Dimming DpId
The dimmer FunctionId is `21`. On a dimmer DpId generally is `2` or `3`. Try both.
1. Go to the Tasmota Console and type `TuyaMCU 21,2` and wait for it to reboot.
2. Enter `Backlog Dimmer 10; Dimmer 100` in the Console.
- If your bulb responds to `Dimmer` commands, you have successfully configured the dimmer FunctionId. Make note of it.
- If not try id `3` and if even `3` doesn't work keep trying Ids from all unknown Ids from the log until one works.
#### Dimming Range
Once you have figured out the dimming functionId, we need to find the maximum dimming range. Once the dimming Id is set, the logs will continue
```
TYA: Heartbeat
TYA: RX Packet: "55aa03070005010100010011"
TYA: RX Relay-1 --> MCU State: Off Current State:Off
TYA: RX Packet: "55aa03070008020200040000000720"
TYA: FnId=21 is set for dpId=2
TYA: RX Dim State=7
```
Now using the hardware buttons increase the dimmer to its maximum and observe the log. The `Dim State=XXX` shows the current dimmer level reported by MCU. Once the dimmer is at max, note this number. Again using hardware buttons decrease dimmer to minimum and note the number for minimum.
Now we need to tell Tasmota to use maximum and minimum values. This controlled by [DimmerRange](Commands#DimmerRange) command. We can set it using `DimmerRange <Min>,<Max>` where `<Min>` is the minimum dimmer state and `<Max>` maximum dimmer state reported in logs.
Once set, try `dimmer 100` in the Console and check if the brightness of bulb is same is the same as when the maximum was set using hardware buttons.
#### Power metering
<a id="power-metering"></a>
Some Tuya MCU devices support Power measurement support over serial. For this its better to use an bulb with known wattage rating.
Observe the logs in the Console
```
TYA: RX Packet: "55aa03070005010100010011"
TYA: FnId=11 is set for dpId=1
TYA: RX Device-1 --> MCU State: Off Current State:Off
TYA: RX Packet: "55aa03070008020200040000000720"
TYA: FnId=21 is set for dpId=2
TYA: RX Dim State=7
TYA: RX Packet: "55aa0307000803020004000000001a"
TYA: FnId=0 is set for dpId=3
TYA: RX Packet: "55aa0307000804020004000000251b"
TYA: FnId=0 is set for dpId=4
TYA: RX Packet: "55aa0307000805020004000000591c"
TYA: FnId=0 is set for dpId=5
TYA: RX Packet: "55aa03070008060200040000098fb5"
TYA: FnId=0 is set for dpId=6
```
In the `RX Packet` we are interested in the 3 digits before last 2 digits. For example:
`98f` in `"55aa03070008060200040000098fb5"`
1. Make sure the bulb if off.
2. Find out the voltage standard of your country (generally 220, 240, 120v) from this [table](https://www.worldstandards.eu/electricity/plug-voltage-by-country/).
3. Multiply that number by 10 (2400) and Convert that number (2400) to Hex using any [hex converter](https://www.binaryhexconverter.com/decimal-to-hex-converter) (2400 = 0x960).
4. Now look for the number nearest to `960` in the logs. In our case it is `98f`. So we expect that's the voltage which is `ID=6` in our example.
5. Set voltage functionId `33` by entering `TuyaMCU 33,6`.
6. Now set dimmer to 100% using the `dimmer 100` command and observe the logs.
7. Now we need the power rating of your bulb example `9W`. Multiply by 10 (90) and convert to hex which gives us 0x5A. Check which unknown ID is close to `5A`. I this example it is `59` for `ID=5`. This is the Id of `Active Power` function.
8. Set the active power functionId `31` by entering `TuyaMCU 31,5`.
9. Once Power and Voltage are set you should see something such as this in the logs:
```
TYA: RX Packet: "55aa03070005010100010011"
TYA: FnId=11 is set for dpId=1
TYA: RX Device-1 --> MCU State: Off Current State:Off
TYA: RX Packet: "55aa03070008020200040000000720"
TYA: FnId=21 is set for dpId=2
TYA: RX Dim State=7
TYA: RX Packet: "55aa0307000803020004000000001a"
TYA: FnId=0 is set for dpId=3
TYA: RX Packet: "55aa0307000804020004000000251b"
TYA: FnId=0 is set for dpId=4
TYA: RX Packet: "55aa0307000805020004000000591c"
TYA: FnId=31 is set for dpId=5
TYA: Rx ID=5 Active_Power=9
TYA: RX Packet: "55aa03070008060200040000098fb5"
TYA: FnId=33 is set for dpId=6
TYA: Rx ID=6 Voltage=244.7
```
10. To get the Id for the current, calculate Current = Power / Voltage ( 9 / 244.7 ) = 0.0367. Multiply this by 1000 = 36.77. Now convert 36 to hex which is 0x24. This is closest to `25` which is Id 4.
11. Set the current FunctionId `32` using command `TuyaMCU 32,4`.
12. Observe the logs should start showing
```
TYA: RX Packet: "55aa03070005010100010011"
TYA: FnId=11 is set for dpId=1
TYA: RX Device-1 --> MCU State: Off Current State:Off
TYA: RX Packet: "55aa03070008020200040000000720"
TYA: FnId=21 is set for dpId=2
TYA: RX Dim State=7
TYA: RX Packet: "55aa0307000803020004000000001a"
TYA: FnId=0 is set for dpId=3
TYA: RX Packet: "55aa0307000804020004000000251b"
TYA: FnId=32 is set for dpId=4
TYA: Rx ID=4 Current=312
TYA: RX Packet: "55aa0307000805020004000000591c"
TYA: FnId=31 is set for dpId=5
TYA: Rx ID=5 Active_Power=9
TYA: RX Packet: "55aa03070008060200040000098fb5"
TYA: FnId=33 is set for dpId=6
TYA: Rx ID=6 Voltage=2447
```
13. Power and current should change on dimming high / low. The Tasmota web UI should show power values now.
### Setting up Switches
For switches we need to
1. Configure the number of relays.
2. Configure Power metering.
#### Configure number of relays
By default, the TuyaMCU module expects a 1 gang switch. There is currenty no way to detect the number of relays present in an MCU based switch. We need to tell the number of relays to Tasmota using FunctionIDs 12 to 18 for Relay2 to Relay4.
* For a 4 gang switch set `TuyaMCU 12,2`, `TuyaMCU 13,3` and `TuyaMCU 14,4` if the DpIds for Relays 2-4 are `2`,`3`,`4`.
> You can configure all at once by using `Backlog TuyaMCU 12,2; TuyaMCU 13,3; TuyaMCU 14,4`
#### Configure power metering
Power metering configuration is same as for [dimmers](#power-metering).
### Setting up a Curtain Motor
The Zemismart WiFi curtain motor uses a Tuya TYWE1S inside the little white dongle as a radio modem.
`U1TX` is connected to "USB D+", `U1RX` is connected to "USB D-", and there is a blue LED in the dongle connected to "USB3 R-" controlled by the MCU. To flash Tasmota, we need `U0RX`, `U0TX`, and `GPIO0`. None of which are broken out on the PCB, so soldering or Tuya-Convert are necessary.
The stock Tuya App communicates with the PIC Micro inside the motor housing at 9600 8N1.
* `dpId 101` is the "partial open/partial close" command with a 4 byte field of 0-100%.
* `dpId 102` is a "fully open/fully close" command with a 1-byte Boolean field.
* `dpId 103` is unknown.
#### Debugging
```
55 aa 00 06 "deliver dp" 0005 "len=5" 66 04 00 01 <00=close100%,01=open0%> <chksum> is the fully open/close command
07 "report dp" 0005 (len) 66 04 00 01 <00 or 01> <chksum> is the reply.
55 aa 00 06 "deliver dp" 0008 (len=8) 65 02 00 04 <value.32 <chksum> is the move partial command
55 aa 00 07 "report dp" 0008 (len=8) 65 02 00 04 <value.32> <chksum> is the reply.
```
There may first be a reply of 65 02 00 04 <oldvalue.32> <chksum> before the motor engages
#### Tasmota
1. `module 54` # TuyaMCU (will reboot)
2. `backlog gpio1 0; gpio3 0; gpio15 107; gpio13 108` # change GPIO assignments. The dongle uses gpio15 for U1TX and gpio13 for U1RX (will reboot)
3. `tuyamcu 21,101` # declare curtain as a dimmer (will reboot)
4. \# no idea what a good tuyamcu xx,102 is
5. \# no idea what a good tuyamcu xx,103 is
6. `setoption 69 0` # allow dimmer below 25% or 10%. (won't reboot)
With these settings, the `dimmer` command can adjust the curtain from 100% (closed) to 1% (almost fully open, 0% is the motor limit, but 1% is the Tasmota limit?)
#### Things that did not work
```
tuyamcu 1,102 # make 0x66 a button
tuyamcu 1,103 # make 0x67 a button
```
Having 0x66 declared a button caused the motor to oscillate - open part way and then close again. Like Tasmota was sending the "fully open" command and then immediately cancelling it with a "partial close" command.
```
tuyamcu 11,102 # make 0x66 a relay
tuyamcu 11,103 # make 0x67 a relay
```
Does not appear to have any impact on the curtain.
## dpId functions in different devices
- ID: Identification number associated with the function.
- Function PointUsed to describe the product function.
- Identifier: Function codename. Can only be letters, numbers and underscores
- Data type
- Issue and report: command data can be sent and status data can be reported back to the Wi-Fi module
- Report only: supports only status reporting, no control options
- Function Typevalues used for command data
- Boolean (bool): non-true or false binary variable, such as: switch function, on / off
- Value (value): suitable for linear adjustment of the type of data, such as: temperature regulation, temperature range 20-40 ℃
- Enum (enum): custom finite set value, such as: working levels, low / mid / high
- Fault (fault): dedicated to reporting and statistical failure of the function points. Support multi-fault, the data is reported only
- Integerinteger: transmitted as integer
- Transparent (raw): data in binary
### Switches or plugs/power strips
```
| DP ID | Identifier | Data type | Function type | Properties |
|-------|-------------|--------------------|---------------|----------------------------------------------|
| 1 | switch_1 | Control and report | Boolean | |
| 2 | switch_2 | Control and report | Boolean | |
| 3 | switch_3 | Control and report | Boolean | |
| 4 | switch_4 | Control and report | Boolean | |
| 5 | switch_5 | Control and report | Boolean | |
| 9 | countdown_1 | Control and report | Integer | undefined0-86400, undefined1, Scale0, Unit:s |
| 10 | countdown_2 | Control and report | Integer | undefined0-86400, undefined1, Scale0, Unit:s |
| 11 | countdown_3 | Control and report | Integer | undefined0-86400, undefined1, Scale0, Unit:s |
| 12 | countdown_4 | Control and report | Integer | undefined0-86400, undefined1, Scale0, Unit:s |
| 13 | countdown_5 | Control and report | Integer | undefined0-86400, undefined1, Scale0, Unit:s |
```
### Aromatherapy machine (Oil Diffuser)
```
| DP ID | Function points | Identifier | Data type | Function type | Properties
| 1 | Switch | Power | Issue and report | Boolean | |
| 6 | Amount of fog | fog | Issue and report | Enum | Enumerated values:small, large|
| 11 | Light | Light | Issue and report | Boolean | |
| 12 | Fault alarm | fault | Only report | Fault | Barrier values:1|
| 13 | Countdown | countdown | Issue and report | Enum | Enumerated values: 0, 1, 2, 3|
| 14 | Countdown remaining time | countdown_left | Only report | Integer | Values range: 0-360, Pitch1, Scale0, Unit:min|
| 101 | Light mode | work_mode | Issue and report | Enum | Enumerated values: white, colour, scene, scene1, scene2, scene3, scene4 |
| 102 | Color value | colour_data | Issue and report | Char type | *see below |
| 103 | Light mode | lightmode | Issue and report | Enum | Enumerated values: 1, 2, 3|
| 104 | Brightness setting | setlight | Issue and report | Integer | Values range: 0-255, Pitch1, Scale0, Unit:\%|
```
> `colour_data` format of the lights is a string of 14 characters, for example, 00112233334455, where 00 indicates R, 11 indicates G, 22 indicates B, 3333 indicates the hue, 44 indicates the saturation, and 55 indicates the value. The initial value is saved by default. If you do not want to adjust the light, set the data to the maximum value 100% (0x64). The last four characters have fixed values.
### Curtain motor
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|-----------------|---------------|------------------|---------------|-----------------------------------------------|
| 1 | Percentage | percent_state | Only report | Integer | Values range:0-100, Pitch1, Scale0, Unit:% |
| 2 | Motor Direction | control_back | Issue and report | Boolean | |
| 3 | Auto Power | auto_power | Issue and report | Boolean | |
| 4 | Left time | countdown | Issue and report | Enum | Enumerated values:cancel, 1, 2, 3, 4 |
| 5 | Total Time | time_total | Only report | Integer | Values range:0-120000, Pitch1, Scale0, Unit:m |
```
> [Complete document on protocols](https://github.com/arendst/Sonoff-Tasmota/files/3658412/protocol_CurtainM_20190926.pdf)
### Power monitoring plug
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|------------------------|-----------------|--------------------|---------------|-----------------------------------------------|
| 1 | switch_1 | switch_1 | Control and report | Boolean | |
| 9 | countdown_1 | countdown_1 | Control and report | Integer | undefined0-86400, undefined1, Scale0, Unit:s |
| 17 | statistics Function | add_ele | Control and report | Integer | undefined0-50000, undefined100, Scale3, Unit: |
| 18 | current | cur_current | Data report | Integer | undefined0-30000, undefined1, Scale0, Unit:mA |
| 19 | power | cur_power | Data report | Integer | undefined0-50000, undefined1, Scale1, Unit:W |
| 20 | voltage | cur_voltage | Data report | Integer | undefined0-5000, undefined1, Scale1, Unit:V |
| 21 | test flag | test_bit | Data report | Integer | undefined0-5, undefined1, Scale0, Unit: |
| 22 | voltage coefficient | voltage_coe | Data report | Integer | undefined0-1000000, undefined1, Scale0, Unit: |
| 23 | current coefficient | electric_coe | Data report | Integer | undefined0-1000000, undefined1, Scale0, Unit: |
| 24 | power coefficient | power_coe | Data report | Integer | undefined0-1000000, undefined1, Scale0, Unit: |
| 25 | statistics coefficient | electricity_coe | Data report | Integer | undefined0-1000000, undefined1, Scale0, Unit: |
| 26 | warning | fault | Data report | Fault | Barrier values:ov_cr |
```
### Dehumidifier
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|-----------------|-------------|------------------|---------------|----------------------------------------------------------|
| 1 | Switch | Switch | Issue and report | Boolean | |
| 2 | PM2.5 | PM25 | Only report | Integer | Values range:0-999, Pitch1, Scale0, Unit: |
| 3 | Work mode | Mode | Issue and report | Enum | Enumerated values:Manual, Auto, Sleep |
| 4 | Wind speed | Speed | Issue and report | Enum | Enumerated values:speed1, speed2, speed3, speed4, speed5 |
| 5 | Filter usage | Filter | Only report | Integer | Values range:0-100, Pitch1, Scale0, Unit:% |
| 6 | Fresh | Anion | Issue and report | Boolean | |
| 7 | Child lock | Lock | Issue and report | Boolean | |
| 9 | UV light | UV | Issue and report | Boolean | |
| 11 | Filter reset | FilterReset | Issue and report | Boolean | |
| 12 | indoor temp | Temp | Only report | Integer | Values range:-20-50, Pitch1, Scale0, Unit:℃ |
| 13 | Indoor humidity | Humidity | Only report | Integer | Values range:0-100, Pitch1, Scale0, Unit:% |
```
### Lighting
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|-----------------|---------------|--------------------|---------------|----------------------------------------------------------------------------|
| 1 | Switch | led_switch | Control and report | Boolean | |
| 2 | Mode | work_mode | Control and report | Enum | Enumerated values:white, colour, scene, scene_1, scene_2, scene_3, scene_4 |
| 3 | Bright | bright_value | Control and report | Integer | undefined25-255, undefined1, Scale0, Unit: |
| 5 | Colour mode | colour_data | Control and report | Char type | |
| 6 | Scene | scene_data | Control and report | Char type | |
| 7 | Scene1 | flash_scene_1 | Control and report | Char type | |
| 8 | Scene2 | flash_scene_2 | Control and report | Char type | |
| 9 | Scene3 | flash_scene_3 | Control and report | Char type | |
| 10 | Scene4 | flash_scene_4 | Control and report | Char type | |
```
### Air purifier
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|-----------------|-------------|------------------|---------------|----------------------------------------------------------|
| 1 | Switch | Switch | Issue and report | Boolean | |
| 2 | PM2.5 | PM25 | Only report | Integer | Values range:0-999, Pitch1, Scale0, Unit: |
| 3 | Work mode | Mode | Issue and report | Enum | Enumerated values:Manual, Auto, Sleep |
| 4 | Wind speed | Speed | Issue and report | Enum | Enumerated values:speed1, speed2, speed3, speed4, speed5 |
| 5 | Filter usage | Filter | Only report | Integer | Values range:0-100, Pitch1, Scale0, Unit:% |
| 6 | Fresh | Anion | Issue and report | Boolean | |
| 7 | Child lock | Lock | Issue and report | Boolean | |
| 9 | UV light | UV | Issue and report | Boolean | |
| 11 | Filter reset | FilterReset | Issue and report | Boolean | |
| 12 | indoor temp | Temp | Only report | Integer | Values range:-20-50, Pitch1, Scale0, Unit:℃ |
| 13 | Indoor humidity | Humidity | Only report | Integer | Values range:0-100, Pitch1, Scale0, Unit:% |
```
### Heater
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|---------------------|-------------|------------------|---------------|--------------------------------------------|
| 1 | Switch | Power | Issue and report | Boolean | |
| 2 | Target temperature | TempSet | Issue and report | Integer | Values range:0-37, Pitch1, Scale0, Unit:℃ |
| 3 | Current Temperature | TempCurrent | Only report | Integer | Values range:-9-99, Pitch1, Scale0, Unit:℃ |
| 4 | Mode | Mode | Issue and report | Enum | Enumerated values:m, p |
| 5 | Fault alarm | Fault | Only report | Fault | Barrier values:1, 2, 3 |
| 6 | Gear position | gear | Issue and report | Enum | Enumerated values:low, mid, high, off |
| 7 | Conservation | eco_mode | Issue and report | Boolean | |
```
### Smart fan
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|----------------------|----------------|------------------|---------------|-------------------------------------------|
| 1 | Switch | switch | Issue and report | Boolean | |
| 2 | Wind Speed Level | fan_speed | Issue and report | Enum | Enumerated values:1, 2, 3, 4 |
| 3 | Left-and-Right Swing | fan_horizontal | Issue and report | Enum | Enumerated values:on, off |
| 4 | Up-and-Down Swing | fan_vertical | Issue and report | Enum | Enumerated values:on, off |
| 5 | Fault Alarm | fault | Only report | Fault | Barrier values:1, 2 |
| 6 | Anion | anion | Issue and report | Boolean | |
| 7 | Humidify | humidifier | Issue and report | Boolean | |
| 8 | Oxygen | oxygan | Issue and report | Boolean | |
| 9 | Child Lock | lock | Issue and report | Boolean | |
| 10 | Cool | fan_cool | Issue and report | Boolean | |
| 11 | Set Temperate | temp | Issue and report | Integer | Values range:0-50, Pitch1, Scale0, Unit:℃ |
| 12 | Current Temperature | temp_current | Only report | Integer | Values range:0-50, Pitch1, Scale0, Unit:℃ |
```
### Kettle
```
| DP ID | Function points | Identifier | Data type | Function type | Properties |
|-------|------------------------------------------------------------|----------------------|------------------|---------------|---------------------------------------------------------------------|
| 1 | Working switch | start | Issue and report | Boolean | |
| 2 | Heat to target temperature shortcut (°C) | temp_setting_quick_c | Issue and report | Enum | Enumerated values:50, 65, 85, 90, 100 |
| 3 | Heat to target temperature shortcut (°F) | temp_setting_quick_f | Issue and report | Enum | Enumerated values:122, 149, 185, 194, 212 |
| 4 | Cool to the target temperature shortcut after boiling (°C) | temp_boiling_quick_c | Issue and report | Enum | Enumerated values:50, 65, 85, 90, 100 |
| 5 | Cool to the target temperature shortcut after boiling (°F) | temp_boiling_quick_f | Issue and report | Enum | Enumerated values:122, 149, 185, 194, 212 |
| 6 | Temperature scale switching | temp_unit_convert | Issue and report | Enum | Enumerated values:c, f |
| 7 | Insulation switch | switch_keep_warm | Issue and report | Boolean | |
| 8 | Holding time setting | keep_warm_setting | Issue and report | Integer | Values range:0-360, Pitch1, Scale0, Unit:min |
| 9 | Mode | work_type | Issue and report | Enum | Enumerated values: setting_quick, boiling_quick, temp_setting, temp_ |
```