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 support for Aqara WXKG11LM controller under ZHA #141

Merged
merged 3 commits into from
Oct 31, 2020
Merged

Conversation

ilarrain
Copy link
Contributor

No description provided.

@xaviml
Copy link
Owner

xaviml commented Sep 29, 2020

Hi @ilarrain,

Thanks for your contribution. What is each of the actions you integrated? Single, double, triple, and quadruple? If so, I would map it to be "single", "double", "triple", "quadruple". I can change it in your branch if you let me know about the actions.

Cheers,
Xavi M.

@ilarrain
Copy link
Contributor Author

ilarrain commented Oct 28, 2020

Hi @XaviMi,
Sorry for the delay.

Thanks for your contribution. What is each of the actions you integrated? Single, double, triple, and quadruple?

Indeed, the "value" argument corresponds to the number of clicks: 1: single, 2: double, 3: triple, and 4: quadruple.

If so, I would map it to be "single", "double", "triple", "quadruple". I can change it in your branch if you let me know about the actions.

Please do. My Python skills are pretty limited.

Regards,
Ignacio

@xaviml
Copy link
Owner

xaviml commented Oct 28, 2020

Hi @ilarrain,

Thanks for your response. I will go ahead and change it from your branch, no worries. However, I have a question for you about this. I just realised that the z2m and deconz integration for this controller does not support triple and quadruple events, but rather "single", "double", "hold" and "release". Could you please confirm that these actions are coming from WXKG11LM and not WXKG01LM? In fact, could you provide the ZHA events for the 4 actions?

Cheers,
Xavi M.

@ilarrain
Copy link
Contributor Author

ilarrain commented Oct 28, 2020

@xaviml
Yes, I've verified:
The hardware:
20201028_003809_2

The event implementation:
https://github.com/zigpy/zha-device-handlers/blob/085116ca0854ad773ba4137d3c447564df97e653/zhaquirks/xiaomi/aqara/switch_aq2.py#L82

The device in HA:
Captura de pantalla de 2020-10-28 00-54-52

Events:
quadruple click:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:33:7c:65",
        "unique_id": "00:15:8d:00:02:33:7c:65:1:0x0006",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 32768,
            "attribute_name": "Unknown",
            "value": 4
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-10-28T03:48:21.268225+00:00",
    "context": {
        "id": "6c36250c18d011eb954f07e38b96ea78",
        "parent_id": null,
        "user_id": null
    }
}

triple click:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:33:7c:65",
        "unique_id": "00:15:8d:00:02:33:7c:65:1:0x0006",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 32768,
            "attribute_name": "Unknown",
            "value": 3
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-10-28T03:48:18.705478+00:00",
    "context": {
        "id": "6aaf195318d011ebb20c01157dd8ea21",
        "parent_id": null,
        "user_id": null
    }
}

double click:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:33:7c:65",
        "unique_id": "00:15:8d:00:02:33:7c:65:1:0x0006",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 32768,
            "attribute_name": "Unknown",
            "value": 2
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-10-28T03:48:15.984228+00:00",
    "context": {
        "id": "690fded218d011eb995e8ba0fa210c29",
        "parent_id": null,
        "user_id": null
    }
}

single click:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:33:7c:65",
        "unique_id": "00:15:8d:00:02:33:7c:65:1:0x0006",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 0,
            "attribute_name": "on_off",
            "value": 1
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-10-28T03:48:13.450083+00:00",
    "context": {
        "id": "678d355318d011ebba8fabeb943ffbd0",
        "parent_id": null,
        "user_id": null
    }
}

Regards,
Ignacio

@ilarrain
Copy link
Contributor Author

I've updated the HA caption, as previous one was of another device (same button, but other ID).
The single click has a different attribute than the multiple clicks, which is reflected in the ZHA quirk implementation.

@xaviml
Copy link
Owner

xaviml commented Oct 28, 2020

Hi @ilarrain,

I added support for this controller for ZHA. Does ZHA fire any event in case of holding an releasing the button? If so, could you send the ZHA events? I would like to add that if possible.

Cheers,
Xavi M.

@ilarrain
Copy link
Contributor Author

It doesn't.
It sends 2 "on_off" attribute updates, with values 0 and 1, just a couple milliseconds apart upon button release, no matter how long the press.

Evento 31 desencadenado 2:00:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:33:7c:65",
        "unique_id": "00:15:8d:00:02:33:7c:65:1:0x0006",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 0,
            "attribute_name": "on_off",
            "value": 1
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-10-28T05:00:17.699472+00:00",
    "context": {
        "id": "7901485118da11eb98e8ad60cceeb7ee",
        "parent_id": null,
        "user_id": null
    }
}
Evento 30 desencadenado 2:00:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:33:7c:65",
        "unique_id": "00:15:8d:00:02:33:7c:65:1:0x0006",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 0,
            "attribute_name": "on_off",
            "value": 0
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-10-28T05:00:17.695713+00:00",
    "context": {
        "id": "7900b57518da11ebabf3dd0971bac9f5",
        "parent_id": null,
        "user_id": null
    }
}

@ilarrain
Copy link
Contributor Author

ilarrain commented Oct 28, 2020

Mapping works great, but it's missing the mapping for "0" value:

2020-10-28 14:33:36.624073 WARNING control_bano: Unexpected error in worker for App control_bano:
2020-10-28 14:33:36.626337 WARNING control_bano: Worker Ags: {'id': 'c1ba6ca904044b6aa995f3cffd8f1051', 'name': 'control_bano', 'objectid': '012c678ed36449aea62d76997a1aff9e', 'type': 'event', 'event': 'zha_event', 'function': <bound method ZHAIntegration.callback of <cx_core.integration.zha.ZHAIntegration object at 0x74899b38>>, 'data': {'device_ieee': '00:15:8d:00:02:33:7c:65', 'unique_id': '00:15:8d:00:02:33:7c:65:1:0x0006', 'endpoint_id': 1, 'cluster_id': 6, 'command': 'attribute_updated', 'args': {'attribute_id': 0, 'attribute_name': 'on_off', 'value': 0}}, 'pin_app': True, 'pin_thread': 4, 'kwargs': {'device_ieee': '00:15:8d:00:02:33:7c:65', '__thread_id': 'MainThread'}}
2020-10-28 14:33:36.628757 WARNING control_bano: ------------------------------------------------------------
2020-10-28 14:33:36.632096 WARNING control_bano: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 838, in async_worker
    await funcref(args["event"], data, self.AD.events.sanitize_event_kwargs(app, args["kwargs"]))
  File "/config/appdaemon/apps/controllerx/cx_core/integration/zha.py", line 34, in callback
    action = self.controller.get_zha_action(data)
  File "/config/appdaemon/apps/controllerx/cx_devices/aqara.py", line 123, in get_zha_action
    return mapping[clicks]
KeyError: 0
2020-10-28 14:33:36.634131 WARNING control_bano: ------------------------------------------------------------

I don't know what the "0" value should be mapped to. "release", "single_release", "ignore", "off", "".
It's not triggered on multiple presses, only on single press, and I see no use for it.

@xaviml
Copy link
Owner

xaviml commented Oct 28, 2020

Hi @ilarrain,

Thanks for pointing that out. I added a default action of empty string, so any unexpected action will be ignored.

For the moment is not worth adding the hold-release functionality since it is not working as expected. So this can be now merged. I will wait until you try it out again, and I will merge the PR.

Gracias! :)

@xaviml xaviml merged commit cdcb74d into xaviml:dev Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants