Skip to content

Instantly share code, notes, and snippets.

@Gr8z
Created July 1, 2026 12:03
Show Gist options
  • Select an option

  • Save Gr8z/59db722a497bd2886333d7ab1e8f5c86 to your computer and use it in GitHub Desktop.

Select an option

Save Gr8z/59db722a497bd2886333d7ab1e8f5c86 to your computer and use it in GitHub Desktop.
blueprint:
name: Aqara H2 Wireless Switch (2 gang) — 2 Lights with Dimming (Z2M)
description: >
Control two lights with an Aqara H2 wireless remote switch (2 gang) via
Zigbee2MQTT.
Left rocker → Light 1, Right rocker → Light 2.
• Single click → toggle the light
• Double click → set light to 100%
• Hold → dim continuously (direction flips on each new hold)
• Release → stop dimming
Requirements:
• Set the switch click_mode to "multi" (needed for double + hold events).
• Keep operation_mode = "event" (default) so actions publish to `action`.
Uses WXKG15LM-style actions: single_left/right, double_left/right,
hold_left/right, release_left/right, single_both.
domain: automation
input:
remote:
name: Aqara H2 Switch (action entity)
description: The Z2M MQTT entity exposing the "action" attribute.
selector:
entity:
filter:
- integration: mqtt
light_left:
name: Light 1 (Left rocker)
selector:
target:
entity:
domain: light
light_right:
name: Light 2 (Right rocker)
selector:
target:
entity:
domain: light
dim_step:
name: Dim step size (%)
description: Brightness change applied each cycle while holding.
default: 10
selector:
number:
min: 1
max: 25
step: 1
unit_of_measurement: "%"
dim_delay:
name: Dim cycle delay (ms)
description: Delay between dim steps while holding. Lower = faster dimming.
default: 350
selector:
number:
min: 100
max: 1000
step: 50
unit_of_measurement: ms
mode: restart
max_exceeded: silent
variables:
remote_ent: !input remote
action: "{{ trigger.to_state.attributes.action }}"
dim_step: !input dim_step
dim_delay: !input dim_delay
trigger:
- platform: state
entity_id: !input remote
attribute: action
condition:
- "{{ trigger.to_state.attributes.action not in [None, ''] }}"
action:
- choose:
# ---------------- LEFT ROCKER → Light 1 ----------------
- conditions: "{{ action == 'single_left' }}"
sequence:
- service: light.toggle
target: !input light_left
- conditions: "{{ action == 'double_left' }}"
sequence:
- service: light.turn_on
target: !input light_left
data:
brightness_pct: 100
- conditions: "{{ action == 'hold_left' }}"
sequence:
# Pick direction: dim up if currently below mid, else dim down.
- variables:
lt_ent: "{{ (light_left.entity_id if light_left.entity_id is string else light_left.entity_id[0]) }}"
step_signed: >
{{ dim_step if (state_attr(lt_ent, 'brightness') or 0) < 128 else (dim_step * -1) }}
- repeat:
while:
- "{{ state_attr(remote_ent, 'action') == 'hold_left' }}"
sequence:
- service: light.turn_on
target: !input light_left
data:
brightness_step_pct: "{{ step_signed }}"
transition: "{{ (dim_delay / 1000) | float }}"
- delay:
milliseconds: !input dim_delay
# ---------------- RIGHT ROCKER → Light 2 ----------------
- conditions: "{{ action == 'single_right' }}"
sequence:
- service: light.toggle
target: !input light_right
- conditions: "{{ action == 'double_right' }}"
sequence:
- service: light.turn_on
target: !input light_right
data:
brightness_pct: 100
- conditions: "{{ action == 'hold_right' }}"
sequence:
- variables:
rt_ent: "{{ (light_right.entity_id if light_right.entity_id is string else light_right.entity_id[0]) }}"
step_signed: >
{{ dim_step if (state_attr(rt_ent, 'brightness') or 0) < 128 else (dim_step * -1) }}
- repeat:
while:
- "{{ state_attr(remote_ent, 'action') == 'hold_right' }}"
sequence:
- service: light.turn_on
target: !input light_right
data:
brightness_step_pct: "{{ step_signed }}"
transition: "{{ (dim_delay / 1000) | float }}"
- delay:
milliseconds: !input dim_delay
# ---------------- BOTH ROCKERS ----------------
- conditions: "{{ action == 'single_both' }}"
sequence:
- service: light.toggle
target: !input light_left
- service: light.toggle
target: !input light_right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment