Zigbee2MQTT - Ikea STYRBAR 4-button remote (E2001/E2002)

Based on Zigbee2mqtt IKEA 5-button remote general use blueprint I adapted it to the STYRBAR 4 button remote:

blueprint:
  name: Z2M - IKEA STYRBAR 4-button remote
  description: "This blueprint is for the IKEA STYRBAR square, 4-button remote when used with zigbee2mqtt.
  It is for general use so all buttons can be connected to any action of your choice"
  domain: automation
  input:
    remote:
      name: Remote
      description: IKEA STYRBAR remote to use
      selector:
        entity:
          integration: mqtt
          domain: sensor
    button_on:
      name: Brightness up button - short press
      description: Action to run when SHORT press on brighness UP button
      default: []
      selector:
        action: {}
    button_off:
      name: Brightness down button - short press
      description: Action to run when SHORT press on brighness DOWN button
      default: []
      selector:
        action: {}
    button_brightness_move_up:
      name: Brightness up button - long press
      description: Action to run when LONG press on brighness UP button
      default: []
      selector:
        action: {}
    button_brightness_move_down:
      name: Brightness down button - long press
      description: Action to run when LONG press on brighness DOWN button
      default: []
      selector:
        action: {}
    button_brightness_stop:
      name: Brightness stop button - long release press
      description: Action to run when LONG press on brighness (up or down) is released
      default: []
      selector:
        action: {}
    button_left_click:
      name: Left button - short press
      description: Action to run when SHORT press on LEFT arrow button
      default: []
      selector:
        action: {}
    button_left_hold:
      name: Left button - hold
      description: Action to run when HOLD press on LEFT arrow button
      default: []
      selector:
        action: {}
    button_left_release:
      name: Left button - release
      description: Action to run when RELEASE press on LEFT arrow button
      default: []
      selector:
        action: {}       
    button_right_click:
      name: Right button - short press
      description: Action to run when SHORT press on RIGHT arrow button
      default: []
      selector:
        action: {}
    button_right_hold:
      name: Right button - hold
      description: Action to run when HOLD press on RIGHT button
      default: []
      selector:
        action: {}
    button_right_release:
      name: Right button - release
      description: Action to run when RELEASE press on RIGHT arrow button
      default: []
      selector:
        action: {}   
mode: restart
max_exceeded: silent
trigger:
  - platform: state
    entity_id: !input "remote"
    attribute: action
action:
  - variables:
      command: "{{ trigger.to_state.state }}"
  - choose:
      - conditions:
          - "{{ command == 'on' }}"
        sequence: !input "button_on"
      - conditions:          
          - "{{ command == 'off' }}"
        sequence: !input "button_off"        
      - conditions:
          - "{{ command == 'brightness_move_up' }}"
        sequence: !input "button_brightness_move_up"
      - conditions:
          - "{{ command == 'brightness_move_down' }}"
        sequence: !input "button_brightness_move_down"
      - conditions:
          - "{{ command == 'brightness_stop' }}"
        sequence: !input "button_brightness_stop"
      - conditions:
          - "{{ command == 'arrow_left_click' }}"
        sequence: !input "button_left_click"
      - conditions:
          - "{{ command == 'arrow_left_hold' }}"
        sequence: !input "button_left_hold"
      - conditions:
          - "{{ command == 'arrow_left_release' }}"
        sequence: !input "button_left_release"        
      - conditions:
          - "{{ command == 'arrow_right_click' }}"
        sequence: !input "button_right_click"
      - conditions:
          - "{{ command == 'arrow_right_hold' }}"
        sequence: !input "button_right_hold"
      - conditions:
          - "{{ command == 'arrow_right_release' }}"
        sequence: !input "button_right_release"

10 Likes

Great Blueprint! I was looking for something like this.

I am getting an error though, and it won’t work:

Error: UndefinedError: 'dict object' has no attribute 'to_state'

It refers to the following line in the code:

variables:
  command: '{{ trigger.to_state.state }}'

Any idea what is wrong?

regards,
Gottgenk

Hi!, I don´t know where is the problem, it is my first blueprint and it is working for me.

When do you receive the error? Selecting the blueprint? Running it?

Happens when I am running the blueprint as an automation. Might be something with a change in Z2M, I am seeing more people having this issue.

I haven’t tried every button yet, but for now it seems to be working. However, I don’t understand what all these actions mean!

What is the difference between, LONG and HOLD?

What is an action for RELEASE? If I press a button, eventually I have to release it…

Hi all,

New to HA, so I have added the blueprint (Thanks OP) ive put the entity to the switch action, of the styrbar remote. Action type - I clicked the device and then added each bulb x 4 (Cant work out how to use a lighting group for this) Action set to brightness up for brightness button etc…

So I also noticed the automation is entered into the automations.yaml rather than the UI, which it has and is all present. However the button is not controlling anything, I know it is connected as i can see the button click responses on the device info.

Have a missed something obvious?

Thanks

I’ve managed to get it working for me, I had to remove the attribute: action from line 87.

The action is the sensor in my case.

1 Like

Do you know how to convert this to Z2M?

Sadly im new to automations and cant get it to work by my own.

Hey Wavs,
Could you maybe update the Blueprint a bit?
Just disabled the legacy option in z2mqtt to see what changed and the remotes stopping working.
The new triggers are

on, off, arrow_right_click, arrow_left_click, brightness_move_down, brightness_move_up, brightness_stop

example payload {"action":"brightness_stop","battery":100,"linkquality":48,"update":{"state":"idle"},"update_available":false}'

2 Likes

Can someone tell me what I’m supposed to do with the Blueprint above.
I cannot see where I can paste into a new empty blueprint!
(I have imported a few using buttons on this forum, but never copied/pasted)

@Wingnut paste the URL from this topic by clicking ‘Import Blueprint’ on Settings - Automations & Scences - Blueprints

That will put the Blueprint from @wavs and allow you to use it as a template when creating automations.

1 Like

Thanks, I’ll remember that for next time.

I didn’t think of that as i thought this community page would not e structured enough for HA to pick out the Blueprint.

Anyway, I discovered where the Blueprints are stored in HA (config/blueprints) so just copied and pasted the code into a new file in that area. That worked, but as it happens, I discovered a more recent and versatile blueprint for the Ikea Styrbar button with the conventional ‘Import Blueprint’ button.

Thanks for the blueprint. Single press works great for me, but double or long press does not. it just fires single presses. any ideas?

Edit: Solved.The " Expose xx button double press event" also enables long press. I am leaving the post for documentation.


this:
  entity_id: automation.house_on_off
  state: 'on'
  attributes:
    last_triggered: '2023-01-11T18:03:12.958417+00:00'
    mode: restart
    current: 0
    id: '1673311001813'
    friendly_name: House on/off
  last_changed: '2023-01-11T18:02:56.884387+00:00'
  last_updated: '2023-01-11T18:03:12.992208+00:00'
  context:
    id: 01GPH005NNDHNVSFZW6WBQ8H4G
    parent_id: 01GPH005NME91WT0MJ4ZYZ9RP4
    user_id: null
trigger:
  id: '1'
  idx: '1'
  alias: null
  platform: event
  event:
    event_type: zha_event
    data:
      device_ieee: 04:0d:84:ff:fe:9a:19:d2
      unique_id: 04:0d:84:ff:fe:9a:19:d2:1:0x0005
      device_id: 44fd8ae7bd6efb8252e7e9686b0be122
      endpoint_id: 1
      cluster_id: 5
      command: release
      args:
        - -12290
      params:
        param1: -12290
    origin: LOCAL
    time_fired: '2023-01-11T18:03:15.892539+00:00'
    context:
      id: 01GPH008HM1JGRXNC7T7R38110
      parent_id: null
      user_id: null
  description: event 'zha_event'
integration: ZHA
button_left_long_loop: false
button_left_long_max_loop_repeats: 500
button_left_double_press: false
button_right_long_loop: false
button_right_long_max_loop_repeats: 500
button_right_double_press: false
button_up_long_loop: false
button_up_long_max_loop_repeats: 500
button_up_double_press: false
button_down_long_loop: false
button_down_long_max_loop_repeats: 500
button_down_double_press: false
helper_last_controller_event: input_text.ikea_styrbar_1
helper_double_press_delay: 500
helper_debounce_delay: 0
integration_id: zha
adjusted_double_press_delay: 500
actions_mapping:
  deconz:
    button_left_short:
      - '3002'
    button_left_long:
      - '3001'
    button_left_release:
      - '3003'
    button_right_short:
      - '4002'
    button_right_long:
      - '4001'
    button_right_release:
      - '4003'
    button_up_short:
      - '1002'
    button_up_long:
      - '1001'
    button_up_release:
      - '1003'
    button_down_short:
      - '2002'
    button_down_long:
      - '2001'
    button_down_release:
      - '2003'
  zha:
    button_left_short:
      - press_257_13_0
    button_left_long:
      - hold_3329_0
    button_left_release:
      - release_1365
    button_right_short:
      - press_256_13_0
    button_right_long:
      - hold_3328_0
    button_right_release:
      - release_-27903
    button_up_short:
      - 'on'
    button_up_long:
      - move_with_on_off_0_83
    button_up_release:
      - stop
    button_down_short:
      - 'off'
    button_down_long:
      - move_1_83
    button_down_release:
      - stop
  zigbee2mqtt:
    button_left_short:
      - arrow_left_click
    button_left_long:
      - arrow_left_hold
    button_left_release:
      - arrow_left_release
    button_right_short:
      - arrow_right_click
    button_right_long:
      - arrow_right_hold
    button_right_release:
      - arrow_right_release
    button_up_short:
      - 'on'
    button_up_long:
      - brightness_move_up
    button_up_release:
      - brightness_stop
    button_down_short:
      - 'off'
    button_down_long:
      - brightness_move_down
    button_down_release:
      - brightness_stop
button_left_short:
  - press_257_13_0
button_left_long:
  - hold_3329_0
button_left_release:
  - release_1365
button_right_short:
  - press_256_13_0
button_right_long:
  - hold_3328_0
button_right_release:
  - release_-27903
button_up_short:
  - 'on'
button_up_long:
  - move_with_on_off_0_83
button_up_release:
  - stop
button_down_short:
  - 'off'
button_down_long:
  - move_1_83
button_down_release:
  - stop
integrations_with_prev_event_storage:
  - zha
  - zigbee2mqtt
controller_entity: ''
controller_device: 44fd8ae7bd6efb8252e7e9686b0be122
controller_id: 44fd8ae7bd6efb8252e7e9686b0be122

Hmm. still struggling a bit. Fast double click on left and right is working well, but on up and down I have to wait between the clients or it will trigger a single click. Left and right long press is triggering a double click and long up and down is not triggering at all.


alias: House on/off
description: ""
use_blueprint:
  path: EPMatt/ikea_e2001_e2002.yaml
  input:
    integration: ZHA
    controller_device: 44fd8ae7bd6efb8252e7e9686b0be122
    helper_last_controller_event: input_text.ikea_styrbar_1
    action_button_up_short:
      - service: script.test_action
        data: {}
    action_button_down_long:
      - service: script.test_hold
        data: {}
    action_button_down_short:
      - service: script.test_action
        data: {}
    action_button_down_double:
      - service: script.test_2
        data: {}
    action_button_right_double:
      - service: script.test_2
        data: {}
    action_button_right_long:
      - service: script.test_hold
        data: {}
    button_right_long_loop: true
    button_right_long_max_loop_repeats: 1
    helper_debounce_delay: 0
    button_left_double_press: true
    button_right_double_press: true
    button_up_double_press: true
    button_down_double_press: true
    action_button_up_long:
      - service: script.test_hold
        data: {}
    action_button_up_double:
      - service: script.test_2
        data: {}
    action_button_left_short:
      - service: script.test_action
        data: {}
    action_button_left_long:
      - service: script.test_hold
        data: {}
    action_button_left_double:
      - service: script.test_2
        data: {}
    action_button_right_short:
      - service: script.test_action
        data: {}
    helper_double_press_delay: 750
    button_left_long_loop: true
    button_left_long_max_loop_repeats: 1
    button_up_long_loop: true
    button_up_long_max_loop_repeats: 1
    button_down_long_loop: true
    button_down_long_max_loop_repeats: 1

Did you end up figuring out why the blueprint was giving an error? I’m having the same error and none of the replies addresses the issue. Thanks!

I’m new to home assistant and blueprints.
This blueprint does not seem to work for me. What am I not understanding?
Do I also need to set make a state entity such as for the " Controller - IKEA E2001/E2002 STYRBAR Remote control" blueprint?

*Edit: It seems to be related to “Home Assistant legacy entity attributes” but what changed here ?

Hello all, just for your information. This blueprint stopped working around Aug’23.
Message was: Stopped because of unknown reason “null”
Context: Ikea STYRBAR 4-button remote, with Zigbee2MQTT.
After some investigation, and browsing MQTT messages, I found after every “on” action, there was a “” action:

Therefore, since the mode is ‘Restart’ the execution of “on” action:

Is interrupted by the next “” action:

The solution is quite easy: Change…

  • From: mode: restart
  • To: mode: queued

Don’t understand why it started happening: Firmware upgrade in the remote, Z2M changes, HA version, anyhow the current behaviour is the correct one, and the issue was in the blueprint. By the way: Big thanks to it, it’s awesome.

Hope it will help others having the same problem.