ZHA - IKEA four button remote (Styrbar) for lights (E2001, E2002)

Hey there, this blueprint is for basic light control with the IKEA four button remote (the square ones), integrated via ZHA.

It extends @SwerveShot’s version (incomplete and hasn’t seen any recent activity) which is based on the work of @frenck with the five button version.

Pressing the up button will turn on the lights at the last set brightness (unless the force brightness is toggled on in the blueprint).

Pressing the down button will turn the lights off again.

Pressing and holding the up/down buttons will change the brightness smoothly and can be pressed and hold until the brightness is satisfactory.

The “left” and “right” buttons can be assigned to a short and long button press action. This allows you to assign, e.g., a scene or anything else. Use the left and right button events with care, as before the long press event is sent, the “on” event gets triggered.

Updates

2023-10-07: Changed the transition time on the brighter/darker hold actions to match the delay time.
2022-05-13: Reworked the blueprint to make the hold actions work again. Also added a slider to specify the time between the execution of brighter/darker actions.

This is what the Blueprint looks like from the UI:

Blueprint Code

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

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

Or import this Blueprint by using the forum topic URL:

blueprint:
  name: ZHA - IKEA four button remote for lights
  description:
    'Control lights with an IKEA four button remote (the square ones),
    for use with [ZHA](https://www.home-assistant.io/integrations/zha/).


    Extends [SwerveShot](https://community.home-assistant.io/u/SwerveShot)''s [version](https://community.home-assistant.io/t/zha-ikea-four-button-remote-for-lights/347657)
    which is based on the work of [frenck](https://community.home-assistant.io/u/frenck)
    with the five button version.


    Pressing the up button will turn on the lights at the last set brightness (unless
    the force brightness is toggled on in the blueprint).


    Pressing the down button will turn the lights off again.


    Pressing and holding the up/down buttons will change the brightness smoothly and
    can be pressed and hold until the brightness is satisfactory.


    The "left" and "right" buttons can be assigned to a short and long button press
    action. This allows you to assign, e.g., a scene or anything else. Use the left
    and right button events with care, as before the long press event is sent, the
    "on" event gets triggered.

    '
  domain: automation
  input:
    remote:
      name: Remote
      description: IKEA remote to use
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: Remote Control N2
    light:
      name: Light(s)
      description: The light(s) to control
      selector:
        target:
          entity:
            domain: light
    force_brightness:
      name: Force turn on brightness
      description:
        Force the brightness to the set level below, when the "on" button
        on the remote is pushed and lights turn on.
      default: false
      selector:
        boolean: null
    brightness:
      name: Brightness
      description: Brightness of the light(s) when turning on
      default: 50
      selector:
        number:
          min: 0.0
          max: 100.0
          mode: slider
          step: 1.0
          unit_of_measurement: "%"
    hold_time:
      name: Hold Time
      description: Time between the execution of the brighter/darker actions when holding the brighter/darker button.
      default: 0.5
      selector:
        number:
          min: 0.1
          max: 2
          step: 0.1
          unit_of_measurement: seconds
    button_left_short:
      name: Left button - short press
      description: Action to run on short left button press
      default: []
      selector:
        action: null
    button_left_long:
      name: Left button - long press
      description:
        Action to run on long left button press. Use with care, as before
        the long press event is sent, the "on" event gets triggered.
      default: []
      selector:
        action: null
    button_right_short:
      name: Right button - short press
      description: Action to run on short right button press
      default: []
      selector:
        action: null
    button_right_long:
      name: Right button - long press
      description:
        Action to run on long right button press. Use with care, as before
        the long press event is sent, the "on" event gets triggered.
      default: []
      selector:
        action: null
  source_url: https://community.home-assistant.io/t/zha-ikea-four-button-remote-styrbar-for-lights-e2001-e2002/384482
mode: restart
max_exceeded: silent
variables:
  force_brightness: !input "force_brightness"
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input "remote"
action:
  - variables:
      command: "{{ trigger.event.data.command }}"
      cluster_id: "{{ trigger.event.data.cluster_id }}"
      endpoint_id: "{{ trigger.event.data.endpoint_id }}"
      args: "{{ trigger.event.data.args }}"
  - choose:
      - conditions:
          - "{{ command == 'on' }}"
          - "{{ cluster_id == 6 }}"
          - "{{ endpoint_id == 1 }}"
        sequence:
          - choose:
              - conditions: "{{ force_brightness }}"
                sequence:
                  - service: light.turn_on
                    target: !input "light"
                    data:
                      transition: 1
                      brightness_pct: !input "brightness"
            default:
              - service: light.turn_on
                target: !input "light"
                data:
                  transition: 1
      - conditions:
          - "{{ command == 'off' }}"
          - "{{ cluster_id == 6 }}"
          - "{{ endpoint_id == 1 }}"
        sequence:
          - service: light.turn_off
            target: !input "light"
            data:
              transition: 1
      - conditions:
          - "{{ command == 'move_with_on_off' }}"
          - "{{ cluster_id == 8 }}"
          - "{{ endpoint_id == 1 }}"
        sequence:
          - repeat:
              count: 10
              sequence:
                - service: light.turn_on
                  target: !input "light"
                  data:
                    brightness_step_pct: 10
                    transition: !input "hold_time"
                - delay: !input "hold_time"
      - conditions:
          - "{{ command == 'move' }}"
          - "{{ cluster_id == 8 }}"
          - "{{ endpoint_id == 1 }}"
        sequence:
          - repeat:
              count: 10
              sequence:
                - service: light.turn_on
                  target: !input "light"
                  data:
                    brightness_step_pct: -10
                    transition: !input "hold_time"
                - delay: !input "hold_time"
      - conditions:
          - "{{ command == 'press' }}"
          - "{{ cluster_id == 5 }}"
          - "{{ endpoint_id == 1 }}"
          - "{{ args == [257, 13, 0] }}"
        sequence: !input "button_left_short"
      - conditions:
          - "{{ command == 'hold' }}"
          - "{{ cluster_id == 5 }}"
          - "{{ endpoint_id == 1 }}"
          - "{{ args == [3329, 0] }}"
        sequence: !input "button_left_long"
      - conditions:
          - "{{ command == 'press' }}"
          - "{{ cluster_id == 5 }}"
          - "{{ endpoint_id == 1 }}"
          - "{{ args == [256, 13, 0] }}"
        sequence: !input "button_right_short"
      - conditions:
          - "{{ command == 'hold' }}"
          - "{{ cluster_id == 5 }}"
          - "{{ endpoint_id == 1 }}"
          - "{{ args == [3328, 0] }}"
        sequence: !input "button_right_long"
16 Likes

Sweet! Nice job adding the brightness adjustment. I’ll import this blueprint asap.

Great work, thank you two for the coding.

I needed a version turning on and off switches as well, so I added a small fork:

1 Like

Does this blueprint still work? I can turn the light on and off with it, but holding them does not raise/lower the brightness.

1 Like

Same problem here

Yes you are absolutely right. For me it isn’t working either. I hope that in the next couple of days I’ll find the time to debug what change in HA made this blueprint not work properly anymore in that regard.
If anyone has any idea what it could be, help is always welcome :slight_smile:

4 Likes

I reworked the blueprints code. The hold actions should now work again. I even added a new slider which lets you pick the time in between brighter/darker actions are executed. Hope that this update fixes the issues that were present.

4 Likes

Seems like the long press actions are broken again. any ideas?

Update: Its working my bad

Is it possible to turn on the light on lowest brightness by pressing the “off” button?
So “on” would be: brightest setting (or force brightness), and “off” would be: turn on with lowest setting.

Yes, that would work for sure but not with my blueprint. I suggest you “fork” my code and make the changes necessary.

      - conditions:
          - "{{ command == 'off' }}"
          - "{{ cluster_id == 6 }}"
          - "{{ endpoint_id == 1 }}"
        sequence:
          - service: light.turn_on
            target: !input "light"
            data:
              transition: 1
              brightness_pct: 1

Above would be the condition that needs to be changed and I’d probably suggest that you make the percentage value an input variable so that you can adjust it via the UI because some lights won’t even turn on when they are set to 1 % brightness.

Hope that this helps :rocket:

I watched the button events in the developer tools. Seems as if this remote doesn’t support double click. So I would have to rewrite the parts for single click to only trigger if no second click appears.
For doubleclicks I’d have to do manual timing to catch the second click. Something like this:

only when the light is on and the second click is less than 0,2s old.

      - conditions:
          - "{{ command == 'off' }}"
          - "{{ cluster_id == 6 }}"
          - "{{ endpoint_id == 1 }}"
          - "{{ is_state(!input 'light', 'on')}}"
          - "{{ utcnow() - states.light.{!input 'light'}.last_changed < timedelta(seconds=0.2)  }}"

but I don’t think this would compile :wink:
Is there a way to test these kind of templates? And how can I get one into HA without an URL?

working great for me thanks - would love to use the left and right buttons to cycle through some preset colours but no idea how ? is it doable

I have the problem that the on/off button only turns on/off one of two lights I have placed in a single lamp. Doesn’t matter if I select both lights manually, create a HA group, create a Zigbee group – only one of them works with the remote, but I can successfully switch both lamps manually (or via the zigbee group). Did anyone notice a similar behavior?

That sounds odd. I can assure you that it works with a HA group, because that is exactly what I use the button for in my setup. So I assume it’s more of a problem on your specific configuration and not related to this blueprint.

1 Like

Thank you, I resolved the problem by reconnecting the remote with HA. There was really something off in my setup.

Thank you for the blueprint. It was very helpful in my setup.

For those that looking for how to cycle scenes using the left and right button, i created a small script that jumps to the next scene and activate it.

You have to create an input_select helper containing all the entity IDs of the desired scenes.

alias: Next Scene
fields:
  scene_select:
    name: Scene Select
    description: Input Select entity to set the next scene.
    required: true
    selector:
      entity:
        domain: input_select
  cycle:
    name: Cycle
    description: If the option should cycle from the last to the first.
    default: true
    selector:
      boolean: null
sequence:
  - service: input_select.select_next
    data:
      cycle: "{{cycle}}"
    target:
      entity_id: "{{scene_select}}"
  - service: scene.turn_on
    target:
      entity_id: "{{states(scene_select)}}"
    metadata: {}
mode: queued
max: 10

First I tried to do it by activating the scene directly when the input_select changed using an automation, but that had multiple drawbacks:

  1. Need an additional automation for every scene input_select.
  2. Tight coupling of changing the input_select and activating the scene.
  3. Sometimes feels buggy. (Fast button presses not recognized etc.)

Hope that this is useful for you.

5 Likes

Might be a silly question, I was looking at this as a repurpose by using it as a four different input switch. As in pressing up, down, left and right can perform separate actions, is this possible?

I have not tried the blueprint yet, just plain automations.
You should be able to create any automation based on the remote’s events, I set mine to toggle lights (up/down) and air purifier fan speed (left/right). Long press left/right can’t really be used on its own because it fires “turn on” too (same as pressing up), as mentioned in the first post. Other than that you can assign anything.

How can I use this so that left/right long press continuously changes white temperature (or color hue) for Ikea bulbs ?

Increasing/decreasing white temperature are not available actions. Only available action is to set a fixed value for that temperature.

Thanks

1 Like

As of now this is not something that can be done with this blueprint nor do I know of a convenient way other than switching in between different scenes with an input helper (as described earlier in this discussion).