Help with ZMAI-90 and ESPHome or Tasmota

Hi!
I’m trying to convert my ZMAI-90 to ESPHome or Tasmota (ESPHome, if possible).
I’m using this tutorial and template as base: ZMAi-90 Digital Energy Meter (ZMAi-90) Template for Tasmota (blakadder.com) and Creation Factory: Reverse engineering the ZMAi-90 DIN rail meter/switch and integrating with Hass.io using Tasmota - Part 2

After opening my device, I figured that mine came with WB3S module, which is not compatible with Tasmota/ESPHome…so I have changed it to ESP-12E (same size and pinout) and I got this working, almost. I can upload ESPHome and Tasmota firmwares, both works fine.
In Tasmota, I could not get any function to work. Button, relay, power information (current, voltage, power), nothing…just the firmware that loads. But I could enable TuyaMCU and got some debug information from that (more below).

In ESPHome, I also got ESP to communicate with TuyaMCU and got some DP’s:

[14:54:53][I][app:105]: ESPHome version 1.17.2 compiled on May 16 2021, 13:30:16
[14:54:53][C][wifi:443]: WiFi:
[14:54:53][C][wifi:303]:   SSID: [redacted]
[14:54:53][C][wifi:304]:   IP Address: 192.168.22.42
[14:54:53][C][wifi:306]:   BSSID: [redacted]
[14:54:53][C][wifi:307]:   Hostname: 'medidor_energia_adsb'
[14:54:53][C][wifi:311]:   Signal strength: -52 dB ▂▄▆█
[14:54:53][C][wifi:315]:   Channel: 11
[14:54:53][C][wifi:316]:   Subnet: 255.255.255.0
[14:54:53][C][wifi:317]:   Gateway: 192.168.22.1
[14:54:53][C][wifi:318]:   DNS1: (IP unset)
[14:54:53][C][wifi:319]:   DNS2: (IP unset)
[14:54:53][C][uart_esp8266:075]: UART Bus:
[14:54:53][C][uart_esp8266:077]:   TX Pin: GPIO1
[14:54:53][C][uart_esp8266:080]:   RX Pin: GPIO3
[14:54:53][C][uart_esp8266:081]:   RX Buffer Size: 256
[14:54:53][C][uart_esp8266:083]:   Baud Rate: 9600 baud
[14:54:53][C][uart_esp8266:084]:   Data Bits: 8
[14:54:53][C][uart_esp8266:085]:   Parity: NONE
[14:54:53][C][uart_esp8266:086]:   Stop bits: 1
[14:54:53][C][uart_esp8266:088]:   Using hardware serial interface.
[14:54:53][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'button'
[14:54:53][C][gpio.binary_sensor:016]:   Pin: GPIO13 (Mode: INPUT)
[14:54:53][C][tuya:025]: Tuya:
[14:54:53][C][tuya:036]:   Datapoint 1: int value (value: 83)
[14:54:53][C][tuya:034]:   Datapoint 12: switch (value: OFF)
[14:54:53][C][tuya:036]:   Datapoint 13: int value (value: 0)
[14:54:53][C][tuya:034]:   Datapoint 16: switch (value: OFF)
[14:54:53][C][tuya:038]:   Datapoint 18: string value (value: 111111111111)
[14:54:53][C][tuya:050]:   Product: '{"p":"nzexeqam9qulajbf","v":"1.0.0","m":2}'
[14:54:53][C][logger:185]: Logger:
[14:54:53][C][logger:186]:   Level: DEBUG
[14:54:53][C][logger:187]:   Log Baud Rate: 0
[14:54:53][C][logger:188]:   Hardware UART: UART0
[14:54:53][C][tuya.switch:028]: Tuya Switch 'Teste Switch'
[14:54:53][C][tuya.switch:029]:   Switch has datapoint ID 16
[14:54:53][C][tuya.sensor:028]: Tuya Sensor 'Power'
[14:54:53][C][tuya.sensor:028]:   Unit of Measurement: 'W'
[14:54:53][C][tuya.sensor:028]:   Accuracy Decimals: 3
[14:54:53][C][tuya.sensor:028]:   Icon: 'mdi:flash'
[14:54:53][C][tuya.sensor:029]:   Sensor has datapoint ID 1
[14:54:53][C][tuya.sensor:028]: Tuya Sensor 'Voltage'
[14:54:53][C][tuya.sensor:028]:   Unit of Measurement: 'V'
[14:54:53][C][tuya.sensor:028]:   Accuracy Decimals: 3
[14:54:53][C][tuya.sensor:028]:   Icon: 'mdi:flash'
[14:54:53][C][tuya.sensor:029]:   Sensor has datapoint ID 13
[14:54:53][C][captive_portal:169]: Captive Portal:
[14:54:53][C][web_server:136]: Web Server:
[14:54:53][C][web_server:137]:   Address: 192.168.22.42:80
[14:54:53][C][web_server:139]:   Basic authentication enabled
[14:54:53][C][ota:029]: Over-The-Air Updates:
[14:54:53][C][ota:030]:   Address: 192.168.22.42:8266
[14:54:53][C][api:095]: API Server:
[14:54:53][C][api:096]:   Address: 192.168.22.42:6053
[14:54:53][C][tuya:025]: Tuya:
[14:54:53][C][tuya:036]:   Datapoint 1: int value (value: 83)
[14:54:53][C][tuya:034]:   Datapoint 12: switch (value: OFF)
[14:54:53][C][tuya:036]:   Datapoint 13: int value (value: 0)
[14:54:53][C][tuya:034]:   Datapoint 16: switch (value: OFF)
[14:54:53][C][tuya:038]:   Datapoint 18: string value (value: 111111111111)
[14:54:53][C][tuya:050]:   Product: '{"p":"nzexeqam9qulajbf","v":"1.0.0","m":2}'

But the only DP that I have successfull made work was 16 and 1. DP 16 is the main device relay and DP 1 is the cummulative power consumption stored in TuyaMCU device. None of the othe items is working.
This is the code that I’m testing with ESPHome:

esphome:
  name: medidor_energia_adsb
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "Skynet"
  password: "XXXX"
  manual_ip:
    static_ip: 192.168.22.42
    gateway: 192.168.22.1
    subnet: 255.255.255.0    
  

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Medidor Energia Adsb"
    password: "JunhgKtFu2z7"

captive_portal:

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80
  auth:
    username: jmaurin
    password: !secret web_server_pwd


uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600
  #parity: EVEN

# Register the Tuya MCU connection
tuya:


switch:
  - platform: "tuya"
    name: "Teste Switch"
    id: power
    switch_datapoint: 16
    
    
binary_sensor:
  - platform: gpio
    pin: 13
    id: button
    on_press:
      then:
        - switch.toggle: power    
        
        
sensor:   
  - platform: "tuya"
    name: "Power"
    sensor_datapoint: 1
    accuracy_decimals: 3
    unit_of_measurement: "W"
    icon: "mdi:flash"
#    filters:
#    - multiply: 0.1

Like I said before, Tasmot could not read anything is this device…not even relay. I’m using these commands to configure tasmota (copyied from URL in this msg):

Backlog SetOption66 1; TuyaMCU 0,17; TuyaMCU 32,18; TuyaMCU 31,19; TuyaMCU 33,20; SetOption59 1

From Tasmota, I got a lot more debug information…but I don’t have any idea how to use/configure these information. Note that even after copy/paste command from URL, I got an invalid function id from tasmota:

19:12:09.732 CMD: Backlog SetOption66 1; TuyaMCU 0,17; TuyaMCU 32,18; TuyaMCU 31,19; TuyaMCU 33,20; SetOption59 1
19:12:09.793 RSL: RESULT = {"SetOption66":"ON"}
19:12:09.001 TYA: TuyaMcu Invalid function id=0

And this is the full log. During this log, I was reading these values in device LCD:
Voltage: more or less 128.3
Current: 0.96A
Power: 0.12 (probabily 120W, since I was using 120W bulb to test)
Cumulative power: 0.84

Log:

00:00:00.001 HDW: ESP8266EX
00:00:00.053 CFG: Loaded from flash at F7, Count 40
00:00:00.058 QPC: Count 1
00:00:00.109 SNS: Hardware Serial
00:00:00.144 Project tasmota Tasmota Version 9.4.0(lite)-2_7_4_9(2021-04-23T10:07:16)
00:00:00.170 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0303000005","Cmnd":3}}
00:00:00.557 WIF: Connecting to AP1 Skynet Channel 11 BSSId 28:D1:27:4E:7E:60 in mode 11n as tasmota_E04F1A-3866...
00:00:02.494 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000C0600000804FE0003C900007B6C","Cmnd":7,"CmndData":"0600000804FE0003C900007B","DpType0Id6":"0x04FE0003C900007B","6":{"DpId":6,"DpIdType":0,"DpIdData":"04FE0003C900007B"}}}
00:00:03.492 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000546C","Cmnd":7,"CmndData":"0102000400000054","DpType2Id1":84,"1":{"DpId":1,"DpIdType":2,"DpIdData":"00000054"}}}
00:00:03.792 WIF: Connected
00:00:04.044 HTP: Web server active on tasmota_E04F1A-3866 with IP address 192.168.22.42
19:18:50.021 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0303000005","Cmnd":3}}
19:18:51.018 RSL: INFO1 = {"Info1":{"Module":"Tuya MCU","Version":"9.4.0(lite)","FallbackTopic":"cmnd/DVES_E04F1A_fb/","GroupTopic":"cmnd/tasmotas/"}}
19:18:51.020 RSL: INFO2 = {"Info2":{"WebServerMode":"Admin","Hostname":"tasmota_E04F1A-3866","IPAddress":"192.168.22.42"}}
19:18:51.022 RSL: INFO3 = {"Info3":{"RestartReason":"Software/System restart"}}
19:18:51.024 RSL: RESULT = {"POWER":"OFF"}
19:18:51.026 RSL: POWER = OFF
19:18:51.100 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0301002A7B2270223A226E7A65786571616D3971756C616A6266222C2276223A22312E302E30222C226D223A327D78","Cmnd":1,"CmndData":"7B2270223A226E7A65786571616D3971756C616A6266222C2276223A22312E302E30222C226D223A327D"}}
19:18:51.102 TYA: MCU Product ID: {"p":"nzexeqam9qulajbf","v":"1.0.0","m":2}
19:18:51.121 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0302000004","Cmnd":2}}
19:18:51.160 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000546C","Cmnd":7,"CmndData":"0102000400000054","DpType2Id1":84,"1":{"DpId":1,"DpIdType":2,"DpIdData":"00000054"}}}
19:18:51.187 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000C0600000804FE0003C900007B6C","Cmnd":7,"CmndData":"0600000804FE0003C900007B","DpType0Id6":"0x04FE0003C900007B","6":{"DpId":6,"DpIdType":0,"DpIdData":"04FE0003C900007B"}}}
19:18:51.202 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030700050A050001001E","Cmnd":7,"CmndData":"0A05000100","DpType5Id10":"0x00","10":{"DpId":10,"DpIdType":5,"DpIdData":"00"}}}
19:18:51.216 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030700050C010001001C","Cmnd":7,"CmndData":"0C01000100","DpType1Id12":0,"12":{"DpId":12,"DpIdType":1,"DpIdData":"00"}}}
19:18:51.236 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030700080D0200040000000024","Cmnd":7,"CmndData":"0D02000400000000","DpType2Id13":0,"13":{"DpId":13,"DpIdType":2,"DpIdData":"00000000"}}}
19:18:51.251 RSL: RESULT = {"TuyaReceived":{"Data":"55AA03070005100100010121","Cmnd":7,"CmndData":"1001000101","DpType1Id16":1,"16":{"DpId":16,"DpIdType":1,"DpIdData":"01"}}}
19:18:51.279 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030700101100000C0100003C030001080400006EF1","Cmnd":7,"CmndData":"1100000C0100003C030001080400006E","DpType0Id17":"0x0100003C030001080400006E","17":{"DpId":17,"DpIdType":0,"DpIdData":"0100003C030001080400006E"}}}
19:18:51.308 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030700101203000C31313131313131313131313186","Cmnd":7,"CmndData":"1203000C313131313131313131313131","DpType3Id18":"111111111111","18":{"DpId":18,"DpIdType":3,"DpIdData":"313131313131313131313131","Type3Data":"111111111111"}}}
19:18:52.455 QPC: Reset
19:18:55.421 RSL: STATE = {"Time":"2021-05-16T19:18:55","Uptime":"0T00:00:11","UptimeSec":11,"Vcc":3.447,"Heap":30,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":0,"POWER":"OFF","Wifi":{"AP":1,"SSId":"Skynet","BSSId":"28:D1:27:4E:7E:60","Channel":11,"RSSI":98,"Signal":-51,"LinkCount":1,"Downtime":"0T00:00:05"}}
19:18:55.430 RSL: SENSOR = {"Time":"2021-05-16T19:18:55","ENERGY":{"TotalStartTime":"2021-05-16T16:37:43","Total":0.000,"Yesterday":0.000,"Today":0.000,"Period":0,"Power":0,"ApparentPower":0,"ReactivePower":0,"Factor":0.00,"Voltage":0,"Current":0.000}}
19:18:55.454 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
19:19:03.495 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000C0600000805000003C900007C70","Cmnd":7,"CmndData":"0600000805000003C900007C","DpType0Id6":"0x05000003C900007C","6":{"DpId":6,"DpIdType":0,"DpIdData":"05000003C900007C"}}}
19:19:04.492 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000546C","Cmnd":7,"CmndData":"0102000400000054","DpType2Id1":84,"1":{"DpId":1,"DpIdType":2,"DpIdData":"00000054"}}}
19:19:06.437 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
19:19:17.435 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
19:19:18.493 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000C0600000805020003CA00007C73","Cmnd":7,"CmndData":"0600000805020003CA00007C","DpType0Id6":"0x05020003CA00007C","6":{"DpId":6,"DpIdType":0,"DpIdData":"05020003CA00007C"}}}
19:19:19.513 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000546C","Cmnd":7,"CmndData":"0102000400000054","DpType2Id1":84,"1":{"DpId":1,"DpIdType":2,"DpIdData":"00000054"}}}
19:19:28.399 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
19:19:33.493 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000C0600000805020003C900007C72","Cmnd":7,"CmndData":"0600000805020003C900007C","DpType0Id6":"0x05020003C900007C","6":{"DpId":6,"DpIdType":0,"DpIdData":"05020003C900007C"}}}
19:19:34.492 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000546C","Cmnd":7,"CmndData":"0102000400000054","DpType2Id1":84,"1":{"DpId":1,"DpIdType":2,"DpIdData":"00000054"}}}
19:19:39.432 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
19:19:48.493 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000C0600000805020003C900007C72","Cmnd":7,"CmndData":"0600000805020003C900007C","DpType0Id6":"0x05020003C900007C","6":{"DpId":6,"DpIdType":0,"DpIdData":"05020003C900007C"}}}
19:19:49.492 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000546C","Cmnd":7,"CmndData":"0102000400000054","DpType2Id1":84,"1":{"DpId":1,"DpIdType":2,"DpIdData":"00000054"}}}
19:19:50.412 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
19:20:01.435 RSL: RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
19:20:03.493 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000C0600000805020003C900007C72","Cmnd":7,"CmndData":"0600000805020003C900007C","DpType0Id6":"0x05020003C900007C","6":{"DpId":6,"DpIdType":0,"DpIdData":"05020003C900007C"}}}
19:20:04.492 RSL: RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000546C","Cmnd":7,"CmndData":"0102000400000054","DpType2Id1":84,"1":{"DpId":1,"DpIdType":2,"DpIdData":"00000054"}}}

Ok, got one tasmota working config:

Backlog SetOption66 1; TuyaMCU 11,16; TuyaMCU 36,6; TuyaMCU 37,1; SetOption59 1; SetOption72 1
Rule1 on System#Boot do RuleTimer1 10 endon on Rules#Timer=1 do backlog TuyaSend8; RuleTimer1 10 endon

Now how to port this to ESPHome?

Whoa there’s at least 3 version of zmai-90 circulating so far.

  1. the one not using tuyamcu protocols
  2. the one using tuyamcu protocols but with esp12
  3. the one using wb3es and using different tuyamcu protocols than no. 2.

I have version 2 and 3 so far, and managed to configure the version 2 with tasmota (however I found minor bug and has been fixed in development version) Support Tuya powermeter >6500W by barbudor · Pull Request #12115 · arendst/Tasmota · GitHub

Planning to replace the version 3 with esp12, but after seeing your post got me think again whether to do it or not lol.

Can you also post the debug log with working configuration? I’d like to know what data is available.

Sorry I can’t help you with esphome since I only have experience with tasmota so far.

Exactly those 2 commands are used, nothing more (no GPIO configuration, no template, nothing!).
After executing these 2 lines, everything is configured in Tasmota.
What is available in Tasmota (and HA too):

Voltage 131 V
Current 0.554 A
Power 46 W
Apparent Power 72 VA
Reactive Power 56 VAr
Power Factor 0.64
Energy Today 0.710 kWh
Energy Yesterday 0.001 kWh
Energy Total 1.570 kWh

After some tests, everything look correct (values).
If you need any other log, tell me how to get… I’m not familiar with Tasmota advanced config or commands.

I have ZMAi-90 with TYWE3S chip, it also uses TuyaMCU and it works great with ESPHome.

Important parts of your config, such as esphome.board and logger.baud_rate are correct.

In your ESPHome log I can see five datapoints reported by TuyaMCU: 1, 12, 13, 16, 18 but in your working Tasmota config I can see three configured datapoints 16, 6 and 1. And datapoint 6 is very confuse me because of ESPHome was not report it.

Tasmota can report datapoints configuration by TuyaSend0 or TuyaSend8 command (I do not remember what exactly one). Also you can read about dpId in Tasmota docs TuyaMCU - Tasmota

Datapoints used in my configuration are very different (1, 17, 19, 18, 20), but it is not a problem because ESPHome supports any, you just need to find and configure them. Basically you should need to find datapoint for voltage, current and active power. Optionally for total power and power switch.

I will share my config later, because of heavy using custom components (apparent and reactive power, power factor, daily stats and tariffs) and want to prepare them to public.

1 Like

I think it’s more complicated to do the same in ESPHome. In my config you see dp6 because I saw that in Tasmota and I wanted to use/test, but no results.
Looking better, I can see that there’s a timer on Tasmota that send a command every X second (I guess 10 seconds). See:

Rule1 on System#Boot do RuleTimer1 10 endon on Rules#Timer=1 do backlog TuyaSend8; RuleTimer1 10 endon

And this is the description of TuyaSend8:

TuyaSend8~
Used without payload to get device information and dpId states. Replaces SerialSend5 55aa000100000

My gues is that Tasmota (or ESPHome) must request status information…then, TuyaMCU reply with results.
About results, I’m preety sure that all data came in only one packet/result and them Tasmota split this data and make bit inversion and formation, etc etc… It’s not just get result from one DP and display as value. We need to split one response into X small values corresponding to P, I, V.
The question is: how to do this in ESPHome?
I don’t even know how to send anything to tuyaMCU in ESPHome…is the same of sending UART commands?! I don’t think.

TuyaMCU automatically reports every datapoint as separate result when it ready (no need timer). Or we can force request status of all datapoints but result will be the same - many responses with one datapoint per response.

So to write ESPHome configuration you just need to get those datapoints from Tasmota.

Could you execute weblog 4 and then TuyaSend0 and TuyaSend8 commands and show logs here?

Here is example of sending command:


switch:
  # Query the device initialization status.
  - platform: "uart"
    id: sw_tuya_query_status
    data: [0x55, 0xaa, 0x00, 0x08, 0x00, 0x00, 0x07]
    name: "$name [Tuya] Query MCU working status"
    icon: mdi:reload

DP=6 is not even listed in ESPHome :confused:
Without the second line from my second post (Rule1…), Tasmota just receive DP=1 every some seconds…nothing else. This is the ‘default’ config for most of ZMAI-90. Them I found this ‘variant’ config that has different DP’s and worked for me!

Here’s the log from Tasmot working configuration and valid values:

23:48:24.208 TYA: fnId=37 is set for dpId=1
23:48:24.210 TYA: RX value 188 from dpId 1 
23:48:24.213 TYA: Rx ID=1 Total_Power=188
23:48:25.202 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000C06000008050A00021600002C76","Cmnd":7,"CmndData":"06000008050A00021600002C","DpType0Id6":"0x050A00021600002C","6":{"DpId":6,"DpIdType":0,"DpIdData":"050A00021600002C"}}}
23:48:25.207 TYA: fnId=36 is set for dpId=6
23:48:25.210 TYA: Rx ID=6 Voltage=1290
23:48:25.212 TYA: Rx ID=6 Current=534
23:48:25.215 TYA: Rx ID=6 Active_Power=44
23:48:32.479 TYA: Send "55aa00000000ff"
23:48:32.494 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
23:48:32.497 TYA: Heartbeat
23:48:34.806 HTP: Configure Logging
23:48:34.810 SRC: WebGui from 192.168.22.12
23:48:34.814 CMD: Group 0, Index 0, Command "BACKLOG", Data "SerialLog 0;WebLog 4;MqttLog 0;SysLog 0;LogHost 192.168.22.12;LogPort 514;TelePeriod 60"
23:48:34.817 HTP: Configuration
23:48:34.872 SRC: Backlog
23:48:34.875 CMD: Group 0, Index 1, Command "SERIALLOG", Data "0"
23:48:34.880 MQT: stat/medidor_energia_adsb/RESULT = {"SerialLog":{"0":{"Active":"0"}}}
23:48:34.885 SRC: Backlog
23:48:34.888 CMD: Group 0, Index 1, Command "WEBLOG", Data "4"
23:48:34.893 MQT: stat/medidor_energia_adsb/RESULT = {"WebLog":4}
23:48:34.899 SRC: Backlog
23:48:34.902 CMD: Group 0, Index 1, Command "MQTTLOG", Data "0"
23:48:34.909 MQT: stat/medidor_energia_adsb/RESULT = {"MqttLog":0}
23:48:34.914 SRC: Backlog
23:48:34.917 CMD: Group 0, Index 1, Command "SYSLOG", Data "0"
23:48:34.923 MQT: stat/medidor_energia_adsb/RESULT = {"SysLog":{"0":{"Active":"0"}}}
23:48:34.927 SRC: Backlog
23:48:34.930 CMD: Group 0, Index 1, Command "LOGHOST", Data "192.168.22.12"
23:48:34.933 CFG: CR 385/699, Busy 0
23:48:34.938 MQT: stat/medidor_energia_adsb/RESULT = {"LogHost":"192.168.22.12"}
23:48:34.944 SRC: Backlog
23:48:34.947 CMD: Group 0, Index 1, Command "LOGPORT", Data "514"
23:48:34.954 MQT: stat/medidor_energia_adsb/RESULT = {"LogPort":514}
23:48:34.958 SRC: Backlog
23:48:34.961 CMD: Group 0, Index 1, Command "TELEPERIOD", Data "60"
23:48:34.965 MQT: stat/medidor_energia_adsb/RESULT = {"TelePeriod":60}
23:48:35.469 MQT: tele/medidor_energia_adsb/STATE = {"Time":"2021-05-17T23:48:35","Uptime":"0T21:29:38","UptimeSec":77378,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"Skynet","BSSId":"9C:9D:7E:75:7C:F6","Channel":11,"RSSI":52,"Signal":-74,"LinkCount":1,"Downtime":"0T00:00:05"}}
23:48:35.480 MQT: tele/medidor_energia_adsb/SENSOR = {"Time":"2021-05-17T23:48:35","ENERGY":{"TotalStartTime":"2021-05-17T01:26:52","Total":1.880,"Yesterday":0.001,"Today":1.020,"Period":0,"Power":44,"ApparentPower":69,"ReactivePower":53,"Factor":0.64,"Voltage":129,"Current":0.534}}
23:48:35.773 CFG: Saved to flash at F4, Count 83, Bytes 4096
23:48:35.930 WIF: Checking connection...
23:48:39.204 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000BCD4","Cmnd":7,"CmndData":"01020004000000BC","DpType2Id1":188,"1":{"DpId":1,"DpIdType":2,"DpIdData":"000000BC"}}}
23:48:39.208 TYA: fnId=37 is set for dpId=1
23:48:39.211 TYA: RX value 188 from dpId 1 
23:48:39.213 TYA: Rx ID=1 Total_Power=188
23:48:39.909 HTP: Main Menu
23:48:40.200 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000C06000008050A00021300002C73","Cmnd":7,"CmndData":"06000008050A00021300002C","DpType0Id6":"0x050A00021300002C","6":{"DpId":6,"DpIdType":0,"DpIdData":"050A00021300002C"}}}
23:48:40.204 TYA: fnId=36 is set for dpId=6
23:48:40.207 TYA: Rx ID=6 Voltage=1290
23:48:40.209 TYA: Rx ID=6 Current=531
23:48:40.212 TYA: Rx ID=6 Active_Power=44
23:48:41.457 HTP: Console
23:48:43.486 TYA: Send "55aa00000000ff"
23:48:43.500 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
23:48:43.503 TYA: Heartbeat
23:48:54.204 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000BCD4","Cmnd":7,"CmndData":"01020004000000BC","DpType2Id1":188,"1":{"DpId":1,"DpIdType":2,"DpIdData":"000000BC"}}}
23:48:54.208 TYA: fnId=37 is set for dpId=1
23:48:54.210 TYA: RX value 188 from dpId 1 
23:48:54.213 TYA: Rx ID=1 Total_Power=188
23:48:54.476 TYA: Send "55aa00000000ff"
23:48:54.493 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
23:48:54.497 TYA: Heartbeat
23:48:55.205 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000C06000008050700021600002C73","Cmnd":7,"CmndData":"06000008050700021600002C","DpType0Id6":"0x050700021600002C","6":{"DpId":6,"DpIdType":0,"DpIdData":"050700021600002C"}}}
23:48:55.209 TYA: fnId=36 is set for dpId=6
23:48:55.212 TYA: Rx ID=6 Voltage=1287
23:48:55.214 TYA: Rx ID=6 Current=534
23:48:55.217 TYA: Rx ID=6 Active_Power=44
23:48:55.949 WIF: Checking connection...
23:48:58.456 TYA: Send "55aa001c00080115051117303a01d1"
23:49:05.472 TYA: Send "55aa00000000ff"
23:49:05.489 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
23:49:05.493 TYA: Heartbeat
23:49:09.200 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000BCD4","Cmnd":7,"CmndData":"01020004000000BC","DpType2Id1":188,"1":{"DpId":1,"DpIdType":2,"DpIdData":"000000BC"}}}
23:49:09.204 TYA: fnId=37 is set for dpId=1
23:49:09.207 TYA: RX value 188 from dpId 1 
23:49:09.210 TYA: Rx ID=1 Total_Power=188
23:49:10.201 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000C06000008050600021400002C70","Cmnd":7,"CmndData":"06000008050600021400002C","DpType0Id6":"0x050600021400002C","6":{"DpId":6,"DpIdType":0,"DpIdData":"050600021400002C"}}}
23:49:10.205 TYA: fnId=36 is set for dpId=6
23:49:10.208 TYA: Rx ID=6 Voltage=1286
23:49:10.211 TYA: Rx ID=6 Current=532
23:49:10.213 TYA: Rx ID=6 Active_Power=44
23:49:15.944 WIF: Checking connection...
23:49:16.471 TYA: Send "55aa00000000ff"
23:49:16.485 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
23:49:16.488 TYA: Heartbeat
23:49:24.199 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000801020004000000BCD4","Cmnd":7,"CmndData":"01020004000000BC","DpType2Id1":188,"1":{"DpId":1,"DpIdType":2,"DpIdData":"000000BC"}}}
23:49:24.202 TYA: fnId=37 is set for dpId=1
23:49:24.205 TYA: RX value 188 from dpId 1 
23:49:24.207 TYA: Rx ID=1 Total_Power=188
23:49:25.199 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA0307000C06000008050200021900002C71","Cmnd":7,"CmndData":"06000008050200021900002C","DpType0Id6":"0x050200021900002C","6":{"DpId":6,"DpIdType":0,"DpIdData":"050200021900002C"}}}
23:49:25.203 TYA: fnId=36 is set for dpId=6
23:49:25.206 TYA: Rx ID=6 Voltage=1282
23:49:25.208 TYA: Rx ID=6 Current=537
23:49:25.210 TYA: Rx ID=6 Active_Power=44
23:49:27.474 TYA: Send "55aa00000000ff"
23:49:27.488 MQT: tele/medidor_energia_adsb/RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
23:49:27.492 TYA: Heartbeat

I want to see the contents of the DpID of 16, 6, and 1 gets translated to power, current and voltage

turn on weblog to 3 (debug) and show the console log.

Your help is greatly appreciated :slight_smile:

Nevermind I just saw your post above my post please disregard this.
Interesting all the info came from DPID of 6

Something like this

08:20:52.620 MQT: tele/tasmota_936F2D/RESULT = {"TuyaReceived":{"Data":"55AA03070005010100010112","Cmnd":7,"CmndData":"0101000101","DpType1Id1":1,"1":{"DpId":1,"DpIdType":1,"DpIdData":"01"}}}
08:20:52.629 TYA: fnId=11 is set for dpId=1
08:20:52.632 TYA: RX Relay-1 --> MCU State: On Current State:On
08:20:52.641 MQT: tele/tasmota_936F2D/RESULT = {"TuyaReceived":{"Data":"55AA03070008110200040028475EF5","Cmnd":7,"CmndData":"110200040028475E","DpType2Id17":2639710,"17":{"DpId":17,"DpIdType":2,"DpIdData":"0028475E"}}}
08:20:52.651 TYA: fnId=0 is set for dpId=17
08:20:52.653 TYA: RX value 18270 from dpId 17 
08:20:52.656 SRC: Backlog
08:20:52.659 CMD: Group 0, Index 1, Command "RULETIMER", Data "10"
08:20:52.666 MQT: stat/tasmota_936F2D/RESULT = {"T1":10,"T2":0,"T3":0,"T4":0,"T5":0,"T6":0,"T7":0,"T8":0}
08:20:52.679 MQT: tele/tasmota_936F2D/RESULT = {"TuyaReceived":{"Data":"55AA030700081202000400000F447C","Cmnd":7,"CmndData":"1202000400000F44","DpType2Id18":3908,"18":{"DpId":18,"DpIdType":2,"DpIdData":"00000F44"}}}
08:20:52.689 TYA: fnId=32 is set for dpId=18
08:20:52.691 TYA: RX value 3908 from dpId 18 
08:20:52.694 TYA: Rx ID=18 Current=3908
08:20:52.700 MQT: tele/tasmota_936F2D/RESULT = {"TuyaReceived":{"Data":"55AA030700081302000400001DEE35","Cmnd":7,"CmndData":"1302000400001DEE","DpType2Id19":7662,"19":{"DpId":19,"DpIdType":2,"DpIdData":"00001DEE"}}}
08:20:52.710 TYA: fnId=31 is set for dpId=19
08:20:52.712 TYA: RX value 7662 from dpId 19 
08:20:52.714 TYA: Rx ID=19 Active_Power=7662
08:20:52.720 MQT: tele/tasmota_936F2D/RESULT = {"TuyaReceived":{"Data":"55AA0307000814020004000008ED20","Cmnd":7,"CmndData":"14020004000008ED","DpType2Id20":2285,"20":{"DpId":20,"DpIdType":2,"DpIdData":"000008ED"}}}
08:20:52.730 TYA: fnId=33 is set for dpId=20
08:20:52.732 TYA: RX value 2285 from dpId 20 
08:20:52.735 TYA: Rx ID=20 Voltage=2285
08:20:57.448 TYA: Send "55aa001c00080115051208143902a7"
08:20:59.397 MQT: tele/tasmota_936F2D/STATE = {"Time":"2021-05-18T08:20:59","Uptime":"0T16:25:03","UptimeSec":59103,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"th0r-IoT","BSSId":"EA:9F:DB:1C:97:3C","Channel":6,"RSSI":88,"Signal":-56,"LinkCount":1,"Downtime":"0T00:00:03"}}
08:20:59.409 MQT: tele/tasmota_936F2D/SENSOR = {"Time":"2021-05-18T08:20:59","ENERGY":{"TotalStartTime":"2021-05-16T09:05:26","Total":2659.987,"Yesterday":36.065,"Today":7.154,"Period":2.3,"Power":766.2,"ApparentPower":893.0,"ReactivePower":458.6,"Factor":0.86,"Voltage":228.5,"Current":3.908}}

Hm…, Now I see… You really have Tuya packed value for dp=6 (voltage, current and active power) and type of this data is 0 (RAW).

Unfortunately ESPHome tuya component does not support RAW data type yet. Look at the code esphome/tuya.cpp at dce9d59dfe6a7e9a3f1914234a02a01c9bdf021e · esphome/esphome · GitHub there is no case for TuyaDatapointType::RAW and even no log for that - by default received message just skipped.

Tuya component is actively developed so you could fill a bug and wait for it resolution or make a fix yourself. ESPHome does not support RAW data, but it can be bypassed with TextSensor.

I really want to help…I even have some little experience with C…but not python (and the main project is in python). The problem is: I could not find any information how to compile ESPHome from the source. Am I missing something? Any link?
I just found how to install using docker or pip, but nothing about compile from source.
Tried python3 setup.py from source tree, didn’t worked…

Nevermind, just found it

In ESPHome Python id used only for code generation, all other parts are c++ code.
Here is contributing guide Contributing — ESPHome
But in my opinion using vscode devcontainer is simplest way.

Also if you have ESPHome installation inside Home Assistant, you can try to put components/tuya inside HA esphome/custom_components folder or try to use great external components feature from ESPHome 1.18 beta and start hacking.

Interesting!
How hard is to update my HA addon to beta version?
I’m running 1.17.2, say it’s the latest version (current).

The easiest way is wait until it is releases :wink: I guess it will be at start of June

Or follow the official docs Frequently Asked Questions — ESPHome

It released!
Try External Components — ESPHome

@jmceara I could try fix it for you

Please install latest ESPHome (1.18.0) and use my patch via external component:

...
external_components:
  - source: github://dentra/esphome@dev
    components: ["tuya"]
...
text_sensor:
  - platform: "tuya"
    name: "Energy Data"
    sensor_datapoint: 6
...

It is a first part. So, I need a log with configured datapoints and reports from text sensor to be sure that all things are fine.

In second part we split data into defferent sensors.

hehehehe…very close to what I was doing to debug :wink:
But of course, your code is better :slight_smile: I’ll test tonight, as soon as I get home. Will report here.

Yep! Data is comming! :slight_smile:

[17:23:04][C][logger:189]: Logger:
[17:23:04][C][logger:190]:   Level: DEBUG
[17:23:04][C][logger:191]:   Log Baud Rate: 0
[17:23:04][C][logger:192]:   Hardware UART: UART0
[17:23:04][C][tuya.text_sensor:025]: Tuya Text Sensor:
[17:23:04][C][tuya.text_sensor:026]:   Text Sensor has datapoint ID 6
[17:23:04][C][tuya.text_sensor:025]: Tuya Text Sensor:
[17:23:04][C][tuya.text_sensor:026]:   Text Sensor has datapoint ID 17
[17:23:04][C][captive_portal:169]: Captive Portal:
[17:23:04][C][web_server:136]: Web Server:
[17:23:04][C][web_server:137]:   Address: 192.168.22.42:80
[17:23:04][C][web_server:139]:   Basic authentication enabled
[17:23:04][C][ota:029]: Over-The-Air Updates:
[17:23:04][C][ota:030]:   Address: 192.168.22.42:8266
[17:23:04][C][api:095]: API Server:
[17:23:04][C][api:096]:   Address: 192.168.22.42:6053
[17:23:04][C][tuya:025]: Tuya:
[17:23:04][C][tuya:036]:   Datapoint 1: int value (value: 394)
[17:23:04][C][tuya:044]:   Datapoint 6: raw value (value: 04.F4.00.02.3E.00.00.2E (8))
[17:23:04][C][tuya:034]:   Datapoint 12: switch (value: OFF)
[17:23:04][C][tuya:036]:   Datapoint 13: int value (value: 0)
[17:23:04][C][tuya:034]:   Datapoint 16: switch (value: ON)
[17:23:04][C][tuya:044]:   Datapoint 17: raw value (value: 01.00.00.3C.03.00.01.08.04.00.00.6E (12))
[17:23:04][C][tuya:038]:   Datapoint 18: string value (value: 111111111111)
[17:23:04][C][tuya:052]:   Product: '{"p":"nzexeqam9qulajbf","v":"1.0.0","m":2}'
[17:23:08][D][text_sensor:015]: 'Energy Data': Sending state '04.F5.00.02.3B.00.00.2E (8)'
[17:23:08][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F5.00.02.3B.00.00.2E (8)
[17:23:23][D][text_sensor:015]: 'Energy Data': Sending state '04.F3.00.02.3E.00.00.2E (8)'
[17:23:23][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F3.00.02.3E.00.00.2E (8)
[17:23:38][D][text_sensor:015]: 'Energy Data': Sending state '04.F5.00.02.3E.00.00.2F (8)'
[17:23:38][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F5.00.02.3E.00.00.2F (8)
[17:23:53][D][text_sensor:015]: 'Energy Data': Sending state '04.F6.00.02.3B.00.00.2E (8)'
[17:23:53][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F6.00.02.3B.00.00.2E (8)
[17:24:08][D][text_sensor:015]: 'Energy Data': Sending state '04.F8.00.02.3B.00.00.2E (8)'
[17:24:08][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F8.00.02.3B.00.00.2E (8)
[17:24:23][D][text_sensor:015]: 'Energy Data': Sending state '04.F8.00.02.3A.00.00.2E (8)'
[17:24:23][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F8.00.02.3A.00.00.2E (8)
[17:24:38][D][text_sensor:015]: 'Energy Data': Sending state '04.FA.00.02.3E.00.00.2E (8)'
[17:24:38][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.FA.00.02.3E.00.00.2E (8)
[17:24:53][D][text_sensor:015]: 'Energy Data': Sending state '04.F4.00.02.44.00.00.2F (8)'
[17:24:53][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F4.00.02.44.00.00.2F (8)
[17:25:08][D][text_sensor:015]: 'Energy Data': Sending state '04.F5.00.02.42.00.00.2E (8)'
[17:25:08][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F5.00.02.42.00.00.2E (8)
[17:25:23][D][text_sensor:015]: 'Energy Data': Sending state '04.F5.00.02.41.00.00.2E (8)'
[17:25:23][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F5.00.02.41.00.00.2E (8)
[17:25:38][D][text_sensor:015]: 'Energy Data': Sending state '04.F5.00.02.42.00.00.2E (8)'
[17:25:38][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F5.00.02.42.00.00.2E (8)
[17:25:53][D][text_sensor:015]: 'Energy Data': Sending state '04.F4.00.02.45.00.00.2F (8)'
[17:25:53][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F4.00.02.45.00.00.2F (8)
[17:26:08][D][text_sensor:015]: 'Energy Data': Sending state '04.F4.00.02.3F.00.00.2E (8)'
[17:26:08][D][tuya.text_sensor:015]: MCU reported text sensor is: 04.F4.00.02.3F.00.00.2E (8)

I have also enabled one more text_sensor for DP17, but nothing is displayed…maybe it’s just the board version or something like this.
The data looks correct. Testing one packet, we can see 04.FA => 1274, or 127.4V (if I’m not wrong).

This is my test config:

esphome:
  name: medidor_energia_adsb
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "Skynet"
  password: "XXXXXXX"
  manual_ip:
    static_ip: 192.168.22.42
    gateway: 192.168.22.1
    subnet: 255.255.255.0    
  

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Medidor Energia Adsb"
    password: "JunhgKtFu2z7"

captive_portal:

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80
  auth:
    username: jmaurin
    password: !secret web_server_pwd


uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600
  #parity: EVEN


external_components:
  - source: github://dentra/esphome@dev
    components: ["tuya"]



# Register the Tuya MCU connection
tuya:


text_sensor:
  - platform: "tuya"
    name: "Energy Data"
    sensor_datapoint: 6
    
  - platform: "tuya"
    name: "DP 17 Data Test"
    sensor_datapoint: 17 

One note about ESPHome: while editing config file, “Upload” is not enabled because editor think that ‘text_sensor.tuya’ is an invalid component. But if we save and hit compile (or upload outside editor), everything works fine…code is compiled and uploaded. I’m pretty sure this is an ESPHome bug from this new ‘external_component’ feature.

Yes, the data is correct.

There is a struct for this data: VVVV00CCCC00PPPP, where VVVV - Voltage, CCCC - Current and PPPP - Active Power. There are unit convertions:
VVVV * 0.1 → V (volts) and you are right here!
CCCC * 0.001 → A (amperes)
PPPP * 0.1 → W (watts)

I will modify my fix tomorrow and remove dots and data size because it was done of debugging purpose. So final string for dp=6 will look like 04F500023B00002E

What is dp=17 I do not know :frowning: but you could try to find correlation between zmai’s displayed values and data from log.

Also just as a guess try to set time_id for tuya component, maybe dp=17 depends on time synchronization.