Aqara H2 US (WS-K02E) Multi-Action Controller (Device Picker + MQTT support)

Easily map the raw transient button actions of your Aqara Light Switch H2 US (WS-K02E) to control any device, light, fan, or custom script sequence via Zigbee2MQTT.

Import Blueprint

Why Use This Blueprint?

Because Zigbee2MQTT clears the action attribute on this switch back to a blank string almost instantly (in less than a millisecond), standard state-matching automations frequently fail to trigger. This blueprint utilizes specialized dynamic triggers to reliably capture those quick button events.

Features

  • User-Friendly Device Picker: Select your hardware switch directly from a visual dropdown menu without digging for hidden entity strings.
  • Direct MQTT Routing Failover: Optionally type a raw MQTT topic path (e.g., zigbee2mqtt/Office Fandelier) for advanced networking setups.
  • Fully Decoupled Actions: Use the standard UI action sequencer to build complex, multi-step actions (e.g., toggling a fan, setting specific dimming percentages, firing scripts) for any press event.
  • Mapped Actions: Supports Single Press and Double Press behaviors for both the physical hardwired (Top Button) and smart decoupled (Wireless Button) modes.

Raw Blueprint Code

blueprint:
  name: "Aqara H2 US (WS-K02E) Multi-Action Controller"
  description: "A highly customizable controller for the Aqara H2 switch that maps raw transient events to user-defined action sequences."
  domain: automation
  input:
    aqara_device:
      name: Aqara H2 Switch Device
      description: "Select the Aqara H2 hardware device from the list."
      default: ""
      selector:
        device:
          integration: mqtt
          manufacturer: Aqara
    mqtt_topic:
      name: (Optional) Direct MQTT Topic Path
      description: "Alternatively, provide a raw MQTT topic path (e.g., zigbee2mqtt/Office Fandelier) if you aren't using the device picker."
      default: ""
      selector:
        text:

    # --- ACTION SEQUENCES ---
    action_single_top:
      name: Single Press (Top Button) Actions
      description: "Action sequence executed when the top button is pressed once."
      default: []
      selector:
        action:
    action_double_top:
      name: Double Press (Top Button) Actions
      description: "Action sequence executed when the top button is double-clicked."
      default: []
      selector:
        action:
    action_single_wireless:
      name: Single Press (Wireless Button) Actions
      description: "Action sequence executed when the smart/decoupled button is pressed once."
      default: []
      selector:
        action:
    action_double_wireless:
      name: Double Press (Wireless Button) Actions
      description: "Action sequence executed when the smart/decoupled button is double-clicked."
      default: []
      selector:
        action:

mode: restart

variables:
  device_id: !input aqara_device
  sensor_entity: >-
    {{ device_entities(device_id) | select('search', 'sensor.*_action') | first if device_id != "" else "" }}

trigger:
  # --- DYNAMIC DEVICE SENSOR PIPELINE ---
  - platform: template
    value_template: "{{ sensor_entity != '' and states(sensor_entity) == 'single_top' }}"
    id: single_top
  - platform: template
    value_template: "{{ sensor_entity != '' and states(sensor_entity) == 'double_top' }}"
    id: double_top
  - platform: template
    value_template: "{{ sensor_entity != '' and states(sensor_entity) == 'single_wireless' }}"
    id: single_wireless
  - platform: template
    value_template: "{{ sensor_entity != '' and states(sensor_entity) == 'double_wireless' }}"
    id: double_wireless

  # --- DIRECT MQTT PAYLOAD PIPELINE ---
  - platform: mqtt
    topic: !input mqtt_topic
    payload: "single_top"
    value_template: "{{ value_json.action if value_json.action is defined else '' }}"
    id: single_top
  - platform: mqtt
    topic: !input mqtt_topic
    payload: "double_top"
    value_template: "{{ value_json.action if value_json.action is defined else '' }}"
    id: double_top
  - platform: mqtt
    topic: !input mqtt_topic
    payload: "single_wireless"
    value_template: "{{ value_json.action if value_json.action is defined else '' }}"
    id: single_wireless
  - platform: mqtt
    topic: !input mqtt_topic
    payload: "double_wireless"
    value_template: "{{ value_json.action if value_json.action is defined else '' }}"
    id: double_wireless

condition: []

action:
  - choose:
      - conditions:
          - condition: trigger
            id: single_top
        sequence: !input action_single_top

      - conditions:
          - condition: trigger
            id: double_top
        sequence: !input action_double_top

      - conditions:
          - condition: trigger
            id: single_wireless
        sequence: !input action_single_wireless

      - conditions:
          - condition: trigger
            id: double_wireless
        sequence: !input action_double_wireless