I got myself a few Aqara Dimmer Switches H2 EU to use in detached mode for the control of smart RGBW lights. For this, I set them to detached mode at 100% brightness and set up automations for single clicks to toggle the respective lights. Easy, but I think this only works in Zigbee mode - so I had to flash the Zigbee firmware first, using the Aqara app (no hub needed!).
Then, I wanted to be able to control brightness via turning the knob too, but of course this had to be done in software as the smart bulbs would not appreciate physical dimming.
I found this thread with solutions for the H1 switch, but they do not work “as is”: Aqara knob H1 (wireless) automations
For example this was not possible:
trigger:
- platform: state
entity_id:
- sensor.bedroom_knob_action
to: rotation
id: rotating_action
From what I can tell, the H2 does not provide the simple “_action” sensor.
This increased brightness alright, but never decreased it:
sequence:
- action: light.turn_on
target:
entity_id: light.bedroom
data:
brightness_step: >
{{ (trigger.payload_json.action_rotation_angle_speed | float(0) * 0.3) | round(0) }}
transition: 0.2
I think the H2 always returns a positive number for rotation angle speed - no matter which direction you turn it - but rotation angle itself is negative when turning the knob anti-clockwise.
Finally, I ended up with this automation which works, albeit a bit more choppily than a pure physical dimmer. The multiplication factor (here: 0.6) may need to be adapted to the type/manufacturer of bulb you dim (I use Hue, Aqara, Paulmann and Wiz bulbs in different rooms, and they all seemed to react a bit differently):
alias: Living Room Dimmer Switch Brightness
description: Living Room Dimmer Switch Brightness
triggers:
- topic: zigbee2mqtt/Living Room Smart Bulbs Dimmer Switch
trigger: mqtt
id: Rotation
conditions:
- condition: trigger
id:
- Rotation
- condition: template
value_template: |
{{ 'action' in trigger.payload_json and
trigger.payload_json.action == 'rotation' and
trigger.payload_json.action_rotation_button_state == 'released' }}
- condition: state
entity_id: light.living_room_ceiling_light_plus_standing_light
state:
- "on"
actions:
- action: light.turn_on
target:
entity_id: light.living_room_ceiling_light_plus_standing_light
data:
brightness_step: >
{{ ((trigger.payload_json.action_rotation_angle_speed *
trigger.payload_json.action_rotation_angle /
(trigger.payload_json.action_rotation_angle | abs)) | float(0) * 0.6) |
round(0) }}
transition: 0.2
mode: single
max_exceeded: silent
It will not react if the light is not on in the first place, and it should filter out turns when the knob is pressed down.
Maybe this is interesting/useful for someone else. Any comments or improvement suggestions are welcome, I am by no means an expert in this.