ZHA identify event additional data (click_type) for automation

After a few tries, I figured it out. Writing all the steps here in case somebody is new to this.

  1. In your HA, go to developer tools > events (/developer-tools/event) and start listening to zha_event.

  2. In the Aqara switch press the button once. The response will be something like:

    {
        "event_type": "zha_event",
        "data": {
            "device_ieee": "00:11:22:33:44:55:66:77",
            "unique_id": "00:33:44:45:62:6a:e4:d1:1:0x0012",
            "endpoint_id": 1,
            "cluster_id": 18,
            "command": "single",
            "args": {
                "value": 1
            }
        },
        "origin": "LOCAL",
        "time_fired": "2020-06-29T07:53:39.352842+00:00",
        "context": {
            "id": "2a7f8a62bc1041139fdf8a6d287e7fdd",
            "parent_id": null,
            "user_id": null
        }
    }
    

    You need the things listed under data.

  3. In the Automations UI, add a new automation:

    1. Add a new trigger

    2. Select “Event” from the dropdown

    3. set zha_event as the event type

    4. In the event data you want the unique stuff that’s under data in the previous step, but converted into YAML.

      For single click, it should be:

      device_ieee: '00:11:22:33:44:55:66:77'
      unique_id: '00:33:44:45:62:6a:e4:d1:1:0x0012'
      command: single
      args:
        value: 1
      

      For double click, it should be:

      device_ieee: '00:11:22:33:44:55:66:77'
      unique_id: '00:33:44:45:62:6a:e4:d1:1:0x0012'
      command: double
      args:
        value: 2
      

      For shake, it should be:

      device_ieee: '00:11:22:33:44:55:66:77'
      unique_id: '00:33:44:45:62:6a:e4:d1:1:0x0012'
      command: shake
      args:
        value: 18
      

In the end, the entry in automations.yaml should look like:

- id: ikealight
  alias: IKEA light toggle
  trigger:
  - event_data:
      device_ieee: 00:11:22:33:44:55:66:77
      unique_id: 00:33:44:45:62:6a:e4:d1:1:0x0012
      command: single
      args:
        value: 1
    event_type: zha_event
    platform: event
  action:
  - entity_id: light.ikea
    service: light.toggle
16 Likes