ZHA identify event additional data (click_type) for automation

Tags: #<Tag:0x00007f3f16fc5718>

I am trying to build automation based on "zha_event"s received from from my Xiaomi Mi Switch - trying to figure out how to distinguish “single” / “double” / “hold” click actions…

Should I do that in the trigger ? in a command ?
any example could help :slight_smile:

Event 13 fired 5:47 PM:
{
    "event_type": "zha_event",
    "data": {
        "unique_id": "0x059f:1:0x0006",
        "device_ieee": "00:15:8d:00:01:25:63:f6",
        "command": "click",
        "args": {
            "click_type": "double"
        }
    },
    "origin": "LOCAL",
    "time_fired": "2019-06-09T14:47:48.651971+00:00",
    "context": {
        "id": "7aa09b79085a44cd8c1ed7ed243a39b5",
        "parent_id": null,
        "user_id": null
    }
}

Event 9 fired 5:47 PM:
{
    "event_type": "zha_event",
    "data": {
        "unique_id": "0x059f:1:0x0006",
        "device_ieee": "00:15:8d:00:01:25:63:f6",
        "command": "click",
        "args": {
            "click_type": "single"
        }
    },
    "origin": "LOCAL",
    "time_fired": "2019-06-09T14:47:27.221229+00:00",
    "context": {
        "id": "ad2de1e3c6ba411a912d130d3220b3e4",
        "parent_id": null,
        "user_id": null
    }
}

You should include the arguments in your trigger as they are different. I use node-red with “payload.event.args” and “contains” but you should be able to do the same in your automation by including them. Something like this might work, although you may have to format the args differently to include “click_type” as well.

- alias: MiDouble
  trigger:
  - event_data:
      args:
      - double
    command: click
    device_ieee: 00:15:8d:00:01:25:63:f6
    event_type: zha_event
    platform: event
  action:
  - data:
    entity_id: light.some_light
    service: light.turn_on

- alias: MiSingle
  trigger:
  - event_data:
      args:
      - single
      command: click
      device_ieee: 00:15:8d:00:01:25:63:f6
    event_type: zha_event
    platform: event
  action:
  - data:
    entity_id: light.some_light
    service: light.turn_off