Updated TuyaMCU (markdown)

Michael Ingraham 2019-09-20 17:21:23 -04:00
parent 05f666ebd5
commit ea255d1357
1 changed files with 113 additions and 147 deletions

@ -5,17 +5,13 @@ In these devices Tuya Wifi module takes care of Wifi and software features while
## TuyaMCU Module (former Tuya Serial Dimmer) ## TuyaMCU Module (former Tuya Serial Dimmer)
TuyaMCU module does the job of mapping devices behind MCU to Tasmota devices. TuyaMCU module introduces a new command `TuyaMCU` which maps the FunctionIDs to DpIds. Module supports maximum of 16 configured FunctionIDs. The TuyaMCU module is for devices employing an MCU to perform the device actions and does the job of mapping those actions to Tasmota commands. The TuyaMCU module introduces a new command `TuyaMCU` which maps the FunctionIDs to DpIds. The module supports maximum of 16 configured FunctionIDs.
### DpId ### DpId
All the devices (relays, dimmers, switches) controlled by MCU are identified by a DpId. Whenever a command is sent to MCU, this DpId dictates which relay or dimmer needs to be changed and same is used when the status is received from MCU. There is no way the Wi-Fi module firmware can know the function of each DpId, so just like GPIO pin configuration for TuyaMCU devices we need to map DpId with its functions.
All the devices (relays, dimmers, switches) controlled by MCU are identified by a DpId. Whenever a command is sent to MCU, this DpId dictates which relay or dimmer needs to be changed and same is used when the status is received from MCU. There is no way the Wifi module firmware can know the function of each DpId, so just like GPIO pin configuration for TuyaMCU devices we need to map DpId with its functions.
### FunctionIDs ### FunctionIDs
The FunctionID defines what type of component is located at DpId. These functions are similar to default Tasmota components (Relays, LEDs, Dimmer like PWM, etc). Currently the TuyaMCU module supports the following FunctionIDs:
The FunctionID defines what type of Device is located at DpId. These functions are similar to default Tasmota GPIOs (Relays, LEDs, Dimmer like PWM, etc). Currently TuyaMCU module supports the following FunctionIDs:
Function | FunctionId Function | FunctionId
-|- -|-
@ -28,90 +24,80 @@ Voltage (in deci Volt) | 33
Relay Inverted1 to Relay Inverted8 | 41 to 48 Relay Inverted1 to Relay Inverted8 | 41 to 48
## TuyaMCU command ## TuyaMCU command
The TuyaMCU command accepts two comma separated parameters; FunctionID and DpId. For example:
`TuyaMCU <fnId>,<dpId>`
TuyaMCU command takes 1 param with FunctionID and DpId comma separated ie where `<fnId>` is FunctionID and `<dpId>` is the DpId to map the function to.
`TuyaMCU <fnId>,<dpId>`
where `fnId` is FunctionID and `dpId` is dpId to map to.
If any existing entry with same `fnId` or `dpId` is already present, it will be updated to the new values. If any existing entry with same `fnId` or `dpId` is already present, it will be updated to the new values.
If any of `fnId` or `dpId` is `0` the entry is removed If any of `fnId` or `dpId` is `0` the entry is removed
If no param is provided then `TuyaMCU` command just prints the current mapping values. If no parameters are provided then `TuyaMCU` command just prints the current mapping values.
example: Example:
`TuyaMCU 11,1`
`TuyaMCU 11,1`
This command maps Relay1 (FunctionID 11) to DpId 1. This command maps Relay1 (FunctionID 11) to DpId 1.
Output of TuyaMCU is the current mapping of fnIds and DpIds. Output of TuyaMCU is the current mapping of fnIds and DpIds.
## Identification of FunctionIDs and DpIds ## Identification of FunctionIDs and DpIds
As mentioned earlier, the hardware is controlled by MCU and Wifi module sends commands to MCU over serial to control the hardware. Each hardware has a DpId which can be different for different models even for same manufacturer. We need to identify these DpIds. As mentioned earlier, 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 be different for different models even for same manufacturer. We need to identify these DpIds.
To do that, To do that:
1. You need to go to `Configure` -> `Console` option in Tasmota web interface. 1. Go to `Configure` -> `Console` option in Tasmota web interface.
2. Type command `weblog 4` to enable verbose logging in web interface. 2. Type command `weblog 4` to enable verbose logging in web interface.
3. Observe that after every 9-10 seconds you will see things like 3. Observe the log. After every 9-10 seconds you should see log messages such as:
```
``` TYA: Heartbeat
TYA: Heartbeat TYA: RX Packet: "55aa0107000501010001000f"
TYA: RX Packet: "55aa0107000501010001000f" TYA: FnId=0 is set for dpId=1
TYA: FnId=0 is set for dpId=1 TYA: RX Packet: "55aa01070005020100010010"
TYA: RX Packet: "55aa01070005020100010010" TYA: FnId=0 is set for dpId=2
TYA: FnId=0 is set for dpId=2 TYA: RX Packet: "55aa01070005030100010011"
TYA: RX Packet: "55aa01070005030100010011" TYA: FnId=0 is set for dpId=3
TYA: FnId=0 is set for dpId=3 TYA: RX Packet: "55aa01070005040100010012"
TYA: RX Packet: "55aa01070005040100010012" TYA: FnId=0 is set for dpId=4
TYA: FnId=0 is set for dpId=4 TYA: RX Packet: "55aa0107000807020004000000001c"
TYA: RX Packet: "55aa0107000807020004000000001c" TYA: FnId=0 is set for dpId=7
TYA: FnId=0 is set for dpId=7 TYA: RX Packet: "55aa0107000808020004000000001d"
TYA: RX Packet: "55aa0107000808020004000000001d" TYA: FnId=0 is set for dpId=8
TYA: FnId=0 is set for dpId=8 TYA: RX Packet: "55aa0107000809020004000000001e"
TYA: RX Packet: "55aa0107000809020004000000001e" TYA: FnId=0 is set for dpId=9
TYA: FnId=0 is set for dpId=9 TYA: RX Packet: "55aa010700080a020004000000001f"
TYA: RX Packet: "55aa010700080a020004000000001f" TYA: FnId=0 is set for dpId=0
TYA: FnId=0 is set for dpId=0 TYA: RX Packet: "55aa0107000865020004000000007a"
TYA: RX Packet: "55aa0107000865020004000000007a" TYA: FnId=0 is set for dpId=101
TYA: FnId=0 is set for dpId=101 TYA: RX Packet: "55aa0107000866020004000000007b"
TYA: RX Packet: "55aa0107000866020004000000007b" TYA: FnId=0 is set for dpId=102
TYA: FnId=0 is set for dpId=102 TYA: RX Packet: "55aa0107000867020004000000007c"
TYA: RX Packet: "55aa0107000867020004000000007c" TYA: FnId=0 is set for dpId=103
TYA: FnId=0 is set for dpId=103 TYA: RX Packet: "55aa0107000868020004000009870d"
TYA: RX Packet: "55aa0107000868020004000009870d" TYA: FnId=0 is set for dpId=104
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 guide ahead
4. The function ids are printed as `TYA: FnId=0 is set for dpId=XXX` We will use these `XXX` ids in guide ahead
### Setting up Dimmer ### Setting up Dimmer
We need to configure four functions of a dimmer:
We need to configure 3 functions of dimmer
1. Dimming DpId 1. Dimming DpId
2. Dimming Range 2. Dimming Range
3. Power metering if supported. 3. Power metering if supported.
4. Dimming less than 10% 4. Dimming less than 10%
#### Dimming DP ID #### Dimming DpId
The dimmer FunctionId is `21`. The DpId generally is `2` or `3`. The easiest is to try both.
Dimmer FunctionId is `21`. DpId generally is `2` or `3`. The easiest is to try both 1. Go to the Tasmota web Console and type `TuyaMCU 21,2` and wait for it to reboot.
2. Enter `Backlog Dimmer 10; Dimmer 100` in the Console
1. Goto console and type `TuyaMCU 21,2` and wait for it to reboot.
2. enter command `dimmer 10` and `dimmer 100`
If your bulb responds to `dimmer` commands you have successfully configured dimmer function id. Note it for future.
If not try id `3` and if even `3` doesn't work keep trying ids from all unknown ids from log till one works.
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 #### 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
Once you have figured out the dimming function id, we need to find the maximum dimming range. Once dimming id is set, the logs will keep showing like
``` ```
TYA: Heartbeat TYA: Heartbeat
TYA: RX Packet: "55aa03070005010100010011" TYA: RX Packet: "55aa03070005010100010011"
@ -121,18 +107,14 @@ TYA: FnId=21 is set for dpId=2
TYA: RX Dim State=7 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, use this number. Now we need to tell Tasmota to use this as maximum. This controlled by [SetOption43](https://github.com/arendst/Sonoff-Tasmota/wiki/Commands#Setoption43) 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, use this number. Now we need to tell Tasmota to use this as maximum. This controlled by [SetOption43](Commands#Setoption43). We can set it using `SetOption43 XXX` where `XXX` is the maximum dimmer state reported in logs.
We can set it using `SetOption43 XXX` where XXX is the maximum dimmer state reported in logs.
Once set try `dimmer 100` in the logs and check if the brightness of bulb is same is maximum set using hardware buttons.
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 #### Power metering
Some Tuya MCU devices support Power measurement support over serial. For this its better to use an bulb with known wattage rating.
Some Tuya MCU devices support Power measurement support over serial. For this its better to use a bulb with known rating. Observe the logs in the Console
Observe in console, the logs would show like
``` ```
TYA: RX Packet: "55aa03070005010100010011" TYA: RX Packet: "55aa03070005010100010011"
TYA: FnId=11 is set for dpId=1 TYA: FnId=11 is set for dpId=1
@ -150,99 +132,83 @@ TYA: RX Packet: "55aa03070008060200040000098fb5"
TYA: FnId=0 is set for dpId=6 TYA: FnId=0 is set for dpId=6
``` ```
In here we are interested in the 3 digits before last 2 digits for example In the `RX Packet` we are interested in the 3 digits before last 2 digits. For example:
`98f` in `"55aa03070008060200040000098fb5"` `98f` in `"55aa03070008060200040000098fb5"`
1. Make sure the bulb if off at the moment. 1. Make sure the bulb if off.
2. Find out the voltage standard of your country (generally 220, 240, 110v) from [table here](https://www.worldstandards.eu/electricity/plug-voltage-by-country/) For example we have 240 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 convertor](https://www.binaryhexconverter.com/decimal-to-hex-converter) which gives you 0x960. 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 see the number nearest to `960` in the logs. In our case it is `98f`. So we expect thats the voltage which is `ID=6` in our example. 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 function Id 33 by entering command `TuyaMCU 33,6` 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.
6. Now set dimmer to 100% by command `dimmer 100` and observe 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.
7. Now we need the power rating of your bulb example `9W`. Multiply by 10 (90) and convert to hex which gives us `5A`. Check which unknown ID is close to `5A` in our case 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`.
8. Set the active power function id 31 using command `TuyaMCU 31,5` 9. Once Power and Voltage are set you should see something such as this in the logs:
```
9. Once Power and Voltage are set the logs will 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: "55aa03070005010100010011" TYA: RX Packet: "55aa03070008020200040000000720"
TYA: FnId=11 is set for dpId=1 TYA: FnId=21 is set for dpId=2
TYA: RX Device-1 --> MCU State: Off Current State:Off TYA: RX Dim State=7
TYA: RX Packet: "55aa03070008020200040000000720" TYA: RX Packet: "55aa0307000803020004000000001a"
TYA: FnId=21 is set for dpId=2 TYA: FnId=0 is set for dpId=3
TYA: RX Dim State=7 TYA: RX Packet: "55aa0307000804020004000000251b"
TYA: RX Packet: "55aa0307000803020004000000001a" TYA: FnId=0 is set for dpId=4
TYA: FnId=0 is set for dpId=3 TYA: RX Packet: "55aa0307000805020004000000591c"
TYA: RX Packet: "55aa0307000804020004000000251b" TYA: FnId=31 is set for dpId=5
TYA: FnId=0 is set for dpId=4 TYA: Rx ID=5 Active_Power=9
TYA: RX Packet: "55aa0307000805020004000000591c" TYA: RX Packet: "55aa03070008060200040000098fb5"
TYA: FnId=31 is set for dpId=5 TYA: FnId=33 is set for dpId=6
TYA: Rx ID=5 Active_Power=9 TYA: Rx ID=6 Voltage=244.7
TYA: RX Packet: "55aa03070008060200040000098fb5" ```
TYA: FnId=33 is set for dpId=6 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.
TYA: Rx ID=6 Voltage=244.7 11. Set the current FunctionId `32` using command `TuyaMCU 32,4`.
```
10. To get current Id, 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 our current id 4.
11. Set the current Function Id 32 using command `TuyaMCU 32,4`.
12. Observe the logs should start showing 12. Observe the logs should start showing
```
``` TYA: RX Packet: "55aa03070005010100010011"
TYA: RX Packet: "55aa03070005010100010011" TYA: FnId=11 is set for dpId=1
TYA: FnId=11 is set for dpId=1 TYA: RX Device-1 --> MCU State: Off Current State:Off
TYA: RX Device-1 --> MCU State: Off Current State:Off TYA: RX Packet: "55aa03070008020200040000000720"
TYA: RX Packet: "55aa03070008020200040000000720" TYA: FnId=21 is set for dpId=2
TYA: FnId=21 is set for dpId=2 TYA: RX Dim State=7
TYA: RX Dim State=7 TYA: RX Packet: "55aa0307000803020004000000001a"
TYA: RX Packet: "55aa0307000803020004000000001a" TYA: FnId=0 is set for dpId=3
TYA: FnId=0 is set for dpId=3 TYA: RX Packet: "55aa0307000804020004000000251b"
TYA: RX Packet: "55aa0307000804020004000000251b" TYA: FnId=32 is set for dpId=4
TYA: FnId=32 is set for dpId=4 TYA: Rx ID=4 Current=312
TYA: Rx ID=4 Current=312 TYA: RX Packet: "55aa0307000805020004000000591c"
TYA: RX Packet: "55aa0307000805020004000000591c" TYA: FnId=31 is set for dpId=5
TYA: FnId=31 is set for dpId=5 TYA: Rx ID=5 Active_Power=9
TYA: Rx ID=5 Active_Power=9 TYA: RX Packet: "55aa03070008060200040000098fb5"
TYA: RX Packet: "55aa03070008060200040000098fb5" TYA: FnId=33 is set for dpId=6
TYA: FnId=33 is set for dpId=6 TYA: Rx ID=6 Voltage=2447
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.
13. Power and current should change on dimming high / low. Tasmota web gui should show power values now.
#### Dimming less than 10% #### Dimming less than 10%
By default Tasmota blocks dimming less than 10% for dimmers. Some dimmers can handle less than 10% very well. By default Tasmota blocks dimming less than 10% for dimmers. Some dimmers can handle less than 10% very well.
1. Turn the dimmer to lowest using hardware button. 1. Turn the dimmer to lowest using hardware button.
2. Check the `Dim state=` in logs to see what is the minimum. 2. Check the `Dim state=` in logs to see what is the minimum.
3. If `Dim state` is less than 10% of maximum range that was set you need to unset [SetOption69](https://github.com/arendst/Sonoff-Tasmota/wiki/Commands#Setoption69) by `SetOption69 0` command. 3. If `Dim state` is less than 10% of maximum range that was set, you need to clear [SetOption69](Commands#Setoption69) by invoking `SetOption69 0`.
### Setting up Switches ### Setting up Switches
For switches we need to
For switches we need to 1. Configure the number of relays.
1. Configure the number of relays
2. Configure Power metering. 2. Configure Power metering.
#### Configure number of relays #### Configure number of relays
By default, the TuyaMCU module expects a 1 gang switch. There is no way currently to detect the number of relays present in an MCU based switch. We need to tell Tasmota using FunctionIDs 12 to 18 for Relay2 to Relay4. For example, for 4 gang switch we need to set `TuyaMCU 12,2`, `TuyaMCU 13,3` and `TuyaMCU 14,4` if the DpIds for Relays 2-4 are `2`,`3`,`4`.
By default TuyaMCU module expects 1 gang switch. There is no way currently to detect the number of relays present in MCU based switch, we need to tell it to Tasmota using FunctionIDs 12 to 18 for Relay2 to Relay4 TIP: You can configure all at once by using `Backlog TuyaMCU 12,2; TuyaMCU 13,3; TuyaMCU 14,4`
So for 4 gang switch we need to set `TuyaMCU 12,2`, `TuyaMCU 13,3` and `TuyaMCU 14,4` if the DpIds for Relays 2-4 are `2`,`3`,`4`.
TIP: You can configure all in one go using `backlog TuyaMCU 12,2; TuyaMCU 13,3; TuyaMCU 14,4`
#### Configure power metering #### Configure power metering
Power metering configuration is same as for dimmers. Check the power metering section for dimmers. Power metering configuration is same as for dimmers. Check the power metering section for dimmers.
### Setting up Curtain Motor ### Setting up Curtain Motor
The Zemismart WiFi curtain motor uses a Tuya TYWE1S inside the little white dongle as a radio modem. 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. `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.
To flash Tasmota, we need `U0RX`, `U0TX`, and `GPIO0`. None of which are broken out on the pcb, so soldering or Tuya-convert are useful.
The stock Tuya App communicates with the PIC Micro inside the motor housing at 9600 8N1. 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 101` is the "partial open/partial close" command with a 4 byte field of 0-100%.
@ -253,13 +219,13 @@ The stock Tuya App communicates with the PIC Micro inside the motor housing at 9
``` ```
55 aa 00 06 "deliver dp" 0005 "len=5" 66 04 00 01 <00=close100%,01=open0%> <chksum> is the fully open/close command 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. 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 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. 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
``` ```
There may first be a reply of 65 02 00 04 <oldvalue.32> <chksum> before the motor engages
#### Tasmota #### Tasmota
1. `module 54` # TuyaMCU (will reboot) 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) 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)
@ -280,4 +246,4 @@ Having 0x66 declared a button caused the motor to oscillate - open part way and
tuyamcu 11,102 # make 0x66 a relay tuyamcu 11,102 # make 0x66 a relay
tuyamcu 11,103 # make 0x67 a relay tuyamcu 11,103 # make 0x67 a relay
``` ```
Does not appear to have any impact on the curtain Does not appear to have any impact on the curtain.