Zigbee2Mqtt - IKEA five button remote

This is a fork of @frenck’s work found here. The functionality should be exactly the same, except we’re just using the action attribute of a sensor created by Zigbee2MQTT.

In my example, my IKEA 5 button remote is called Office Remote. When you load the blueprint, select the sensor related to your remote. Mine’s called sensor.office_remote_action.

I have the “Home Assistant legacy entity attributes” setting checked in Zigbee2MQTT, or in the yaml configuration (see link for yaml).

A quote from the original:

It was specially created for use with (any) light(s). As the basic light controls are already mapped in this blueprint.
The middle “on” button, toggle the lights on/off to the last set brightness (unless the force brightness is toggled on in the blueprint). Dim 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.

Blueprint

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

Import the blueprint by using the forum topic URL! Or use the button.

blueprint:
  name: Z2M - IKEA five button remote for lights and actions
  description: |
    Control lights with an IKEA five button remote (the round ones).

    The middle "on" button, toggle the lights on/off to the last set brightness
    (unless the force brightness is toggled on in the blueprint).

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

    This is a fork of @Frenck's blueprint for ZHA found here https://community.home-assistant.io/t/zha-ikea-five-button-remote-for-lights/253804

  domain: automation
  input:
    remote:
      name: Remote
      description: IKEA remote to use. For example, "sensor.IKEA_REMOTE_action"
      selector:
        entity:
          domain: sensor
    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
          max: 100
          mode: slider
          step: 1
          unit_of_measurement: "%"
    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
      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
      default: []
      selector:
        action:

mode: restart
max_exceeded: silent

variables:
  force_brightness: !input force_brightness

trigger:
  - platform: state
    entity_id: !input remote
    attribute: action

action:
  - variables:
      command: "{{ trigger.to_state.state }}"
  - choose:
      - conditions:
          - "{{ command == 'toggle' }}"
        sequence:
          - choose:
              - conditions: "{{ force_brightness }}"
                sequence:
                  - service: light.toggle
                    target: !input light
                    data:
                      transition: 1
                      brightness_pct: !input brightness
            default:
              - service: light.toggle
                target: !input light
                data:
                  transition: 1

      - conditions:
          - "{{ command == 'brightness_up_click' }}"
        sequence:
          - service: light.turn_on
            target: !input light
            data:
              brightness_step_pct: 10
              transition: 1

      - conditions:
          - "{{ command == 'brightness_up_hold' }}"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: !input remote
                  state: brightness_up_release
                  attribute: action
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step_pct: 10
                    transition: 1
                  target: !input light
                - delay: '1'

      - conditions:
          - "{{ command == 'brightness_down_click' }}"
        sequence:
          - service: light.turn_on
            target: !input light
            data:
              brightness_step_pct: -10
              transition: 1

      - conditions:
          - "{{ command == 'brightness_down_hold' }}"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: !input remote
                  state: brightness_down_release
                  attribute: action
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step_pct: -10
                    transition: 1
                  target: !input light
                - delay: '1'

      - conditions:
          - "{{ command == 'arrow_left_click' }}"
        sequence: !input button_left_short

      - conditions:
          - "{{ command == 'arrow_left_hold' }}"
        sequence: !input button_left_long

      - conditions:
          - "{{ command == 'arrow_right_click' }}"
        sequence: !input button_right_short

      - conditions:
          - "{{ command == 'arrow_right_hold' }}"
        sequence: !input button_right_long

And a screenshot from my example:

Edit 5/30/22: Add details about Zigbee2MQTT legacy attributes setting.
Edit 6/14/22: Remove code block formatting for previous edit, added link to documentation instead.

14 Likes

Thanks for the blueprint!

The brightness changes by clicking up and down buttons (brightness_up_click and brightness_down_click) but not when holding those buttons pressed.
Actually, in the blueprint, there is no action for brightness_up_hold or for brightness_down_hold.

I am interested to see how that can be done with an automation. So far, the smooth dimming works for me only when binding the remote to a group of lights.

Can you put the YAML of the blueprint in the post itself instead of (just) linking to the gist? That way people can use the url of this forum topic to import the blueprint.

1 Like

@Bram_Kragten Done!

@razvanmdobre My “office lights” are a Zigbee2Mqtt group of 4 bulbs that work smoothly together for dimming, but yeah it does take 10 clicks to get it to dim all the way down. I’ll look how @frenck did it and try to add the Hold actions!

2 Likes

Import it again, I got up/down brightness button hold working!

You’re the man, @starbuck93!

This is working great! I have an issue tho that maybe I can get some help with:
I have an IKEA LED1732G11 light, that has the ability to adjust its color temperature. Originally I had the functionality that pressing/holding left and right increased/decreased the color temperature. Do you know by any chance how I can get that functionality back? Z2M doesnt give me an action on the lights entity to set the color temp, albeit the light card on HA does allow me to set it, so there has to be some mqtt command for it, I just don’t know how to investigate it.
Thanks!

@sztanpet My best guess would be to assign Left button - long press to a script that grabs the current color temperature, then increments along up or down. That’s a good idea, though.

Here’s some logic I’m using for holding down the brightness up/down buttons that maybe could be used in a similar way for color/temperature too.

sequence:
  - repeat:
      until:
        - condition: state
          entity_id: sensor.ikea_remote_action
          state: arrow_left_release
          attribute: action
      sequence:
        - service: light.turn_on
          data:
            # change color temp here by an increment instead of brightness
            brightness_step_pct: 10
            transition: 1
          entity_id: light.target_light
        - delay: '1'
2 Likes

So I tried multiple things, but I’m guessing this just won’t work without another variable that tracks the value of the color temperature, maybe it doesn’t update while the repeat-until is going on?
What I’m trying to do is to access the target lights state, get the current color temperature and adjust relative to it, either increasing or decreasing it.
It doesn’t work at all, maybe I’m doing it completely wrong, but there isn’t much documentation on how to access the target in the action, or I just didn’t find the relevant docs. Here is a snippet, everything else is basically the same as in the OP

- variables:
    command: '{{ trigger.to_state.state }}'
    lights: !input 'light'
- choose:
  - conditions:
    - '{{ command == ''toggle'' }}'
    sequence:
    - choose:
      - conditions: '{{ force_brightness }}'
        sequence:
        - service: light.toggle
          target: !input 'light'
          data:
            transition: 1
            brightness_pct: !input 'brightness'
      default:
      - service: light.toggle
        target: !input 'light'
        data:
          transition: 1
  - conditions:
    - '{{ command == ''brightness_up_click'' }}'
    sequence:
    - service: light.turn_on
      target: !input 'light'
      data:
        brightness_step_pct: 10
        transition: 1
  - conditions:
    - '{{ command == ''brightness_up_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: brightness_up_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: 10
            transition: 1
          target: !input 'light'
        - delay: '1'
  - conditions:
    - '{{ command == ''brightness_down_click'' }}'
    sequence:
    - service: light.turn_on
      target: !input 'light'
      data:
        brightness_step_pct: -10
        transition: 1
  - conditions:
    - '{{ command == ''brightness_down_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: brightness_down_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: -10
            transition: 1
          target: !input 'light'
        - delay: '1'
  - conditions:
    - '{{ command == ''arrow_left_click'' }}'
    sequence: !input 'button_left_short'
  - conditions:
    - '{{ command == ''arrow_right_click'' }}'
    sequence: !input 'button_right_short'
  - conditions:
    - '{{ command == ''arrow_left_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: arrow_left_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            color_temp: >
              {% if state_attr(lights[0], "color_temp") | int - 100 < state_attr(lights[0], "min_mireds")  %}
                {{- state_attr(lights[0], "min_mireds") -}}
              {% else%}
                {{- state_attr(lights[0], "color_temp") | int - 100 -}}
              {% endif %}
            transition: 1
          target: !input 'light'
        - delay: '1'
  - conditions:
    - '{{ command == ''arrow_right_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: arrow_right_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            color_temp: >
              {% if state_attr(lights[0], "color_temp") | int + 100 > state_attr(lights[0], "max_mireds")  %}
                {{- state_attr(lights[0], "max_mireds") -}}
              {% else%}
                {{- state_attr(lights[0], "color_temp") | int + 100 -}}
              {% endif %}
            transition: 1
          target: !input 'light'
        - delay: '1'

It looks like you’re heading in the right direction. I’d test the templates with the /developer-tools/template section and perhaps turn the sequence into a Script to test it without the Blueprint bits. My Tradfri bulb unfortunately doesn’t support color_temp so I’m not sure how to help test your sequence.

{% if state_attr('light.bulb', "color_temp") | int - 100 < state_attr('light.bulb', "min_mireds")  %}
  {{- state_attr('light.bulb', "min_mireds") -}}
{% else%}
  {{- state_attr('light.bulb', "color_temp") | int - 100 -}}
{% endif %} 

Thanks for this excellent blueprint, that greatly simplifies setting up the remote.

It might be worth considering creating a modification of this, that uses the “recommended” MQTT Device triggers as per https://www.zigbee2mqtt.io/integration/home_assistant.html#via-mqtt-device-trigger-recommended

So that the blueprint also functions properly even if
homeassistant_legacy_triggers: false
is set in the zigbee2mqtt configuration.yaml :smile:

3 Likes

I’ve been messing with this thing, trying to increase the speed of the repeat sequence, but it seems to me that the repeat sequence doesn’t work correctly. I changed the until-state to arrow_left_click as a test, so that the brightness should continue increasing/decreasing until I press the left button. It doesn’t work. My IKEA remotes just sends a hold message every second or so until I release the brightness buttons, and the brightness step sequence only seems to activate when a new hold message is sent. Probably because the repeat sequences are preceded by - conditions: - “{{ command == ‘brightness_up_hold’ }}”. I suspect that as soon as there isn’t a brightness hold message being received, the condition is false, and thus the repeat sequence is cut short. Maybe we should have multiple trigger-action rules. I’m going to try a few things.

Did you try to adjust the delay time in the sequence to milliseconds and remove the transition?

I tried that first, yes. The behaviour remained the same as before that change. Just a change once every second or so. Even when I change it to 100 milliseconds.

EDIT: nevermind, I just discovered that it’s a limit in my lamps. Apparently, my Philips Hue does work smoothly now. My WiZ lights have some sort of limit. The problem is not with this blueprint.

@Revorge I’m using zigbee2mqtt for a while now and I’ve disabled the legacy triggers. I’m using the MQTT device triggers as you mentioned. For that reason I cannot use this kind of blueprints because the action attribute isn’t reset to the default value.

Do you know if it is possible to create blueprints using device triggers? I never found any examples/documentation about it.

WoW, just after the conference i thought of looking in to creating one for Zigbee2mqtt. But never got the time for it. I have imported it but not yet tested it. I was wondering is it possible to add 2 remotes to 1 blueprint. In my case i have 3 ikea lights which i can control from 2 side of the home. Not sure if this is the correct translating but compare it with a hotel switching where you can put on the light from on side of the room en turn it off on the other side of the room.

The quick and dirty way now would be to duplicate the automation but was wondering if it even is possible to add 2 remotes to 1 blueprint.

Again Thanks! This saves me already so much time setting up automations

I think you’re talking about a 2-way switch. Or is it a 3 way switch. Anyways! I imagine you could rewrite the blueprint to allow for multiple remotes. I think the point of the blueprints is to easily duplicate the automation with different settings, or in your case, the same target light. Or, use the blueprint to create an automation once, then from the automation, use “Duplicate automation” and select a different remote.

image

Good thinking, but when i duplicate and select edit with Yaml i don’t see the real automation but still the yaml for the blueprint. (still new to blue print so might be doing something wrong)

Oh, that’s interesting, you’re right, the Edit with YAML button on the Automation shows the blueprint yaml, but only things that I’ve configured? But the Edit with UI still seems to be normal.

In your case, I’d just use Edit with UI and after duplicating the Automation just change the remote entity. You’ll end up with two Automations but maybe that’s just a limitation of the blueprint I wrote.

That would work, but currently looking in to the blueprint yaml and found a way to select multiple remotes, but still figuring out how to connect it to the trigger. Think it has something to do with the “sequence” option but can’t find any documentation on it.