Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Aqara H2 plug #3265

Draft
wants to merge 10 commits into
base: dev
Choose a base branch
from
Draft

Conversation

ChristophCaina
Copy link

Proposed change

This PR should add the Aqara H2 EU Wall-Plug to the Xiaomi Aqara Quirk to address #3187

Additional information

Work in Progress!
Since this is my first work on ZHA Device Handlers at all, I am not even sure if this is the correct approach.
I don't have any way to test this atm - and there are still several unknown topics, such as "unknown cluster_id's" and profile_id's etc.

It would be great, if someone who's more into this could assist... :)

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works

@ChristophCaina
Copy link
Author

there are some things not quite clear to me :-(

comparing the INPUT_CLUSTERS from plug_eu.py with plug.py:

plug_eu.py

            # input_clusters=[0, 2, 3, 4, 5, 6, 9, 1794, 2820]
            # output_clusters=[10, 25]>
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    DeviceTemperature.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    OnOff.cluster_id,
                    Alarms.cluster_id,
                    Metering.cluster_id,
                    ElectricalMeasurement.cluster_id,
                ],

plug.py

            # input_clusters=[0, 4, 3, 6, 16, 5, 10, 1, 2, 2820]
            # output_clusters=[25, 10]>
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Basic.cluster_id
                    PowerConfiguration.cluster_id,
                    DeviceTemperature.cluster_id,
                    Groups.cluster_id,
                    Identify.cluster_id,
                    OnOff.cluster_id,	
                    Scenes.cluster_id,
                    BinaryOutput.cluster_id,
                    Time.cluster_id,
                    ElectricalMeasurement.cluster_id,
                ],

it seems, that IDs 3. 4, 6, 16 are not the same?

Is there a resource about the clusters somewhere?
Also, the endpoints would be interesting if this is documented somewhere :)

@TheJulianJES TheJulianJES added the Xiaomi Request/PR regarding a Xiaomi device label Jul 27, 2024
@TheJulianJES TheJulianJES changed the title [draft] - Add aqara h2 plug Add Aqara H2 plug Aug 3, 2024
@@ -346,3 +346,55 @@ class PlugMAEU01Alt3(PlugMAEU01):
}

replacement = PlugMAEU01.replacement

class PlugAEU001(PlugAEU001)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a missing : at the end here.

@@ -346,3 +346,55 @@ class PlugMAEU01Alt3(PlugMAEU01):
}

replacement = PlugMAEU01.replacement

class PlugAEU001(PlugAEU001)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also can't inherit from the same class that you're creating.
Either use PlugMAEU01 or CustomDevice. CustomDevice might make more sense here, since it seems like there's quite a big difference between the older plugs and this H2 plug.

@TheJulianJES
Copy link
Collaborator

Ideally, we'd use the new v2 quirks API, but I'll try to explain this with an example of the old "API".
As an example of the old API, see the quirk for the original EU plug: zha-device-handlers/zhaquirks/xiaomi/aqara/plug_eu.py#L79-L150 and also my explanation about a possible quirk for this H2 plug below.

class PlugAeu001(CustomDevice):
    """Aqara lumi.plug.aeu001 custom device implementation."""

    # The signature is unaltered. It has to match the device signature exactly for the quirk to apply.
    signature = {
        MODELS_INFO: [("Aqara", "lumi.plug.aeu001")],
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    OnOff.cluster_id,
                    MultistateInput.cluster_id,
                    TemperatureMeasurement.cluster_id,
                    Metering.cluster_id,
                    ElectricalMeasurement.cluster_id,
                    0xfcc0, # this is a custom Aqara cluster, it will be replaced with a implementation in the replacement
                ],
                OUTPUT_CLUSTERS: [
                    Time.cluster_id,
                    Ota.cluster_id,
                ],
            },
            2: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    OnOff.cluster_id,
                ],
                OUTPUT_CLUSTERS: [
                ],
            },
            21: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    AnalogInput.cluster_id,
                ],
                OUTPUT_CLUSTERS: [
                ],
            },
        },
    }

    # This replaces the device signature when exposed to ZHA.
    # We can remove clusters (or even endpoints completely). We can also use custom clusters here.
    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
                INPUT_CLUSTERS: [
                    BasicCluster, # this modified basic cluster catches some special Aqara reports, not sure if needed
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    # OnOff.cluster_id, # we can remove the `OnOff` cluster from endpoint 1, as it doesn't seem to work according to the linked issue
                    MultistateInput.cluster_id,
                    TemperatureMeasurement.cluster_id, # if this shows wrong temperatures, remove it completely
                    MeteringCluster, # we're replacing this with a custom cluster
                    ElectricalMeasurementCluster, # we're replacing this with a custom cluster
                    OppleCluster, # we're adding our Aqara cluster implementation here
                ],
                OUTPUT_CLUSTERS: [
                    Time.cluster_id,
                    Ota.cluster_id,
                ],
            },
            2: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    OnOff.cluster_id,
                ],
                OUTPUT_CLUSTERS: [
                ],
            },
            21: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    AnalogInputCluster, # we're using a custom cluster here too to "catch" some energy reports and forward it to the main ElectricalMeasurement cluster on endpoint 1
                ],
                OUTPUT_CLUSTERS: [
                ],
            },
        },
    }

@ChristophCaina
Copy link
Author

ChristophCaina commented Aug 4, 2024

Hi, thanks ... there are still some topics I don't really understand - and I couldn't really find any documentation about it...

  1. Where exactly is the information about the clusters available?
    I got most clusters from other quirks - but sometimes, the same id seems to have different cluster's...
    just like shown in my example with plug vs. plug_eu

So I would like to know, where I can find the refference for such cluster_id's - and where you got the information for cluster ID's 16 & 1026 from... :)

                    MultistateInput.cluster_id,
                    TemperatureMeasurement.cluster_id,

Can you also explain me, why you are using ON_OFF_SWITCH as deviceType in 1: here?
Shouldn't this also be the Plug?

Getting some answers to that, would also help me in the future, better to understand how this works :)

Thanks for your help :) 👍

[EDIT]
Also, a stupid question maybe, but since it is the first time I am working on such things... how can I add this as a custom quirk to see, if it actually working?

I 've already created a folder structure to my HA installation
grafik

and modified the config

zha:
  zigpy_config:
    enable_quirks: true
    custom_quirks_path: /config/zha/custom

but I haven't found more documentation - do I only need to place the quirk into a seperate py file?
f.e. "plug_eu.py" with only the added changes from this PR ?

@PureTryOut
Copy link

Also, a stupid question maybe, but since it is the first time I am working on such things... how can I add this as a custom quirk to see, if it actually working?

https://community.home-assistant.io/t/zigbee-guide-how-to-setup-local-custom-device-handler-quirks-in-zha-integration/683473

Thank you for working on this! I just installed this device today and was sad to see it was missing some options and had a duplicated toggle, glad to see someone is working on this!

Let me know when this is ready for testing, I'd be glad to help out.

@TheJulianJES TheJulianJES added the help wanted Extra attention is needed label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed Xiaomi Request/PR regarding a Xiaomi device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants