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"}}}