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

Alright that’s the issue. This blueprint is specifically designed for ZHA. In the forum you should find alternatives.

1 Like

Oh! I completely missed that. Sorry.

Example script for changing color temp using the left and right buttons;

Yaml script for the left button:

service: light.turn_on
target:
  entity_id: light.hanglamp_keuken
data:
  color_temp: >
    {{ state_attr( 'light.hanglamp_keuken', 'color_temp' ) | default( 0, True
    ) | int + 50 }}

Yaml script for the right button:

service: light.turn_on
target:
  entity_id: light.hanglamp_keuken
data:
  color_temp: >
    {{ state_attr( 'light.hanglamp_keuken', 'color_temp' ) | default( 0, True
    ) | int - 50 }}

The default(0,True) sets the value to zero, True is required to make it work. This is because sometimes when powering the lamp on for the first time the color_temp value is None and not an int.

I’m looking for a way to remove the manual entity_id, I tried !input “light” or this.entity_id but that doesn’t seem to work.

I hope this helps someone.

2 Likes

I’ve been using this blueprint for a while now. And it works great.
Except that the SO today got a bit angry at me. (It was early in the morning)

She has told me a few times now that she wants to dim the light down to the lowest setting, without it turning off.

Is that possible? Hopefully you guys can help me fix this, before she gets to angry XD

I’m also looking for this to set it at 1% given there is already an off button this would make more sense. I can think of adding additional condition to change the step but I think this would get messy. Did you come up with a solution?

The blueprint is otherwise really good

Hey there, I sat down this morning and tried to come up with a solution to this problem. My biggest problem with this is the handling of domain light which is the input of this blueprint. To make the blueprint stop lowering the brightness on the light I need to check by how far I can lower the brightness so that at least 1 % brightness is left. The action the blueprint performs when the hold actions are executed are a relative change of the brightness. I came up with this solution right here where I either set the brightness -10 (%) when they are brighter than 10 % or I change them by 0 (no change).

{{ -10 if (0 if state_attr('light.living_room', 'brightness') is none else state_attr('light.living_room', 'brightness')) > (254 / 10) | round(0, 'floor') | int else 0 }}

The problem as I said is that I don’t know how to achieve the same thing with the domain “light” which can hold several light entities.
I’ve found this community post but don’t know how to apply it to this.
Maybe someone else with more experience can think of a solution :slight_smile:

You need to set A Variable in the Blueprint that is extracting all the relevant entities, thus being able to reference there current state.

It’s a pain when you are using the Target Selector, it’s easier if you use A Entity Selector or Area Selector. Please Vote on this, to make Target Selectors easier to use.

This statement is like black magic (gibberish :)) to me even with a python background. Does this replace the -10 the below statement?

brightness_step_pct: -10

And then the two light.living_room references replaced with the variable (not sure what the syntax here would be?). HA is great but still has a way to go to make this approachable!

Same here. And yes it would but it does not work by simply replacing it due to the fact this blueprint uses the target selector instead of the entity selector.

Hi,
if i create a script with your code, i get this error message.

Message malformed: extra keys not allowed @ data['service'].

alias: Ikea Tradfri FlurFarbtemperatur Plus
service: light.turn_on
target:
  entity_id: light.ikea_of_sweden_tradfribulbe27wsglobeopal1055lm_light
data:
  color_temp: >
    {{ state_attr( 'light.ikea_of_sweden_tradfribulbe27wsglobeopal1055lm_light', 'color_temp' ) | default( 0, True )
    | int + 50 }}
icon: mdi:brightness-4
mode: single

Maybe a noob question 🫣

To switch colors I added a input select, listing colors by name and added the following automation and template:

          - service: input_select.select_previous
            data:
              cycle: true
            target:
              entity_id: input_select.ikea_bulb_1_color
          - service: light.turn_on
            data_template:
              rgb_color: >
                {% set color = states('input_select.ikea_bulb_1_color') %}
				{%if color == 'white' %}[255, 255, 255] 
				{% elif color == 'orange' %}[255, 165, 0] 
				{% elif color == 'red' %}[255, 0, 0] 
				{% elif color == 'purple' %}[128, 0, 128] 
				{% elif color == 'blue' %}[0, 0, 255] 
				{% elif color == 'green' %}[0, 255, 0] 
				{% elif color == 'yellow' %}[255, 255, 0] 
				{% elif color == 'pink' %}[255, 105, 180] 
				{% elif color == 'magenta' %}[255, 0, 255] 
				{% elif color == 'cyaan' %}[0, 255, 255] 
				{% elif color == 'sky' %}[135, 206, 235]
				{% elif color == 'lime' %}[0, 255, 0] 
				{% elif color == 'teal' %}[0, 128, 128] 
				{% else %}[255, 255, 255] {% endif %}
              target:
                entity_id: light.ikea_bulb_1_light

Hope this helps. The only issue I have at the moment is that the input select changes value 5 times or so when I press the button

Inspired by the example code from @FaliseDotCom I created an version which allows to specify the device_id instead (lookup of the entry_id is time consuming) and uses an configurable stepping to have better control of the ‘speed’ off which the light colour changes.

YAML script for left button:

service: light.turn_on
data: 
  color_temp_kelvin: >
    {# BEGIN: User configurable variables #}
    {% set device_id = 'c5f2b25338af8e50c21eff7ea18282f2' %}
    {% set steps = 3 %}
    {# END: User configurable variables #}

    {% set entity_id = expand(device_entities(device_id)) | selectattr ( 'domain' , 'eq' , 'light' ) | map(attribute="entity_id") | first %}
    {# Default to 0 if not current color can be detected (condition lightbulb is not available #}
    {% set current_color_temp_kelvin = state_attr(entity_id, 'color_temp_kelvin') | default(0, True) %}
    {% set step_size = int((state_attr(entity_id, 'max_color_temp_kelvin') - state_attr(entity_id, 'min_color_temp_kelvin')) / steps) %}
    
    {# Ensure limit is honoured #}
    {{ min(current_color_temp_kelvin + step_size, state_attr(entity_id, 'max_color_temp_kelvin')) }}

target:
  device_id: c5f2b25338af8e50c21eff7ea18282f2

YAML script for right button:

service: light.turn_on
data: 
  color_temp_kelvin: >
    {# BEGIN: User configurable variables #}
    {% set device_id = 'c5f2b25338af8e50c21eff7ea18282f2' %}
    {% set steps = 3 %}
    {# END: User configurable variables #}

    {% set entity_id = expand(device_entities(device_id)) | selectattr ( 'domain' , 'eq' , 'light' ) | map(attribute="entity_id") | first %}
    {# Default to 0 if not current color can be detected (condition lightbulb is not available #}
    {% set current_color_temp_kelvin = state_attr(entity_id, 'color_temp_kelvin') | default(0, True) %}
    {% set step_size = int((state_attr(entity_id, 'max_color_temp_kelvin') - state_attr(entity_id, 'min_color_temp_kelvin')) / steps) %}
    
    {# Ensure limit is honoured #}
    {{ max(current_color_temp_kelvin - step_size, state_attr(entity_id, 'min_color_temp_kelvin')) }}
target:
  device_id: c5f2b25338af8e50c21eff7ea18282f2

I just installed this Blueprint and it’s pretty sweet! Thank you!

I am having a bit of an issue however. I have the top and bottom buttons turning on/off 4 lights and dimming them. Works perfectly. The left/right buttons short press turns the Onkyo Home Theatre receiver on and off. Also works well. Long pressing them turns the volume up and down. But an unwanted side effect is that long pressing them also is turning on the lights set to be controlled by the top and bottom buttons. I have deleted the automation and set it up 3 times now with the exact same effect.

Any ideas?

alias: IKEA Styrbar
description: Livingroom Lights and Stereo control
use_blueprint:
  path: Malte/zha-ikea-four-button-remote-styrbar-for-lights-e2001-e2002.yaml
  input:
    remote: 9ba6aae67fd3bd4966d02a0a50504062
    light:
      entity_id:
        - light.fireplace_lights
        - light.livingroom_yeelight
        - light.ikea_tradfri_led_lamp_light
    force_brightness: true
    brightness: 85
    button_left_short:
      - service: light.turn_off
        data: {}
        target:
          device_id: c2c105e87bf0ad6393bf9ee56b485d53
    button_left_long:
      - service: media_player.volume_down
        data: {}
        target:
          device_id: 4482737fa563612caceafaa8c1eb9e8c
    button_right_short:
      - service: light.turn_on
        data: {}
        target:
          device_id: c2c105e87bf0ad6393bf9ee56b485d53
    button_right_long:
      - service: media_player.volume_up
        data: {}
        target:
          device_id: 4482737fa563612caceafaa8c1eb9e8c

The Onkyo turns on via a script which acts like a light. It’s scripted because it also tunes Volumio to an Internet radio station and plays it. The left Off button just turns off the Onkyo and stops Volumio from playing (via the same script).

There is sadly nothing I can do about it. As I explained in the comments of the blueprint, this is how IKEA implemented this button. The on-command will always be sent whenever you use the long-press actions.

Yes, I read that, but the on-command for what? The last button used or the device assigned to the top button? This is where I am confused. There is no light assigned to to the left/right buttons, so the on command should just send an “on” command to the Onkyo, which is assigned to that button and would be harmless, I would think.

The text in the Blueprint only says “Use with care, as before the long press event is sent, the “on” event gets triggered.” It is a bit vague.

I split the blueprint into 2 separate ones. One for on/off/dim and the 2nd to change the color using a input_select. Since they both need to work in a different mode I had to split the blueprint. I’ve taken the default colors and added a couple of extra.

In the config.yaml I added a input_select for each remote:

input_select:
  ikea_remote_1_colors:
    options:
      - white
      - orange
      - gold
      - red-orange
      - pink
      - lavender
      - periwinkle
      - light-salmon
      - peach
      - blue
      - sky
      - lime
      - yellow

I had a 2nd set so I recreated each color setting and asked chatgpt to name the RBG values… names like periwinkle are not something I could come up with myself :stuck_out_tongue:

BLUEPRINT 1

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
          multiple: false
    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: {}
    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.0
          step: 0.1
          unit_of_measurement: seconds
          mode: slider
    button_left_short:
      name: Left button - short press
      description: Action to run on short left button press
      default: []
      selector:
        action: {}
    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: {}
    button_right_short:
      name: Right button - short press
      description: Action to run on short right button press
      default: []
      selector:
        action: {}
    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: {}
  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

BLUEPRINT 2

blueprint:
  name: ZHA - IKEA four button remote for lights - color switch
  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
          multiple: false
    light:
      name: Light(s)
      description: The light(s) to control
      selector:
        target:
          entity:
          - domain:
            - light
    input_select:
      name: Color Loop
      description: The input select that defines the color loop
      selector:
        target:
          entity:
          - domain:
            - input_select
    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: {}
    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.0
          step: 0.1
          unit_of_measurement: seconds
          mode: slider
          
    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: {}

    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: {}

  source_url: https://community.home-assistant.io/t/zha-ikea-four-button-remote-styrbar-for-lights-e2001-e2002/384482
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 }}'
    input_select: !input input_select
- choose:
  - conditions:
    - '{{ command == ''press'' }}'
    - '{{ cluster_id == 5 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == [257, 13, 0] }}'
    sequence: 
    - service: input_select.select_previous
      target: !input input_select
      data:
        cycle: true
    - service: light.turn_on
      data_template:
        rgb_color: >
          {% set color = states(input_select.entity_id) %}
          {% if color == 'white' %}[255, 255, 255] 
          {% elif color == 'orange' %}[255, 146, 39] 
          {% elif color == 'gold' %}[255, 168, 37] 
          {% elif color == 'red-orange' %}[255, 103, 49] 
          {% elif color == 'pink' %}[255, 91, 232] 
          {% elif color == 'lavender' %}[198, 116, 255] 
          {% elif color == 'periwinkle' %}[148, 122, 255] 
          {% elif color == 'light-salmon' %}[255, 170, 95] 
          {% elif color == 'peach' %}[255, 197, 149] 
          {% elif color == 'blue' %}[0, 0, 255] 
          {% elif color == 'sky' %}[135, 206, 235]
          {% elif color == 'lime' %}[0, 255, 0]
          {% elif color == 'yellow' %}[255, 255, 0] 
          {% else %}[255, 255, 255] {% endif %}
      target: !input light
  - conditions:
    - '{{ command == ''press'' }}'
    - '{{ cluster_id == 5 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == [256, 13, 0] }}'
    sequence: 
    - service: input_select.select_next
      target: !input input_select
      data:
        cycle: true
    - service: light.turn_on
      data_template:
        rgb_color: >
          {% set color = states(input_select.entity_id) %}
          {% if color == 'white' %}[255, 255, 255] 
          {% elif color == 'orange' %}[255, 146, 39] 
          {% elif color == 'gold' %}[255, 168, 37] 
          {% elif color == 'red-orange' %}[255, 103, 49] 
          {% elif color == 'pink' %}[255, 91, 232] 
          {% elif color == 'lavender' %}[198, 116, 255] 
          {% elif color == 'periwinkle' %}[148, 122, 255] 
          {% elif color == 'light-salmon' %}[255, 170, 95] 
          {% elif color == 'peach' %}[255, 197, 149] 
          {% elif color == 'blue' %}[0, 0, 255] 
          {% elif color == 'sky' %}[135, 206, 235]
          {% elif color == 'lime' %}[0, 255, 0]
          {% elif color == 'yellow' %}[255, 255, 0] 
          {% else %}[255, 255, 255] {% endif %}
      target: !input light
    
  - conditions:
    - '{{ command == ''hold'' }}'
    - '{{ cluster_id == 5 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == [3329, 0] }}'
    sequence: !input button_left_long

  - conditions:
    - '{{ command == ''hold'' }}'
    - '{{ cluster_id == 5 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == [3328, 0] }}'
    sequence: !input button_right_long
- delay:
    hours: 0
    minutes: 0
    seconds: 0
    milliseconds: 500
mode: single

How is this advantageous compared to the original version?

Worked great! One thing I was missing was to handle several remotes within one blueprint (having the same configuration).

But today, while my HA server was down for maintenance, I learned about binding.
It is connecting ZigBee devices directly to each other.
So I made a Group of my Philips Hue bulbs, and bound it to the IKEA Tradfri.
In my trivial case it works exactly the same, as with the blueprint. And also when HA is down.

However, I still want to use the blueprint for handling the left and right buttons.

@Malte,

  1. is it possible to allow the list of lights for on/off events to be empty? (Because now it’s handled by binding.) UPDATE: Never mind, it doesn’t hurt to turn on/off the bulbs by both binding and the automation.
  2. is it possible to handle several remotes within one blueprint?

Hey, this blueprint is currently not able to handle multiple remotes within this blueprint. You would need to duplicate the blueprint and change the remote to achieve that behavior.

Great blueprint, thanks a lot for sharing!

One question though. I find on/off dimming animations to be very long for my taste. Is there a way to speeding them up without impacting manual dimming speed? I would like them to be about 500ms long - from pressing on/off button until the final state. Any suggestions?