dpId=9 seems to be a timer to toggle the device relay, set it to any value and it starts counting down, by the time it reaches 0 the relay toggles state. As far as I know, this can't be used in Tasmota
Where the command `TuyaMCU {fnId},{dpId}` is as outlined here.
So based on what you mentioned, the relay seems to be dpId 9.
The others (above) seem to relate to: dpId 20 = voltage power monitor (V) dpId 18 = current power monitor (A) dpId 19 = active power monitor (W)
dpId 101 = not sure as the fnId of 37 is not listed here
So let's try to get this running together. I don't have much time and I don't know this device, so we will do it step by step, carefully.
kraavok wrote:
So based on what you mentioned, the relay seems to be dpId 9.
Not really, it seems that it's a timer to turn off relay. Timer turns off relay after some time. It's not like a direct access to relay. But let's try that.
Quote:
Backlog TuyaMCU 33,20; TuyaMCU 32,18; TuyaMCU 31,19; TuyaMCU 37,101;
dpId=9 seem to be a timer to toggle the device relay, set it to any value and it starts counting down, by the time it reaches 0 the relay toggles state. As far as I know, this can't be used in Tasmota
This is an autoexec.bat that you shall drag on file system on LFS.
NOTE: you can just also type those 3 commands in console, but then they will NOT be remembered corrrectly.
linkTuyaMCUOutputToChannel [dpId][varType][channelID] Used to map between TuyaMCU dpIDs and our internal channels. Mapping works both ways. DpIDs are per-device, you can get them by sniffing UART communication. Vartypes can also be sniffed from Tuya. VarTypes can be following: 0-raw, 1-bool, 2-value, 3-string, 4-enum, 5-bitmap
Unless I'm much mistaken, the above code might allow you to toggle the relay through OpenBeken. Can you check it and tell me if the relay toggles? If it does not, we will try to diagnose. If it does, we will try to go further.
Things to check:
1. Do you get a button (toggle) on GUI with the code above?
2. Do you get a textfield with a "Send" button on GUI with the code above?
3. If you press a button, does the relay toggle instantly?
4. If you send a "1" in textfield (enter 1 and press button to send), does relay turn off after 1 second?
5. if you send a "5" in textfield (enter 5 and press button to send), does relay turn off after 5 seconds?
Please try the code above and report results here. Also provide screenshots to show any potential issues.
Unfortunately no luck. I even tried dpId 1 and 4 (some others mentioned in the Tasmota official docs for switches and relays). (see below for update)
1 & 2: Both fields displayed and were clickable
3: No response on the device on click
4 & 5: No response on the device after changing the values
Also, I had to use `setChannel ...` instead of `setChannelType ...` as it seems to have changed in your docs and `setChannelType` gave a "command not found" error.
EDIT: OK, I see that `setChannelType` works in the webapp console but not in the standard config console (outside the webapp). However, it does not change the outcome.
I checked the logs and found the following dpId outputs:
I can add any channel type for you, I can add a "voltage" channel that will format value as volts, I can add a "current" channel, etc, it's up to you.
Ah, ok, didn't realize they needed a new channel format. Makes sense now!
I guess the following channels would be useful, to match my Tasmota plugs:
p.kaczmarek2 wrote:
Also.... dpID 111, power factor, values like that need to have a multiplier, right?
It shows on the LCD display of the device as a decimal of the value listed. For example 542 shows as 0.542 so I suspect the value is simply clamped between 0 and 1000 and acts as the multiplier.
The Apparent Power could then be calculated by multiplying the Active Power (W) by 1/ Power Factor (PF as decimal).
Also, is there a way to ask TuyaMCU to update more frequently or is it fixed in their IC?
How often are you getting TuyaMCU updates? I will look into it.
Can you specify again all found dpIDs with their raw values and meaning? I know to know the multipliers.
Something like:
- dpID 111 - power factor - raw value 542 means 0.542 (multiplier 0.001)
- dpID 103 -voltage - raw value 221 means 221 (multiplier 1)
- etc
I want to add channel types for you, but I need to know multipliers.
How often are you getting TuyaMCU updates? I will look into it.
Right now, on the LCD display it's every second. In OpenBeken it arrives every minute I think.
p.kaczmarek2 wrote:
Can you specify again all found dpIDs with their raw values and meaning? I know to know the multipliers.
Something like:
- dpID 111 - power factor - raw value 542 means 0.542 (multiplier 0.001)
- dpID 103 - voltage - raw value 221 means 221 (multiplier 1)
- etc
I want to add channel types for you, but I need to know multipliers.
Here's the current status of what I've figured out:
1 - Energy Total (kWh) [UNCONFIRMED] - 0.001 multiplier
6 - Voltage - 0.1 multiplier
9 - [UNKNOWN]
16 - Relay switch
17 - [UNKNOWN - possibly current (more likely)] - if current, probably 0.01 multiplier
18 - [UNKNOWN - possibly current] - if current, probably 0.01 multiplier
101 - Energy Today (kWh) [UNCONFIRMED] - 0.001 multiplier
102 - Energy Yesterday (kWh) [UNCONFIRMED] - 0.001 multiplier
103 - Active Power (W) - NO multiplier
105 - Frequency (Hz) - 0.01 multiplier
109 - Energy Export [back to grid] (kWh) - 0.001 multiplier
110 - Reactive Power (VAr) - NO multiplier
111 - Power Factor (PF) - 0.001 multiplier
I will try to look into it today. I have ported OpenBeken to Windows and I will just add an UART simulator to 'fake' the TuyaMCU packets and write the support for their interpretations.
If anyone wants to help, please provide me more TuyaMCU packets dump, preferably from the RX pins of WiFi (the packets that WiFi module receives) in a hex form.
I have tools for analyzing them:
How to make TuyaMCU packets dump 1. solder RX of UART to USB connector to the given UART lane of your choice (for example, to RX of the Beken to see what Beken receives)
2. Open RealTerm
3. Go to Capture, set "Capture as Hex", disable other options (no commas, timestamps), enter file name, press "Start capture" and wait - it will capture to file (and will stop displaying output on RealTerm screen, just will be forwarding it to file"
4. Get a file like:
but this is just a general guide, I will try to use the data already provided here by @kraavok
UPDATE I only added variable types so far. Haven't done ROUNDING yet.
I have a question about id 6. This is not an enum nor an integer. It is 15 bytes of data.
Can anyone provide me more detailed samples of TuyaMCU packets, for example, with a certain known loads or voltages, so I can investigate more? I mean this data point:
Quote:
6:
Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 13 06 00 00 0F 00 00 00 0C 00 00 00 10 01 C3 00 00 77 09 1C AD
Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 26 bytes
Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 6, dataType 0-DP_TYPE_RAW and 15 data bytes
The DP_TYPE_RAW with 15 bytes of data is not even handled in my code yet. What kind of data is that?
55 AA 03 07 00 13 06 00 00 0F 000000BF0000013C01F800064F0930 180
HEADER VER=03 State LEN fnId=6 RAW V=00 00 00 BF 00 00 01 3C 01 F8 00 06 4F 09 30 CHK
55 AA 03 07 00 13 06 00 00 0F 000000BD0000013C01F40006450936 170
HEADER VER=03 State LEN fnId=6 RAW V=00 00 00 BD 00 00 01 3C 01 F4 00 06 45 09 36 CHK
55 AA 03 07 00 13 06 00 00 0F 000000C10000013C01FD000653092E 189
HEADER VER=03 State LEN fnId=6 RAW V=00 00 00 C1 00 00 01 3C 01 FD 00 06 53 09 2E CHK
55 AA 03 07 00 13 06 00 00 0F 000000BD0000013B01F6000646092E 164
HEADER VER=03 State LEN fnId=6 RAW V=00 00 00 BD 00 00 01 3B 01 F6 00 06 46 09 2E CHK
55 AA 03 07 00 13 06 00 00 0F 000000BD0000013B01F5000646092D 162
HEADER VER=03 State LEN fnId=6 RAW V=00 00 00 BD 00 00 01 3B 01 F5 00 06 46 09 2D CHK
but from a quick glance, I have not yet determined where the voltage is stored. I analyzed the data above in the hex editor and I can't see your voltage value yet, neither as a 32-bit float, nor an integer (most likely multiplied by 100 or so)
I would need more samples. It would be extremely helpful to get, for example, a sample from voltage like 234V and then from 225V or even 180V if you have an autotransformer, but I assume that most people don't own one. Hmmm. I will think about it more later today.
Just as kraavok, I get 13 dpIds. 8 VALUE (1, 101, 102, 103, 105, 109, 110, 111), 1 BOOL (16), 3 RAW (6, 17, 18) and 1 BITMAP (9). All the VALUE type dpIds are accounted for (almost, I can't confirm 102 is energy yesterday, as I only installed it today and it says 0, and 109 I think it's "reactive energy kvarh", not export) 16 is the relay. 6, 9, 17, 18 I don't know.
I have an inverter with slightly adjustable output voltage. (maybe 210-240V, not sure) I will try to use that and compare the voltages with the data from all these 4 dpIds.
Please do. And make a longer log file for me for analysis, maybe I will come up with something.
First let's decode those dpIDs, then we will handle the MQTT publishes.
Good thing also would be a test with 60W bulb and then a test with 10W bulb and two separate log files for comparison.
Dodano po 2 [godziny] 19 [minuty]:
Huh, now @btsimonh made me realize I haven't checked the big-endian values.... thanks @btsimonh !
000000BD0000013B01F5000646 092D This stands for 2349 which is most likely the voltage...
So that's it! I will now consider how to handle it in code.
Voltage parsing done, now I need two packet dumps:
- one with 60W bulb load
- one with 10W bulb load
Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 08 67 02 00 04 00 00 00 D3 51
Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 15 bytes
Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 103, dataType 2-DP_TYPE_VALUE and 4 data bytes
Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 211
Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 08 6F 02 00 04 00 00 02 38 C0
Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 15 bytes
Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 111, dataType 2-DP_TYPE_VALUE and 4 data bytes
Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 568
103 is power (so 211W) and 111 is power factor (0.568)
Voltage is 094C so 238V.
If my math is right, the current should be ~1.56A.
The display confirmed this value.
From dpId 6 if we take 2 or 3 bytes, before the voltage, we get 000613 (so 1555)
Seems right to me.
startDriver TuyaMCU
setChannelType 10 Current_div1000
setChannelType 11 Voltage_div10
setChannelType 12 Power
setChannelType 13 PowerFactor_div1000
// special syntax for 15 bytes packets containing multiple variables
// (no channel specified, it will set channels by their type automatically)
// This sets Current_div1000 and Voltage_div10
linkTuyaMCUOutputToChannel 6 RAW_DDS238
// this links tuyamcu var 103 to channel 12 which is Power
linkTuyaMCUOutputToChannel 103 Enum 12
// this links tuyamcu var 111 to channel 13 which is PowerFactor_div1000
linkTuyaMCUOutputToChannel 111 Enum 13
This is how it looks like on panel:
What next do we need? There is much more variables, but I am not sure about their meanings.
For example, are we sure about that "today consumption total" and "yesterday"?
Not sure about today and yesterday, I think my meter doesn't have a clock.
1 seems to be total consumption, but it's 0.01 scale (not 0.001)
Maybe it's different than DDS238-2.
So I am adding channel type: "EnergyTotal_kWh_div100". Now, what else do we need to read from that TuyaMCU?
And regarding next steps, what kind of publish format would you like? JSON one?
We already have our own power system that is able to calculate today's total and yesterdays (or should I rather say, last 24h?) and "all time" power consumption, I think I will add an option to connect TuyaMCU to that.
I don't think I need anything else right now.
MQTT with plain text is fine for me.
I already integrated it in Home Assistant and it calculates hourly/daily/monthly/cost/etc.
Automatic discovery in HA would be nice, but I only have one BK7231T device, so it wasn't a problem for me.
It works great.
Thanks a lot!
PS: The device froze one time with the previous firmware and config. Not sure why. It responded to ping, but the http requests failed (timeout) and it wasn't publishing anything to HA.
Right now it seems fine. I hope it stays that way.
Hey, sorry I have been away on holiday the past week but great work to you both! And nice find on the current reading @bizquik!
I'll flash the update ASAP and check on the changes. I have been using stock since my last update so that it was usable in the meantime.
@bizquik, could you post your HA config for the mqtt energy readings by any chance? Would save me (and hopefully others) some time setting that up. Thanks!
If there are any stability issues, please report them on Github. @valeklubomir did a great job updating LWIP for more stable version and most of issues are resolved, but we never know if it's really 100% stable now, maybe there is still something bad at play.
@kraavok@bizquik one important thing to know would be that we already have a power metering system with statistics in OpenBeken and with HA discovery and with JSON publish, but.... but it's not yet connected to TuyaMCU. It is used only for BL0937, BL0942, CSE, etc...
So soon I might add an option to connect that system to TuyaMCU.
Then you will be able to make a choice - whether to receive raw readings directly from channel publishes, or whether to use our OBK built-in system...
@bizquik, could you post your HA config for the mqtt energy readings by any chance? Would save me (and hopefully others) some time setting that up. Thanks!
The discussion revolves around configuring the OpenBK7231T (WB3S) firmware for the Hiking DDS238-2 smart meter after it was flashed successfully. Users explore the TuyaMCU protocol to control various functionalities of the smart meter, including relay operations and power monitoring. They identify specific dpIDs for different measurements such as voltage, current, and power factor, and discuss the necessary commands to set up these parameters in Tasmota. The conversation includes troubleshooting steps, sharing of logs, and the development of a Home Assistant integration for monitoring energy consumption. Users also share their findings on the multipliers for raw values and the frequency of updates from the device. Summary generated by the language model.