Zigbee2Mqtt - IKEA five button remote

To make brightness up/down work, the sequence needs an OR added to it to accept both remotes.

Here’s a Script I just wrote using the UI editor

alias: 1New Script
sequence:
  - repeat:
      until:
        - condition: or
          conditions:
            - condition: state
              entity_id: sensor.a_remote_action
              state: brightness_up_release
            - condition: state
              entity_id: sensor.b_remote_action
              state: brightness_up_release
      sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: 10
            transition: 1
          entity_id: light.0x7ce52400000c15aa_light
        - delay: '1'
mode: single

Then use that for brightness_up_hold and brightness_down_hold

Getting stuck for the moment and have to continue at a later time. Will post my results if i make more progress. Thanks again!

Thanks so much for this @starbuck93

I’ve recently switched over from Deconz to zigbee2mqtt due to broader device support (as is my understanding anyway), and previously used this blueprint for Ikea 5 button which worked amazing: deCONZ - IKEA five button remote for lights with color temp

I’m relatively new to HA and have been trying to follow along with the discussion on Color Temp changing with Left/Right buttons but havent been able to work it out :frowning: Is there a simple way to make this work using your blueprint for zigbee2MQTT or, is it possible for you to update the blueprint to support functionality similar to the deconz version?

Thanks Again!

@BrisbaneGuy From what I could tell, deconz has some different commands than Z2M does, so I’m not exactly sure. Maybe try out --> 🎮 ZHA, deCONZ, Zigbee2MQTT - Ikea 5-button Remote Universal blueprint - all actions + double click events - control lights, media players and more with Hooks

I also tried to create a blueprint using devices instead of entity, I think currently it just isn’t possible as there is not only a device_id, there is also a discovery_id (when looking at automations using device triggers). Still not found any other blueprints or documentation using that.
So it seems “Home Assistant legacy triggers” is required for now?

Yes! It is quite annoying now - if you don’t use legacy triggers as is recommended in z2m as well as HA docs, blueprints cannot really work as mentioned/showed/discussed here: Device triggers from zigbee2mqtt vs mqtt listen, and sometimes a bit about blueprints - #15 by kotrfa

Edit: Add firt-class support for MQTT Device Triggers (to have feature parity with legacy triggers)

I’ve just imported the blueprint and set 3buttons of my 5button remote to control each gang of a Tuya 3gang switch when I run the automation and show the trace I get the following error. I should I set each of the 3buttons to toggle!

Error: UndefinedError: dict object has no attribute to_state

Have I missed something?

@starbuck93 thank you for this blueprint. So helpfully for a new HA user here!

How would I go about changing the bright/dim hold feature to be faster. The wife finds it to be too slow?

Thanks

Change the value of brightness_step_pct (it’s currently 10 for increasing brightness and -10 for decreasing brightness).

Thanks for the prompt reply.
Does a higher numeral mean faster? Like 20 and - 20.
What’s the max allowed.

Sorry really don’t need to mess this up.

Edit: tried higher numerals but made no change. I remembered reading that the automations need to be reloaded. Once I figured out how to do that I am glad to say the changes work.
Changed to 40 and -40. Very happy with it now…

Thanks again

first off. thank you for your on this blueprint.

But i am getting the following error when i try to use it:

Error: UndefinedError: ‘dict object’ has no attribute ‘to_state’

any idea to what i doing wrong?

If you’re using Zigbee2MQTT, you have to choose sensor.%sensornamme%_action, which is what I think may be your issue.

this is how my config looks like:

mode: restart
max_exceeded: silent
variables:
  force_brightness: false
trigger:
  - platform: state
    entity_id: sensor.tradfri_remote_control_nr_2_action
    attribute: action
action:
  - variables:
      command: '{{ trigger.to_state.state }}'
  - choose:
      - conditions:
          - '{{ command == ''toggle'' }}'
        sequence:
          - choose:
              - conditions: '{{ force_brightness }}'
                sequence:
                  - service: light.toggle
                    target:
                      device_id: 7e8f8334942ee07fb9519fa697d948b2
                    data:
                      transition: 1
                      brightness_pct: 50
            default:
              - service: light.toggle
                target:
                  device_id: 7e8f8334942ee07fb9519fa697d948b2
                data:
                  transition: 1
      - conditions:
          - '{{ command == ''brightness_up_click'' }}'
        sequence:
          - service: light.turn_on
            target:
              device_id: 7e8f8334942ee07fb9519fa697d948b2
            data:
              brightness_step_pct: 10
              transition: 1

That look like the blueprint code, not the automation code, correct?

Yes, that is correct.

Try importing the blueprint again:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.
And use the visual editor to create a new automation, instead of editing the blueprint code.

image

I think that blueprints shouldn’t be edited with the remote (in your case sensor.tradfri_remote_control_nr_2_action) in the YAML.

i tried removeing the blueprint and the unit from z2m, and readding both.
But i still get the same error, no matter what i do.

{
  "trace": {
    "last_step": "action/0",
    "run_id": "78c39bd728e4819d23faf0bd6061db9b",
    "state": "stopped",
    "script_execution": "error",
    "timestamp": {
      "start": "2022-04-25T18:14:36.018722+00:00",
      "finish": "2022-04-25T18:14:36.026991+00:00"
    },
    "domain": "automation",
    "item_id": "1650910437476",
    "error": "UndefinedError: 'dict object' has no attribute 'to_state'",
    "trigger": null,
    "trace": {
      "trigger": [
        {
          "path": "trigger",
          "timestamp": "2022-04-25T18:14:36.018808+00:00",
          "changed_variables": {
            "force_brightness": false,
            "this": {
              "entity_id": "automation.z2m_ikea_five_button_remote_for_lights",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-04-24T16:03:23.951776+00:00",
                "mode": "restart",
                "current": 0,
                "id": "1650910437476",
                "friendly_name": "Z2M - IKEA five button remote for lights"
              },
              "last_changed": "2022-04-25T18:14:33.082940+00:00",
              "last_updated": "2022-04-25T18:14:33.082940+00:00",
              "context": {
                "id": "25c1f24672a1ca44bdca848e09ce414a",
                "parent_id": null,
                "user_id": "5091a839e50c41c4894436f2365fe899"
              }
            },
            "trigger": {
              "platform": null
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-04-25T18:14:36.019878+00:00",
          "changed_variables": {
            "context": {
              "id": "f29c33a70a2ed31e183802a8c95b36f1",
              "parent_id": "14e3ff66aae7c942b9e3c20291ccad62",
              "user_id": null
            }
          },
          "error": "UndefinedError: 'dict object' has no attribute 'to_state'"
        }
      ]
    },
    "config": {
      "mode": "restart",
      "max_exceeded": "silent",
      "variables": {
        "force_brightness": false
      },
      "trigger": [
        {
          "platform": "state",
          "entity_id": "sensor.tradfri_rc_2_action",
          "attribute": "action"
        }
      ],
      "action": [
        {
          "variables": {
            "command": "{{ trigger.to_state.state }}"
          }
        },
        {
          "choose": [
            {
              "conditions": [
                "{{ command == 'toggle' }}"
              ],
              "sequence": [
                {
                  "choose": [
                    {
                      "conditions": "{{ force_brightness }}",
                      "sequence": [
                        {
                          "service": "light.toggle",
                          "target": {
                            "entity_id": "light.lys_panel"
                          },
                          "data": {
                            "transition": 1,
                            "brightness_pct": 50
                          }
                        }
                      ]
                    }
                  ],
                  "default": [
                    {
                      "service": "light.toggle",
                      "target": {
                        "entity_id": "light.lys_panel"
                      },
                      "data": {
                        "transition": 1
                      }
                    }
                  ]
                }
              ]
            },
            {
              "conditions": [
                "{{ command == 'brightness_up_click' }}"
              ],
              "sequence": [
                {
                  "service": "light.turn_on",
                  "target": {
                    "entity_id": "light.lys_panel"
                  },
                  "data": {
                    "brightness_step_pct": 10,
                    "transition": 1
                  }
                }
              ]
            },
            {
              "conditions": [
                "{{ command == 'brightness_up_hold' }}"
              ],
              "sequence": [
                {
                  "repeat": {
                    "until": [
                      {
                        "condition": "state",
                        "entity_id": "sensor.tradfri_rc_2_action",
                        "state": "brightness_up_release",
                        "attribute": "action"
                      }
                    ],
                    "sequence": [
                      {
                        "service": "light.turn_on",
                        "data": {
                          "brightness_step_pct": 10,
                          "transition": 1
                        },
                        "target": {
                          "entity_id": "light.lys_panel"
                        }
                      },
                      {
                        "delay": "1"
                      }
                    ]
                  }
                }
              ]
            },
            {
              "conditions": [
                "{{ command == 'brightness_down_click' }}"
              ],
              "sequence": [
                {
                  "service": "light.turn_on",
                  "target": {
                    "entity_id": "light.lys_panel"
                  },
                  "data": {
                    "brightness_step_pct": -10,
                    "transition": 1
                  }
                }
              ]
            },
            {
              "conditions": [
                "{{ command == 'brightness_down_hold' }}"
              ],
              "sequence": [
                {
                  "repeat": {
                    "until": [
                      {
                        "condition": "state",
                        "entity_id": "sensor.tradfri_rc_2_action",
                        "state": "brightness_down_release",
                        "attribute": "action"
                      }
                    ],
                    "sequence": [
                      {
                        "service": "light.turn_on",
                        "data": {
                          "brightness_step_pct": -10,
                          "transition": 1
                        },
                        "target": {
                          "entity_id": "light.lys_panel"
                        }
                      },
                      {
                        "delay": "1"
                      }
                    ]
                  }
                }
              ]
            },
            {
              "conditions": [
                "{{ command == 'arrow_left_click' }}"
              ],
              "sequence": []
            },
            {
              "conditions": [
                "{{ command == 'arrow_left_hold' }}"
              ],
              "sequence": []
            },
            {
              "conditions": [
                "{{ command == 'arrow_right_click' }}"
              ],
              "sequence": []
            },
            {
              "conditions": [
                "{{ command == 'arrow_right_hold' }}"
              ],
              "sequence": []
            }
          ]
        }
      ],
      "id": "1650910437476",
      "alias": "Z2M - IKEA five button remote for lights",
      "description": ""
    },
    "blueprint_inputs": {
      "id": "1650910437476",
      "alias": "Z2M - IKEA five button remote for lights",
      "description": "",
      "use_blueprint": {
        "path": "starbuck93/zigbee2mqtt-ikea-five-button-remote.yaml",
        "input": {
          "remote": "sensor.tradfri_rc_2_action",
          "light": {
            "entity_id": "light.lys_panel"
          }
        }
      }
    },
    "context": {
      "id": "f29c33a70a2ed31e183802a8c95b36f1",
      "parent_id": "14e3ff66aae7c942b9e3c20291ccad62",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Z2M - IKEA five button remote for lights",
      "message": "has been triggered",
      "source": null,
      "entity_id": "automation.z2m_ikea_five_button_remote_for_lights",
      "context_id": "f29c33a70a2ed31e183802a8c95b36f1",
      "when": "2022-04-25T18:14:36.018927+00:00",
      "domain": "automation"
    }
  ]
}

Brian, I was having the same issue and was just able to get it fixed and working (mostly).

The blueprint code is looking not at the state of the entity “[Your Remote]_action” but for an attribute of the entity “[Your Remote]”. For me, this entity does not exist. Instead I have multiple entities, one for each of the exposed attributes on Z2M. This is the case for all my Z2M devices. I think this might be a semi-recent change to the way Z2M handles devices.

To get it to work, I had to edit the blueprint code (not the automation yaml, but the blueprint one found in the blueprints folder) to remove all references to “attribute: action”. Once those lines were deleted, I removed my old automation and made a new one with the adjusted blueprint. That worked right away and triggered all events, lights and custom ones. I’ve included the edited code below.

However, the “Hold” Functions no longer work as intended, both for lights and custom commands. Looking at the states in Dev Tools, I see that the state is changed from blank to the button press only for a split second before going back to blank, even when holding the button. Looks like the blueprint code is relying on the state staying the same while the button is pressed. Actions that require only a single trigger work as custom actions, but being able to hold the button to change the dim for as long as the button is held, and custom actions that continue as long as the button are held do not work right. They trigger but then immediately release, even when holding down the button.

Starbuck93, I appreciate all the work you’ve done with this, but it looks like you will need to update the code (at least to remove the attribute strings to make it functional) to account for the new way Z2M is handling states vs attributes.

blueprint:
  name: Z2M - IKEA five button remote for lights
  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
      selector:
        entity:
          domain: sensor
          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: '%'
    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: {}
  source_url: https://community.home-assistant.io/t/zigbee2mqtt-ikea-five-button-remote/255308
mode: restart
max_exceeded: silent
variables:
  force_brightness: !input 'force_brightness'
trigger:
- platform: state
  entity_id: !input 'remote'
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
        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
        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'

Thank you for your work on this, @WhatTrees!

My original blueprint code does in fact look at the attributes of sensor.[Your Remote]_action, not the MQTT device that is under “Devices & Services” in settings. But, watching the sensor state and attribute Action value, it looks like they are duplicated when I press and hold then release the remote button. So, removing attribute: action will have the desired outcome, and I don’t know why it wouldn’t be working with the line included.

Thanks for the reply starbuck93!

I have found the issue.

Z2M has a setting called “Home Assistant legacy entity attributes” inside the front end settings, “Home Assistant integration” which is not enabled by default. This adds the action and click attributes. Without it, the actions only appear as a state and not as an attribute called “action”. That seems to have fixed the issue for me. Even the hold functions seem to work as intended again!

Thanks for the amazing blueprint! You might consider adding a note in the description about needing to have that enabled for it to work since it doesn’t appear to be on by default.