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 #homeassistant.
See the spike:
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.
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 #homeassistant 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.
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.
Leave a Reply