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"

2 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.

Do you know how to convert this to Z2M?

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