From 87c2f61dad0cb2d425ab7e695729c44f6adc894b Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Sat, 26 Sep 2026 20:46:36 +0100 Subject: [PATCH] Another attempted fix for H2 EU dimmer detecting stop_rotating instead of single press - use a timeout --- aqara-h2-eu-dimmer-z2m-light-control.yaml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/aqara-h2-eu-dimmer-z2m-light-control.yaml b/aqara-h2-eu-dimmer-z2m-light-control.yaml index 1fe58dc..aa6ba18 100644 --- a/aqara-h2-eu-dimmer-z2m-light-control.yaml +++ b/aqara-h2-eu-dimmer-z2m-light-control.yaml @@ -117,13 +117,27 @@ action: # Safely extract payload variables directly from the MQTT JSON message payload: "{{ trigger.payload_json if trigger.payload_json is defined else {} }}" raw_action_type: "{{ payload.action | default('') }}" - rotation_button_state: "{{ payload.action_rotation_button_state | default('') }}" + + # Time since the previous MQTT event triggered this automation. + # Genuine stop_rotating events immediately follow rotation events. + # The H2 bug emits a stray stop_rotating after the device has been idle. + idle_seconds: > + {{ as_timestamp(now()) - + as_timestamp( + this.attributes.last_triggered + | default(as_datetime(0), true) + ) + }} + + # Work around the H2 occasionally reporting the first single press + # after being idle as stop_rotating. action_type: > - {% if raw_action_type == 'stop_rotating' and rotation_button_state == 'pressed' %} + {% if raw_action_type == 'stop_rotating' and idle_seconds | float > 1 %} single {% else %} {{ raw_action_type }} {% endif %} + raw_angle: "{{ payload.action_rotation_angle | default(0) | float(0) }}" # Pull inputs into variables so they can be safely evaluated in templates below @@ -196,4 +210,4 @@ action: target: !input target_light data: brightness_step_pct: "{{ scaled_step }}" - transition: !input dim_transition \ No newline at end of file + transition: !input dim_transition