Help with ZMAI-90 and ESPHome or Tasmota

No success :confused:
Maybe dpId 17 is the initial date/time for total enery?
I could not find a plausible correlation between this data and initial date/time reported using Tasmota…maybe it’s in EPOC time? I did not tried EPOC, just converting hex to decinal (no success).
See this old log:

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

Also, note that dpId 17 is not being received during normal run, just in startup…either in Tasmota or ESPHome, only during startup.

Could you send TuyaSend8 command with some interval and look for this data to be sure that it will changes or not. Probably it static data like from dp=18.

Keenly watching this thread as someone who’s also fiddling with a tuya-style, rechipped ZMAI-90, I think I can unblock you here

Datapoint 17 does indeed appear to be static regardless of how often TuyaSend8 is performed - the main ones I can see that refresh regularly are DP1 and DP6. Here’s my relevant logging from Tasmota:

16:03:58.972 MQT: tele/tasmota_49FBEA/RESULT = {"TuyaReceived":{"Data":"55AA0307000C060000080986000000000000B2","Cmnd":7,"CmndData":"060000080986000000000000","DpType0Id6":"0x0986000000000000","6":{"DpId":6,"DpIdType":0,"DpIdData":"0986000000000000"}}}
16:04:03.430 MQT: tele/tasmota_49FBEA/RESULT = {"TuyaReceived":{"Data":"55AA030000010104","Cmnd":0,"CmndData":"01"}}
16:04:08.974 MQT: tele/tasmota_49FBEA/RESULT = {"TuyaReceived":{"Data":"55AA03070008010200040000002A42","Cmnd":7,"CmndData":"010200040000002A","DpType2Id1":42,"1":{"DpId":1,"DpIdType":2,"DpIdData":"0000002A"}}}

(note that this is with no load connected)

@jmceara I have changed git branch to tuya-raw-fix.

Here is configuration without basic parts.

...
external_components:
  - source: github://dentra/esphome@tuya-raw-fix 
    components: ["tuya"]

text_sensor:
  - platform: tuya
    id: tuya_raw_test
    sensor_datapoint: 6
    on_value:
      lambda: |
        auto d = tuya::rawdecode(x);
        id(voltage).publish_state((d[0] << 8 | d[1]) * 0.1);
        id(current).publish_state((d[3] << 8 | d[4]) * 0.001);
        id(power).publish_state((d[6] << 8 | d[7]) * 0.1);
sensor:
  - platform: "tuya"
    id: total
    name: "Energy Total"
    sensor_datapoint: 1
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
    unit_of_measurement: "kWh"
    icon: "mdi:sigma"
    device_class: "energy"
  - platform: template
    id: voltage
    name: "Voltage"
    unit_of_measurement: "V"
    icon: "mdi:sine-wave"
    device_class: "voltage"
  - platform: template
    id: current
    name: "Current"
    unit_of_measurement: "A"
    icon: "mdi:current-ac"
    device_class: "current"
  - platform: template
    id: power
    name: "Active Power"
    unit_of_measurement: "W"
    icon: "mdi:flash"
    device_class: "power"
switch:
   - platform: "tuya"
     name: "Power"
     switch_datapoint: 6
     icon: "mdi:power"

I will wait for your feedback and if this part is good we can add some additional features to firmware.

@duckfullstop could you show a line from your log with dp=17?

Ok, good news. Almost everything is ok…just power that doesn’t need to multiply by 0.1, just 1 (or no multiple at all). The informed value is the real Watt… in device display, P=0.04 means 40W.
I’ve double checked with an 120W buld and it’d displayed as P=1.20. I’ve removed * 0.1 and its fine now.
Switch, in my device, is DP16…I have tested before, I just can’t doo right now because i have some devices in production behind this ZMAI :frowning:

Just one observation: I think the power informed by tuyamcu is real power, not calculated. I’m assuming this because Tasmota displays power factor, reactive power and apparente power…but these seens to be calculated. Also, these information looks correct in Tasmota…using some raspberry pi’s connected I was getting power factor of about 0.6…but using a light bulb (incandecente), power factor was 1.0…seens pretty good calculation! These would be a very good additions after we validate our values :wink:

Without real measured power this device is useless. And you right that power factor, reactive power and apparent power are calculated, but they are very accurate because there are absolutely all values for the formula.

Will be able to get it for you tomorrow in theory!

Here’s Datapoint 17:

18:06:32.604 MQT: tele/tasmota_49FBEA/RESULT = {"TuyaReceived":{"Data":"55AA030700101100000C0100003C030001080400009619","Cmnd":7,"CmndData":"1100000C0100003C0300010804000096","DpType0Id17":"0x0100003C0300010804000096","17":{"DpId":17,"DpIdType":0,"DpIdData":"0100003C0300010804000096"}}}

thanks it is look very close. the difference in one byte. it didn’t become clearer :frowning:

0100003C0300010804000096
vs
0100003C030001080400006E

Here is part of configuration to expose additional power sensors.

...
external_components:
  - source: github://dentra/esphome-components
...
  - platform: "energy_monitoring"
    power: power
    voltage: voltage
    current: current
    apparent_power:
      name: "Apparent Power"
    reactive_power:
      name: "Reactive Power"
    power_factor:
      name: "Power Factor"

1 Like

Also I have components for gathering some statistics (today, yesterday, week and month) and support of tariffs (can be used instead of total sensor to adjust or reset value without reflashing right from Home Assistant). So you can get at least all the same features as Tasmota firmware but even more.

The repo is the same: esphome-components/components at master · dentra/esphome-components · GitHub

There maybe a low-detailed description but I can support you here or GitHub.

hi,

finally I got my other zmai-90 WB3S replaced with ESP12E, everything went well in tasmota thanks to your config!

however do you have any idea how to enable the physical button on the zmai90 to switch the relay state?

Great to hear that replacement is working well!

With TYWE3S and ESPHome it can be done with:

switch:
    - platform: "tuya"
      name: Power
      switch_datapoint: <your_switch_dp_id>
      icon: "mdi:power"

In tasmota you should bind tuya dpId to tasmota fnId

@ tesna

did you get the button to work?
Have the same problem and no idea who I find a way for this tipp.
“In tasmota you should bind tuya dpId to tasmota fnId”

regards

I’m trying to contribute support for raw sensors in ESPHome (PR: Tuya raw data usage by dentra · Pull Request #1812 · esphome/esphome · GitHub). The original solution with text_sensor is changed via PR review. Now it is a trigger of Tuya platform. text_sensor support raw datapoints only for debugging purpose (well readable but weorse parseble). In my device I can test only number sensors and it will be nice if someone can test it with raw sensor. @jmceara could you help with your device?

It shoud work with ESPHome 1.19.x. Changes to configuration are minimal - you need to move lambda part of text_sensor to tuya trigger, and remove it after.

...
external_components:
  - source: github://dentra/esphome@tuya-raw-fix 
    components: ["tuya"]
tuya:
  ...
  on_datapoint_update:
    - sensor_datapoint: 6
      datapoint_type: raw
      then:
        - lambda: |-
            id(voltage).publish_state((x[0] << 8 | x[1]) * 0.1);
            id(current).publish_state((x[3] << 8 | x[4]) * 0.001);
            id(power).publish_state((x[6] << 8 | x[7]) * 0.1);  
...

anyone can share setting up sensors to support new “Power Dashboard”
all i have is
image
but i need to setup sensor in kWh
anyone have formulas ?

To convert Wh to kWh just add to your ESPHome sensor:

      accuracy_decimals: 3
      filters:
          - multiply: 0.001

ty! i will try now )