zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

[New device support]: Tuya 213E Ultrasonic water meter (_TZE200_zlwr0raf)

Open Takacsk76 opened this issue 2 years ago • 22 comments

Link

https://www.aliexpress.com/item/1005007308058989.html?spm=a2g0o.order_list.order_list_main.5.79851802N0tQyH

Other: https://www.tuyaexpo.com/product/1105384

What I learned

Factory name of the device: Zigbee阀控超声波水表-vdevo In English: Zigbee valve controlled ultrasonic water meter-vdevo

Data points in the Tuya app: Tuya Smart datapoints

Database entry

{"id":56,"type":"EndDevice","ieeeAddr":"0xa4c1389cbaf936cd","nwkAddr":807,"manufId":4417,"manufName":"_TZE200_zlwr0raf","powerSource":"Battery","modelId":"TS0601","epList":[1],"endpoints":{"1":{"profId":260,"epId":1,"devId":81,"inClusterList":[4,5,61184,0],"outClusterList":[25,10],"clusters":{"genBasic":{"attributes":{"65503":"��|.i��|.i��|.i\u0004�|.f\u0005�|.\u0012","65506":56,"65508":0,"stackVersion":0,"dateCode":"","appVersion":72,"modelId":"TS0601","manufacturerName":"_TZE200_zlwr0raf","powerSource":3,"zclVersion":3,"hwVersion":1}}},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":72,"stackVersion":0,"hwVersion":1,"dateCode":"","zclVersion":3,"interviewCompleted":true,"meta":{},"lastSeen":1726666275707}

Zigbee2MQTT version

1.40.1

Comments (starting point)

I tried to make the configuration based on another type: https://github.com/Koenkk/zigbee2mqtt/issues/21255

ZHA has exactly this configuration, but it should be transferred to Z2M: https://github.com/zigpy/zha-device-handlers/issues/3301

Tuya development

develop1 develop2

Output from the script in tuya_dev:

{
"1":"Water consumption",
"2":"Month consumption",
"3":"Daily consumption",
"4":"Report period set",
"5":"Warning",
"6":"Month and daily frozen time set",
"16":"Meter ID",
"18":"Reverse Water Consumption",
"21":"Instantaneous Flow Rate",
"22":"Working temperature",
"26":"Power supply voltage"
}

Results:

About Exposes State

I don't really understand how Zigbee and Tuya clusters work.

External definition

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const modernExtend = require('zigbee-herdsman-converters/lib/modernExtend');
const e = exposes.presets;
const ea = exposes.access;
const tuya = require('zigbee-herdsman-converters/lib/tuya');


const definition = {
    fingerprint: [
        {
            modelID: 'TS0601',
            manufacturerName: '_TZE200_zlwr0raf',
        },
    ],
    model: 'TS0601_v12',
    vendor: 'Tuya',
    description: 'Water meter',
    fromZigbee: [tuya.fz.datapoints],
    toZigbee: [tuya.tz.datapoints],
    onEvent: tuya.onEventSetTime,
    configure: tuya.configureMagicPacket,
    exposes: [
        e.numeric('water_consumption', ea.STATE).withUnit('L').withDescription('Total water consumed'),
        e.numeric('month_consumption', ea.STATE).withDescription('Month consumption'),
        e.numeric('daily_consumption', ea.STATE).withDescription('Daily consumption'),
        e.numeric('month_and_daily_frozen_time_set', ea.STATE).withDescription('Month Daily Frozen Set'),
        e.enum('report_period', ea.STATE_SET, ['1h', '2h', '3h', '4h', '6h', '8h', '12h', '24h']).withDescription('Report interval'),
        e.numeric('warning', ea.STATE).withDescription('Fault code'),
        e.text('meter_id', ea.STATE).withDescription('Meter ID (ID of device)'),
        e.numeric('reverse_water_consumption', ea.STATE).withDescription('Reverse water flow'),
        e.numeric('instantaneous_flow_rate', ea.STATE).withDescription('Inst flow rate'),
        e.numeric('working_temperature', ea.STATE).withUnit('°C').withDescription('Water Temperature'),
        e.numeric('power_supply_voltage', ea.STATE).withUnit('V').withDescription('Battery voltage'),
    ],
    meta: {
        // All datapoints go in here
        tuyaDatapoints: [
            [1,'water_consumption', tuya.valueConverter.raw],
            [2,'month_consumption', tuya.valueConverter.raw],
            [3,'daily_consumption', tuya.valueConverter.raw],
            [4,'report_period', tuya.valueConverterBasic.lookup({'1h': tuya.enum(0), '2h': tuya.enum(1), '3h': tuya.enum(2),
                                                                '4h': tuya.enum(3), '6h': tuya.enum(4), '8h': tuya.enum(5),
                                                                '12h': tuya.enum(6), '24h': tuya.enum(7) })],
            [5,'warning', tuya.valueConverter.raw],
            [6,'month_and_daily_frozen_time_set', tuya.valueConverter.raw],
            [16,'meter_id', tuya.valueConverter.raw],
            [18,'reverse_water_consumption', tuya.valueConverter.raw],
            [21,'instantaneous_flow_rate', tuya.valueConverter.raw],
            [22,'working_temperature', tuya.valueConverter.divideBy100],
            [26,'power_supply_voltage', tuya.valueConverter.divideBy100]
        ],
    },
    extend: [
        // A preferred new way of extending functionality.
    ],
};

module.exports = definition;

What does/doesn't work with the external definition?

What works with external definition:

  • Reading out Total water consumed
  • Report period set
  • Reading out the warning (fault) status

What doesn't work with the external definition:

  • Device battery percentage report
  • Setting the device time? ("Last Seen" is -1 hour away from local time)

Template binary sensors

Processing of "Warning" statuses "state": "{{ '{:013b}'.format(state_attr('sensor.water_meter_warning', 'warning') | int)[-1] == '1' }}", [-1]: the sequence number of the bit

      {
        "created_at": "2024-10-02T10:34:55.948720+00:00",
        "data": {},
        "disabled_by": null,
        "domain": "template",
        "entry_id": "01J96CR52CE0F3MK6QW02PAX75",
        "minor_version": 1,
        "modified_at": "2024-10-02T10:34:55.948723+00:00",
        "options": {
          "template_type": "binary_sensor",
          "name": "Water meter battery alarm",
          "state": "{{ '{:013b}'.format(state_attr('sensor.water_meter_warning', 'warning') | int)[-1] == '1' }}",
          "device_class": "problem",
          "device_id": "e88e4ca5742993c7b66d24a10fa3fdee"
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "title": "Water meter battery alarm",
        "unique_id": null,
        "version": 1
      }
      {
        "created_at": "2024-10-02T10:34:15.140108+00:00",
        "data": {},
        "disabled_by": null,
        "domain": "template",
        "entry_id": "01J96CPX747X3PDNE0WK1Y1GBG",
        "minor_version": 1,
        "modified_at": "2024-10-02T10:34:15.140112+00:00",
        "options": {
          "template_type": "binary_sensor",
          "name": "Water meter magnetism alarm",
          "state": "{{ '{:013b}'.format(state_attr('sensor.water_meter_warning', 'warning') | int)[-2] == '1' }}",
          "device_class": "problem",
          "device_id": "e88e4ca5742993c7b66d24a10fa3fdee"
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "title": "Water meter magnetism alarm",
        "unique_id": null,
        "version": 1
      },

etc...

HA device data: HA-device

Request:

///If anyone could help me create a working config file I would greatly appreciate it. I'm just trying, but I have no scientific basis. Thanks/// I managed to put something together

Takacsk76 avatar Sep 18 '24 13:09 Takacsk76

Thank you very much! after a couple of months your post gave me light! I'm also struggling with decoding the JSON in month_consumption and daily_consumption but with no success. AFAIK the last position in the buffer is the current state but I had no success implementing it on the external converter.

atanesmarc avatar Oct 10 '24 11:10 atanesmarc

Thank you very much! after a couple of months your post gave me light! I'm also struggling with decoding the JSON in month_consumption and daily_consumption but with no success. AFAIK the last position in the buffer is the current state but I had no success implementing it on the external converter.

I have not yet installed the device in its final location, but it is expected to be ready this week. I didn't know what to do with the JSON data yet, because there is nothing to compare it to. In my opinion, the data could be statistics for the last 7 days and the last 7 months, but this is just a guess (but why only 7 months?).

Takacsk76 avatar Oct 14 '24 11:10 Takacsk76

Is there something already available to add manually ?

danielewyss avatar Nov 01 '24 09:11 danielewyss

As far as I know, there isn't.

Takacsk76 avatar Nov 02 '24 20:11 Takacsk76

I have just acquired a 214C and have just managed to get it paired (the supplied manual described using a Hall Effect button with a magnet - it doesn't exist - you have to long-press when the date is shown) I can see the device OK in Tuya, but unsupported in Z2M. Not yet plumbed in. But hopefully I can contribute or at least test anything others find.

senrabyar avatar Nov 13 '24 20:11 senrabyar

Hi, I received a video from the seller for zigbee pairing:

User Manual===https://drive.google.com/file/d/1BZ7b_sgXukM0FRVaEws1VgDZbckWVEoa/view?usp=sharing

213E===https://drive.google.com/file/d/1q-v2mhXkvjOclElcICHZBHT3yqfJ9d_G/view?usp=sharing

214C===https://drive.google.com/file/d/1gM6k_ndeKYNl9mXyKixQ_uLA6TiDvyAa/view?usp=sharing

Takacsk76 avatar Nov 13 '24 21:11 Takacsk76

Ah thanks, now I have the full manual - after question to the supplier they had sent me just the two relevant pages. The manual in the box is totally different. Your info will certainly help anyone else who discovers this. But that's really outside of this thread on Z2M !

senrabyar avatar Nov 13 '24 22:11 senrabyar

Very welcome. I would also be happy to help implement the integration into Z2M, but no such request has been received so far.

Takacsk76 avatar Nov 13 '24 22:11 Takacsk76

I just need to figure out how to calculate the battery percentage. I'm trying, but I can't.

Takacsk76 avatar Nov 15 '24 08:11 Takacsk76

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Jan 15 '25 00:01 github-actions[bot]

The device is not supported, therefore I think that we would like to keep it open ;-)

danielewyss avatar Jan 15 '25 05:01 danielewyss

I've no idea how many devices are out there needing device to work with MQTT - in my case a 214C - through to HomeAssistant or direct to NodeRed. But I will have to dabble further into this soon - I've already spent £££s buying the device, and will have to spend ££ to get it installed into my house plumbing. I just don't have the time to get my head round external definitions yet, so was hoping it would become a supported device.

senrabyar avatar Jan 15 '25 09:01 senrabyar

I had to fix the processing of template sensors because the binary processing became invalid. I don't even understand how it worked until now?!

'{:013b}'.format(states('sensor.water_meter_warning') | int(0))[-1] == '1'

  {
    "created_at": "2024-10-02T10:34:55.948720+00:00",
    "data": {},
    "disabled_by": null,
    "domain": "template",
    "entry_id": "01J96CR52CE0F3MK6QW02PAX75",
    "minor_version": 1,
    "modified_at": "2024-10-02T10:34:55.948723+00:00",
    "options": {
      "template_type": "binary_sensor",
      "name": "Water meter battery alarm",
      "state": "{{ '{:013b}'.format(states('sensor.water_meter_warning') | int(0))[-1] == '1' }}",
      "device_class": "problem",
      "device_id": "e88e4ca5742993c7b66d24a10fa3fdee"
    },

Takacsk76 avatar Jan 16 '25 22:01 Takacsk76

I've no idea how many devices are out there needing device to work with MQTT - in my case a 214C - through to HomeAssistant or direct to NodeRed. But I will have to dabble further into this soon - I've already spent £££s buying the device, and will have to spend ££ to get it installed into my house plumbing. I just don't have the time to get my head round external definitions yet, so was hoping it would become a supported device.

I don't know either, but I hope it will be added to the list of supported devices one day and maybe they will fix it. I offer to help with testing, but so far no one has contacted me about it. I don't dare buy an officially unsupported Tuya Zigbee device anymore because it can cause problems. I have time, but unfortunately I don't have that much patience. There are too many failures. I'm happy to help you anytime.

This is how I made it:

Image

Takacsk76 avatar Jan 16 '25 22:01 Takacsk76

I got 413E 2w ago hoping it could be added by ZHA but nothing. I cannot pair it. I'll send it back until there will be a solution, if there will... I need a real time precise water meter to discover leaks in the old pipework and toilets and bathrooms, then close a valve automatically and get an alarm. It seemed really promising. So sad!

I could use it with Zigbee2MQTT if it would work, but I have no single device through it, I need to learn how to use it along with ZHA.

One question - can it transmit real-time or every hour? In the user manual it says real time. I need a real-time device. Can anybody suggest anything?

almostlunatic avatar Feb 07 '25 20:02 almostlunatic

I got 413E 2w ago hoping it could be added by ZHA but nothing. I cannot pair it. I'll send it back until there will be a solution, if there will... I need a real time precise water meter to discover leaks in the old pipework and toilets and bathrooms, then close a valve automatically and get an alarm. It seemed really promising. So sad!

I could use it with Zigbee2MQTT if it would work, but I have no single device through it, I need to learn how to use it along with ZHA.

One question - can it transmit real-time or every hour? In the user manual it says real time. I need a real-time device. Can anybody suggest anything?

I also started with ZHA. I switched to Z2M with 30 devices. Both platforms have problems and cannot follow newly appearing devices. I think you should try it too. Temporarily disable ZHA and install Z2M. If you don't like it, you can quickly restore it. Zigbee is a communication channel. Unfortunately, Tuya data is handled very freely by developers. Many device manufacturers just buy the same software components from a third party. The device would be perfect, but the software side is poor. The 213E device sends the clock cyclically. The sending can be set in an interval of 1-24 hours. By default, it sends every 12 hours. I have a 1-hour cycle set. In case of error detection, it sends "Warning" (fault) data immediately. The "Water meter empty pipe alarm" is easy to test.

Takacsk76 avatar Feb 07 '25 21:02 Takacsk76

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Apr 09 '25 00:04 github-actions[bot]

Image I managed to partially integrate the meter

Sthev61800 avatar Apr 09 '25 11:04 Sthev61800

Image I managed to partially integrate the meter

Super! Could you share your work, maybe I can help you. I just installed a 213e and disappointed to not have a z2m support.

bertrandgressier avatar Apr 20 '25 07:04 bertrandgressier

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Jun 20 '25 00:06 github-actions[bot]