Posted

in

by


Tuya 3-phase energy meter and Home Assistant

The issue with spike power readings on phase B /

So, if you bought a cheap (~70โ‚ฌ) Tuya 3-phase zigbee energy meter (with 3 clamps), you’ve probably noticed strange readings on a phase B and C (39xxx W) in .

Tuya 3-phase clamp meter (zigbee)

See the spike:

Power measurement with a spike because of negative current

It happens to me when my micro-solar inverter exports energy to the grid and the power should be negative. It also happened when I connected the clamps wrongly. Be attentive to the white arrow (current direction) on the clamps!

I suspect that some programmer @Tuya used a wrong datatype (unsigned smallint) when programming a device firmware.

Tuya 3-phase clamp meter in a cabinet

Other users have similar issues. There are some discussions (1, 2) on GitHub, the issue is stale and, obviously, it can not be easily solved in zigbee2mqtt component because Tuya reports wrong power measurements.

The workaround

I’ve created a new template sensor for ‘phase B’ power in the file (configuration.yaml) which subtracts 39330 from the reading.

#tuya patch, shows negative power if exporting
template:
  - sensor:
      - name: "Tuya power b (patch)"
        unique_id: "tuya_power_b_2"
        state: >
          {% if states('sensor.tuyaelectricitymeter_power_b') | float(0) > 5000 %}
                  {{(states('sensor.tuyaelectricitymeter_power_b') | float(0)-39330) | round (2) }}
          {% else %}
                  {{(states ('sensor.tuyaelectricitymeter_power_b') | float(0)) |round(2) }}
          {% endif %}
        availability: >
          {{ states('sensor.tuyaelectricitymeter_power_b') | is_number }}
        unit_of_measurement: "W"
        device_class: power

This is not a real solution, but now I can see normal power values for a ‘patched’ phase B. I can use these patched values further (to calculate consumption, export etc.). Until a new firmware arrives (if ever), it’s good enough.

I’ve also created a new ‘Total power’ sensor, which simply summarizes Phase A + Phase B (patched) + Phase C:

- sensor:
      - name: "Tuya real total power"
        unique_id: tuya_real_total_power
        state: >
          {{ (states('sensor.tuyaelectricitymeter_power_a') | float(0) + states('sensor.tuya_power_b_real_consumption') | float(0) + states('sensor.tuyaelectricitymeter_power_c') | float(0)) | round(2) }}
        availability: >
          {{ states('sensor.tuyaelectricitymeter_power_a') | is_number and states('sensor.tuya_power_b_real_consumption') | is_number and states('sensor.tuyaelectricitymeter_power_c') | is_number }}
        unit_of_measurement: "W"
        device_class: power

*if you’re using the code above, replace ‘tuya_power_b_real_consumption‘ with the name of your patched sensor.

Otherwise, the integration works quite nicely and provides measurements like power, energy, current, frequency, voltage, power factor (not sure what it is) over all 3 phases, and also temperature.

Home assistant integration of Tuya 3-phase zigbee meter

If you have any ideas on how to solve this issue at its roots (the device)? Comment here or reply to the thread on Mastodon.



Comments

9 responses to “Tuya 3-phase energy meter and Home Assistant”

  1. Beko Pharm Avatar

    @tomi test comment ๐Ÿ˜

    1. Tomi Avatar
      Tomi

      Thanks! Are comments federated too? How did you post reply? Via reply form below the post or from fediverse?

  2. Tomi the Slav and 1024 others Avatar

    @tomi Yay, WordPress post is visible on Mastodon ๐Ÿ™‚

  3. Walter Avatar
    Walter

    Hi, I am using the same device but then with Domoticz instead of Home Assistant.
    I noticed that when my solar panels are producing more power than I consume the power is reported negative but the energy is still positive (see also my github remark below). Do you see the same with zignee2mqtt and Home Assistant?

    https://github.com/zigbeefordomoticz/z4d-certified-devices/issues/38#issuecomment-1879031266

    1. Tomi Avatar
      Tomi

      I don’t use energy sensors from Tuya. Yes, they’re always growing, no negatives.
      I created some additional sensors in HA: Export-to-the-grid (If power is negative, convert to positive)
      I also created my own consumption sensor (Riemann integration from power). For the solar, I created a new sensor (Aqara smart socket). HomeAssistant then does the magic and calculates how much I spent from the grid and how much from the PV.

  4. Andrea Avatar
    Andrea

    I have a slightly different problem. During normal operation, the voltage and amp reading are accurate (within tolerance) but the reported power is way off.

    For example the reading 3.111A and 227.6V, power is 10065.622W. I have tested 2 devices (I have bought 4) and both devices have the same problem, regardless of the phase. Same problem on Tuya app and HA via Z2M. Any idea how to fix this?

    1. Tomi Avatar
      Tomi

      Sorry, but I have no idea ๐Ÿ™‚

  5. Tms Avatar
    Tms

    Hi i have same device but no entities in HA do you any solution for This? I tried some quirks but still not working anybody to help?

    1. Tomi Avatar
      Tomi

      Entities should appear automatically after adding via zigbee2mqtt integration.
      Does z2m recognize it?

Leave a Reply

Your email address will not be published. Required fields are marked *