zigpy / zha-device-handlers

ZHA device handlers bridge the functionality gap created when manufacturers deviate from the ZCL specification, handling deviations and exceptions by parsing custom messages to and from Zigbee devices.
Apache License 2.0
725 stars 672 forks source link

[Device Support Request] Zemismart Tuya Zigbee 3 Phase Energy Meter (TS0601 by _TZE200_ves1ycwx) #2757

Open Scorpio256 opened 10 months ago

Scorpio256 commented 10 months ago

Problem description

No entity found.

Here is some diagnosting data https://github.com/sprut/Hub/issues/2585

Solution description

As far as I understand, something to do with quirks is required for this to work properly with Zigbee Home Assistant, and the device needs to be opted into ZHA. I think that's all that's necessary?

Screenshots/Video

No response

Device signature

Device signature ```json [Paste the device signature here] ```

Diagnostic information

Diagnostic information ```json "data": { "ieee": "**REDACTED**", "nwk": 48283, "manufacturer": "_TZE200_ves1ycwx", "model": "TS0601", "name": "_TZE200_ves1ycwx TS0601", "quirk_applied": false, "quirk_class": "zigpy.device.Device", "quirk_id": null, "manufacturer_code": 4098, "power_source": "Mains", "lqi": 255, "rssi": -44, "last_seen": "2023-11-17T11:53:09", "available": true, "device_type": "Router", "signature": { "node_descriptor": "NodeDescriptor(logical_type=, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=, mac_capability_flags=, manufacturer_code=4098, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)", "endpoints": { "1": { "profile_id": "0x0104", "device_type": "0x0051", "input_clusters": [ "0x0000", "0x0004", "0x0005", "0xef00" ], "output_clusters": [ "0x000a", "0x0019" ] } }, "manufacturer": "_TZE200_ves1ycwx", "model": "TS0601" }, "active_coordinator": false, "entities": [], "neighbors": [], "routes": [], "endpoint_names": [ { "name": "SMART_PLUG" } ], "user_given_name": "ZHA - METER - Main power", "device_reg_id": "462e6e24bbed327d795732059be0fde4", "area_id": null, "cluster_details": { "1": { "device_type": { "name": "SMART_PLUG", "id": 81 }, "profile_id": 260, "in_clusters": { "0x0000": { "endpoint_attribute": "basic", "attributes": { "0x0001": { "attribute_name": "app_version", "value": 68 }, "0x0004": { "attribute_name": "manufacturer", "value": "_TZE200_ves1ycwx" }, "0x0005": { "attribute_name": "model", "value": "TS0601" } }, "unsupported_attributes": {} }, "0x0004": { "endpoint_attribute": "groups", "attributes": {}, "unsupported_attributes": {} }, "0x0005": { "endpoint_attribute": "scenes", "attributes": {}, "unsupported_attributes": {} }, "0xef00": { "endpoint_attribute": null, "attributes": {}, "unsupported_attributes": {} } }, "out_clusters": { "0x0019": { "endpoint_attribute": "ota", "attributes": {}, "unsupported_attributes": {} }, "0x000a": { "endpoint_attribute": "time", "attributes": {}, "unsupported_attributes": {} } } } } } ```

Logs

No response

Custom quirk

No response

Additional information

No response

Scorpio256 commented 10 months ago

https://vi.aliexpress.com/item/1005006034226090.html

Scorpio256 commented 10 months ago

https://github.com/zigpy/zha-device-handlers/blob/fb794323fb11014c41843bebc5825bc9004cd23a/zhaquirks/tuya/ts0601_din_power.py#L245

I tried to add a model for my device here and one sensor appeared in Home Assistant: state_increasing

image

dkssn commented 9 months ago

Looking forward to this one too.

It appears that Zigbee2mqtt already supports it: https://zigbee.blakadder.com/Zemismart_SPM02-D2TZ.html

It binds successful but no entities besides LQI and RSSI.

image
blka commented 9 months ago

duplicate of #2463. see this topic about SPM01 and SPM02 (is what you need) https://github.com/zigpy/zha-device-handlers/pull/2603

blka commented 9 months ago

HowTo for someone like me:

  1. create directory for custom quirks, eg /config/zha_quirks
  2. setup custom quirk directory in configuration.yml
    zha:
    enable_quirks: true
    custom_quirks_path: /config/zha_quirks
  3. put this quirk into custom_quirks directory: ts0601_din_power.py
  4. you can restart HA now, some metrics should be available in zha gui under your device (SPM02), eg "sensor summation_delivered" which can be added to your energy card right now.

The next steps are for people, who dont want to wait until zha core changes for 3 phase will be merged into official HA:

  1. create directory /config/custom_components/zha - yes, after few stepst, you will overwrite your ZHA with custom one:)
  2. go into this directory and wget repo branch, where all needed changes was made:
    cd /config/custom_components/zha
    wget https://codeload.github.com/Roeland54/core/zip/refs/heads/feature/3phase-2023-12
    mv 3phase-2023-12 3phase-2023-12.zip
    unzip 3phase-2023-12.zip
    mv core-feature-3phase-2023-12/homeassistant/components/zha/* .
    rm -rf 3phase-2023-12.zip core-feature-3phase-2023-12
  3. in web ui, under dev tools, check configuration. if everything is fine, restart HA
  4. after restart, goto your device, new stuff should appear. if ZHA didn't goes up, just reload again (was needed for me)
  5. profit

remember to subscribe to PRs, to have info about merges to official one. in the future you will need to remove this custom zha to have your installation updated.

Scorpio256 commented 9 months ago

HowTo for someone like me:

  1. create directory for custom quirks, eg /config/zha_quirks
  2. setup custom quirk directory in configuration.yml
zha:
  enable_quirks: true
  custom_quirks_path: /config/zha_quirks
  1. put this quirk into custom_quirks directory: ts0601_din_power.py
  2. you can restart HA now, some metrics should be available in zha gui under your device (SPM02), eg "sensor summation_delivered" which can be added to your energy card right now.

The next steps are for people, who dont want to wait until zha core changes for 3 phase will be merged into official HA: 7. create directory /config/custom_components/zha - yes, after few stepst, you will overwrite your ZHA with custom one:) 8. go into this directory and wget repo branch, where all needed changes was made:

cd /config/custom_components/zha
wget https://codeload.github.com/Roeland54/core/zip/refs/heads/feature/3phase-2023-12
mv 3phase-2023-12 3phase-2023-12.zip
unzip 3phase-2023-12.zip
mv core-feature-3phase-2023-12/homeassistant/components/zha/* .
rm -rf 3phase-2023-12.zip core-feature-3phase-2023-12
  1. in web ui, under dev tools, check configuration. if everything is fine, restart HA
  2. after restart, goto your device, new stuff should appear. if ZHA didn't goes up, just reload again (was needed for me)
  3. profit

remember to subscribe to PRs, to have info about merges to official one. in the future you will need to remove this custom zha to have your installation updated.

image Don't think it is working correctly.

blka commented 9 months ago

SOA1

maiandrei commented 8 months ago

https://codeload.github.com/Roeland54/core/zip/refs/heads/feature/3phase-2023-12

Hi! The aforementioned link is not valid anymore. Does it work for you? Thanks

blka commented 8 months ago

@maiandrei, base on author activity, branch name is now with "-4" at the end, so https://codeload.github.com/Roeland54/core/zip/refs/heads/feature/3phase-2023-12-4

see https://github.com/Roeland54/core/branches

tbaumann commented 8 months ago

I tried. The Meter device has no new entries.

checked out github.com/Roeland54/core branch feature/3phase-2023-12-4 to /config/custom_components/zha

Is there a clever way to make sure the custom component is indeed used?

blka commented 8 months ago

Check quirk location and configuration. Works with z2m by default…

tbaumann commented 7 months ago

Check quirk location and configuration. Works with z2m by default…

Thanks. I assumed I need the quick OR the branch.

tbaumann commented 6 months ago

Hope this can be merged soon. Staying on a custom branch for too long gives me the heebie-jeebies.

mathmorier commented 4 months ago

I Just fellow the steps, To made working I add in the code file ts0601_din_power.py the correcte number of my device _TZE200_v9hkz2yn

image

I reload the zha configuration and that was good

Mow I get this infos : image

mrehanabbasi commented 4 months ago

@mathmorier Yes, but you only get values for one phase.

mathmorier commented 4 months ago

@mrehanabbasi You don't thinks is the add or avrage of the 3 phase ?

mrehanabbasi commented 4 months ago

Nope, it's just one phase.

mathmorier commented 4 months ago

@mrehanabbasi You have an idea to correct that ?

mrehanabbasi commented 4 months ago

@mathmorier One possible workaround is to replace zha with a custom one like https://github.com/Roeland54/core

el3m3l3k commented 3 months ago

Dear community, any news on the topic? I am a ZHA fan and the unfortunate owner of a Zemismart SPM02-D2TZ (TS0601_TZE200_v9hkz2yn). I followed steps 1-4 from @blka, and corrected the name of the device as @mathmorier - luckily, now I can see one "Summation delivered" sensor instead of 100,000 warnings per hour in the log, but it would be great to have the full functionality of the device available. Is there any chance that it will be added to ZHA core and merged into official HA?

rrataj commented 3 months ago

Hey There! I created a quirk for _TZE200_v9hkz2yn version which supports 3 phase Voltage, Current and Power stats: https://github.com/rrataj/zha-device-handlers/blob/0a6b19ab591378c53f6a8887e6c65b76ea31084b/zhaquirks/tuya/ts0601_din_power_3.py

Hope that helps someone :)

el3m3l3k commented 3 months ago

@rrataj - amazing job! All functionalities are unlocked :) I have removed the old quirk, uploaded yours, picked up a 2kW hairdryer, and played a bit in the tester, finding what follows:

  1. This is what "Reconfigure" device shows as identified with your quirk: reconfigure

  2. The sensors for the first phase are duplicated (maybe I did something wrong?): sensors

  3. Besides being duplicated, the first phase works very accurately for all 3 sensors (Power, Voltage, Current).

  4. The second phase shows only current correctly :( Voltage and Power are significantly lower than it should be.

  5. I was not able to identify any electrical socket or light switch in my house that would change something in the readings for phase 3 (it looks like frozen).

  6. Not sure how the "Summation delivered" works... it should aggregate value from all 3 phases, right?

rrataj commented 3 months ago

Hey! Thanks :) For answer to your question no 2 see here: https://github.com/zigpy/zha-device-handlers/issues/3184#issuecomment-2178663005

Basically 1st entry shows always the same value as 2nd entry (1st entry was suppose to be a total sum for all phases, but it's not working yet, while 2nd entry shows 1st phase)

Regarding 3,4,5 I think you may just connect it in a wrong way. You need to connect all 3 phase wires to different phases (adequate to Z, Y, Z). Please try to change wires for phase 2 with phase 3 and check again (Or phase 1 with 2, hard to tell which one is the X,Y,Z). I don't have access to device right now so can't check it.

Regarding 6 - Yes, I think it's aggregated total for all 3 phases.

el3m3l3k commented 3 months ago

Thank you for such a quick response :) I didn't think about the order of the wires. Great advice! The only thing is this electrical switchgear box in my house is a true nightmare. I'm already traumatized by the installation of the device only, but I may mobilize myself to experiment with changing it through the weekend. I'll let you know how it went ;)

vasektomas commented 3 months ago

I also would like to thank you. It's perfect! Off topic. Does anybody know what command can be used to clear internal values of the summation received and the summation delivered?

chriexpe commented 2 months ago

Hey There! I created a quirk for _TZE200_v9hkz2yn version which supports 3 phase Voltage, Current and Power stats: https://github.com/rrataj/zha-device-handlers/blob/0a6b19ab591378c53f6a8887e6c65b76ea31084b/zhaquirks/tuya/ts0601_din_power_3.py

Hope that helps someone :)

Thanks for that quirk, I have one that is almost identical, _TZE204_v9hkz2yn, I tried yours, changed the device name and it unfortunately didn't work, tho if I reconfigure it detect something, where do I extract more info about my device?

### UPDATE I had to reboot Home Assistant after adding the Power Meter in order for it to use that Quirk, so basically: Add Quirk > Fully Reboot > Add Power Meter > Fully Reboot

image

pomianowski commented 2 months ago

Hey @rrataj, thanks for the quirk but it does not work out of the box for the _TZE200_x8fp01wi.

I modified the signature and move everthing to a separate class,

class TuyaThreePhasePowerMeter(CustomDevice):
    """Tuya 3-Phase Power Meter device."""

    def __init__(self, *args, **kwargs):
        """Init device."""
        self.switch_bus = Bus()
        self.clamp_bus = {}
        for i in ["power", "energy"]:
            self.clamp_bus[i] = {}
            for j in ["abc", "a", "b", "c"]:
                self.clamp_bus[i][j] = Bus()
        super().__init__(*args, **kwargs)

    signature = {
        MODELS_INFO: [("_TZE200_x8fp01wi", "TS0601")],
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    TuyaManufClusterAttributes.cluster_id,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            242: {
                PROFILE_ID: 41440,
                DEVICE_TYPE: 97,
                INPUT_CLUSTERS: [],
                OUTPUT_CLUSTERS: [33] # 0x0021
            }
        },
    }

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    ZemismartManufCluster,
                    ZemismartElectricalMeasurement,
                    ZemismartPowerMeasurement,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            10: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.METER_INTERFACE,
                INPUT_CLUSTERS: [
                    # EnergyA,
                    PowerA,
                ],
            },
            20: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.METER_INTERFACE,
                INPUT_CLUSTERS: [
                    # EnergyB,
                    PowerB,
                ],
            },
            30: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.METER_INTERFACE,
                INPUT_CLUSTERS: [
                    # EnergyC,
                    PowerC,
                ],
            }
        }
    }

however, the base sensor does not work, as if the counting is not understandable for the class, just like @el3m3l3k's.

there is a signature:

{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.FullFunctionDevice|MainsPowered|RxOnWhenIdle|AllocateAddress: 142>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0051",
      "input_clusters": [
        "0x0000",
        "0x0004",
        "0x0005",
        "0xef00"
      ],
      "output_clusters": [
        "0x000a",
        "0x0019"
      ]
    },
    "242": {
      "profile_id": "0xa1e0",
      "device_type": "0x0061",
      "input_clusters": [],
      "output_clusters": [
        "0x0021"
      ]
    }
  },
  "manufacturer": "_TZE200_x8fp01wi",
  "model": "TS0601",
  "class": "zigpy.device.Device"
}

Device similar to this one: https://de.aliexpress.com/item/1005005679887461.html?spm=a2g0o.order_list.order_list_main.11.21ef5c5fQ1gjzL&gatewayAdapt=glo2deu

Discussed here: https://github.com/Koenkk/zigbee2mqtt/issues/18750

image

flaneur90 commented 1 month ago

Hey There! I created a quirk for _TZE200_v9hkz2yn version which supports 3 phase Voltage, Current and Power stats: https://github.com/rrataj/zha-device-handlers/blob/0a6b19ab591378c53f6a8887e6c65b76ea31084b/zhaquirks/tuya/ts0601_din_power_3.py

Hope that helps someone :)

Great stuff, plug and play! Thks @rrataj !

ha-primalb commented 1 month ago

@pomianowski - could you please share complete working file for "_TZE200_x8fp01wi" or create new branch of ts0601_din_power_3.py? thank you in advance.

PS: it's a bi-directional meter device, any idea how to get all data and separate up/down?

iorifly commented 3 weeks ago

How to reset a value recorded on a ZigBee device.

Dear all, I have this value (energy = 1696.32kWh) recorded on my “Zemismart three-phase ZigBee meter”

image

I can’t reset it! Does anyone know what to do? If I reset it on Home Assistant, it comes back… because the information is on the device. I’ve already reset it and it still doesn’t work. I’ve already disconnected it from the power supply, and in fact, I received it with these measurements.

Some images that might help.

image

image