Aqara H1 Rotary Dimmer Switch Dial - Media Controls

Hey all, I finally got my hands on an Aqara H1 Rotary Dimmer Switch, a ZigBee device that makes for a neat remote.

While it’s designed to be a light dimmer, it looks like a radio knob, which got me wanting to use it to control a media player.

Using an existing blueprint as a reference, I was able to put together a blueprint that allows you to control a media player with the different controls on the device (single press, double press, long press, rotate left, rotate right).

NOTE: This device is not currently supported in ZHA, and requires a custom quirk (available here: Custom ZHA quirk for Aqara H1 Knob Wireless · GitHub) until official support is added.

Blueprint

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

# This blueprint allows you to control a media player with a Aqara H1 Rotary Dial (https://homekitnews.com/2020/11/02/aqara-reveal-smart-rotary-dimmer-switch/)
# This automation requires a boolean (toggle) helper to maintain state: https://www.home-assistant.io/integrations/input_boolean/
#
# This ZigBee device is not currently supported by ZHA, and requires a custom ZHA quirk: https://gist.github.com/oxc/754d6436ce62d92af660d3671acd9346
# This ZigBee device is already supported by Z2M: https://github.com/zigpy/zha-device-handlers/issues/2266

blueprint:
  name: Aqara H1 Rotary Dial - Media Controls

  description: >-
    This automation allows using an Aqara H1 Rotary Dial to control a media player.
    Requires a custom ZHA quirk until official ZHA support is added.
    Requires a boolean (toggle) helper to store modes.

  domain: automation

  input:
    dial:
      name: Aqara H1 Rotary Dial
      description: Select the rotary dial you wish to use
      selector:
        device:
          integration: zha
          manufacturer: LUMI
          model: lumi.remote.rkba01
    media_player:
      name: Media Player
      description: The media player to control
      selector:
        target:
          entity:
            domain: media_player
    mode_helper:
      name: Mode toggle helper
      description: A boolean (toggle) helper to store the current mode in
      selector:
        entity:
          domain: input_boolean

mode: restart
max_exceeded: silent

trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input dial

action:
  - choose:
      # Play/pause on single press
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "1_single" }}'
        sequence:
          - service: media_player.media_play_pause
            data: {}
            target: !input media_player

      # Toggle mode on double press
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "1_double" }}'
        sequence:
          - service: input_boolean.toggle
            data: {}
            target:
              entity_id: !input mode_helper

      # Stop playback on long press
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "1_hold" }}'
        sequence:
          - service: media_player.media_stop
            data: {}
            target: !input media_player

      # Volume down / previous track on left turn
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "stop_rotation" and trigger.event.data.args.rotation_direction == -1 }}'
        sequence:
          - if:
              - condition: state
                entity_id: !input mode_helper
                state: "on"
            then:
              - service: media_player.media_previous_track
                data: {}
                target: !input media_player
            else:
              - service: media_player.volume_down
                data: {}
                target: !input media_player

      # Volume up / next track on right turn
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "stop_rotation" and trigger.event.data.args.rotation_direction == 1 }}'
        sequence:
          - if:
              - condition: state
                entity_id: !input mode_helper
                state: "on"
            then:
              - service: media_player.media_next_track
                data: {}
                target: !input media_player
            else:
              - service: media_player.volume_up
                data: {}
                target: !input media_player

    # Any other event will cancel the repeat loops.
    default: []

Setup

Double-clicking the button toggles between volume and track controls. To store the state, this automation relies on an input boolean helper.

Usage

  • Single press: Play/pause the media player
  • Double press: Toggle between volume and track controls
  • Long press: Stop the media player
  • Rotate right: Increase the volume or skip to the next track, depending on mode
  • Rotate left: Decrease the volume or skip to the previous track, depending on mode

Credit

Hopes this helps!

EDIT: 08-10-2023

A few days ago, I noticed that some aspects of this automation were no longer working, and discovered that my devices were now set into COMMAND mode rather than EVENT mode, which changes the triggers available for processing.

Supposedly, you can switch between COMMAND and EVENT mode by clicking the button on the device 5 times quickly, although I have been unable to switch my devices back into EVENT mode. I suspect a firmware update for these devices may have altered this behind-the-scenes.

If you also face the same issue, I have made a variant of this blueprint that works in COMMAND mode, which can be imported below:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

The key difference between the two is that, in COMMAND mode, a single press is not registered. As a result, single press is unavailable in this blueprint. I would suggest using the original EVENT mode variant above if possible.

3 Likes

Is this possible to use in the Z2M?

Thank you

1 Like

Probably, it seems like support for the device was added to Z2M:

1 Like

Thank you for your reply .

Yes the device is already supported in the Z2M but this Blueprint is only for the ZHA? Or can I also used this in the Z2M?

Thank you

Right now the blueprint expects a ZHA-connected device. You can try changing integration: zha to integration: z2m (or it might be integration: zigbee2mqtt? Not sure, never used Z2M before). The event names might be different in Z2M, in which case it won’t work. But it might not be different; I think the guy who made the ZHA quirk modeled it after Z2M’s implementation, so it might be the same. Basically, YMMV, but worth a shot.

Great Thank you

I try to “convert” this Blueprint editing the yaml file changing the integration that is mqtt

But once the

trigger:
  - platform: event
    event_type: zha_event ´

The trigger is different and I don’t have a Event linked to the mqtt events. I think i need to perform a several changes…

Thank you

Thanks for posting this. I have just received one and wish to use it for media control.

Does anyone know how to connect the thing to home assistant? The instructions I have are all in Chinese.

Add a ZHA device in Home Assistant, hold down the knob for around 10 seconds until it flashes.

2 Likes

Thank you for that.

Can’t seem to get this to work. I’ve added the quirk:

zha:
  custom_quirks_path: /config/zha_quirks/
  database_path: /config/zigbee.db 
  enable_quirks: true

the quirk shows up in ZHA

I turn the knob and can see events being fired but it doesn’t affect the volume of the media player (Sonos Roam)

I’ve tried clicking the button five times, tried both blue prints. I can see the automation has been triggered but nothing happens on the media player.

Any suggestions on where to go now?

If the automation has been triggered, what does the Trace of the automation say (“Traces” button in the top-left corner)?

Thanks, apologies for the delay in responding, I was away for bit. Here is the trace. Not sure what to make of it TBO.

Thanks for this, works for me with Sonos.

Would be great if I could adjust the dial sensitivity though, do you know if there is anyway to do this?

It takes a full turn of the knob to change the volume by around 5%.

Hmmmm… maybe that is the problem. Not turning the dial far enough.

Sorry, let me rephrase that. It doesn’t matter if I turn it one click or one full turn of the knob it changes the volume the same amount.

I’m coming from the Ikea Symfonisk so used to turning it a lot. These are a lot better as they don’t have the runaway effect that can turn the volume up to 100% by accident.

Unfortunately, that’s a problem with the hardware and/or Zigbee quirk itself. The device doesn’t seem to report out multiple “turn” events until a “turn” is stopped, and there’s no “distance”-related parameter, so we can’t tell how far or how long the knob was turned for.

Mine will no longer control the volume. I can see the events being fired in the logs when I rotate the dial, but it no longer turns the volume up and down on my sonos devices.